Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 6601: Add right click menu for main table header #8762

Closed
wants to merge 22 commits into from

Conversation

pratt33k
Copy link

@pratt33k pratt33k commented May 7, 2022

Fixes #6601

We are able to remove the column from the maintable using a right click menu. And it also updates the Entry Table in Preferences.

Inspired from #7729

Screenshots:

  1. When the user right clicks on the maintable, a context menu (right click menu) appears with the maintable columns in it.

image

  1. After clicking 'Journal/Booktitle' in the right click menu​, it gets deleted from the maintable (2a) and entry table (2b) accessible through show preferences.

2a
image

2b
image

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

TableTab tableTab = new TableTab();
TableTabViewModel tableTabViewModel = new TableTabViewModel(dialogService, preferencesService);

// tableTabViewModel.removeColumn(tableTab.getList().getSelectionModel().getSelectedItem());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We know how to access the column name but not sure if we can somehow use it in removeColumn( ).

Or is there a different way to remove a particular column from the preferences/entry table and maintable if we know the column name.

Any suggestions would be highly appreciated!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would operate on the ColumnPreferences here as follows.
In MainTable you have the columns in this.columns and can map them to the MainTableColumnModel. And then you can create a new TablecolumnPreferences

   this.getColumns().stream()
                    .map(column -> (MainTableColumn<?>) column) 

e.g. (see PersistenceVisualStateTable)

preferences.storeMainTableColumnPreferences(new ColumnPreferences(
                mainTable.getColumns().stream()
                         .filter(col -> col instanceof MainTableColumn<?>)
                         .map(column -> ((MainTableColumn<?>) column).getModel())
                         .collect(Collectors.toList()),
                preferences.getColumnPreferences().getColumnSortOrder()));

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! We had a bit of confusion understanding how to create a new TablecolumnPreferences. We found another way to remove column though. Let us know if it works, thanks!

@pratt33k pratt33k marked this pull request as ready for review May 24, 2022 03:59
@pratt33k pratt33k requested a review from Siedlerchr May 26, 2022 00:42
@ShaunChang ShaunChang force-pushed the fix-for-issue-6601 branch from 6f4ffba to 6163d4c Compare May 26, 2022 10:19
static MainTable mT = null;

public void show(MainTable mainTable, LibraryTab libraryTab, DialogService dialogService) {
System.out.println("show()");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these System.out statements...

import org.jabref.logic.l10n.Localization;

public class MainTableHeaderRightClickMenu extends ContextMenu {
static MainTable mT = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this static? You could simply declare it as normal member variable.
I would pass the MainTable argument in the constructor and assign it there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not abbreviate variable names.

@@ -147,4 +146,8 @@ public void sortColumnDown() {
public void addColumn() {
viewModel.insertColumnInList();
}

public TableView<MainTableColumnModel> getList() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would give this a meaningful name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not use a getter for the TableView, instead inject the columnslist of the table into your new class RightClickMenu and work on that. We need to untangle all the callbacks, otherwise the classes are untestable.

@Siedlerchr Siedlerchr requested a review from calixtus May 30, 2022 18:58
@Siedlerchr Siedlerchr added the status: changes required Pull requests that are not yet complete label May 30, 2022
Comment on lines +62 to +64
public ListView<PreferencesTab> getPreferenceTabList() {
return preferenceTabList;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not touch the PreferencesDialog. Changes must happen in the Preferences, not in the Dialog

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps make the method more generic, so a new method could open any specific preferences tab.

Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed the wrong button

Comment on lines -152 to +157
.map(column -> (MainTableColumn<?>) column)
.filter(column -> column.getModel().equals(columnModel))
.findFirst()
.ifPresent(column -> this.getSortOrder().add(column)));
.map(column -> (MainTableColumn<?>) column)
.filter(column -> column.getModel().equals(columnModel))
.findFirst()
.ifPresent(column -> this.getSortOrder().add(column)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo all your whitespace changes and use our checkstyle config for your jabref workspace.

Comment on lines +260 to +299
/**
* Create any single column
*/
public TableColumn<BibEntryTableViewModel, ?> createColumn(MainTableColumnModel columnModel) {
switch (columnModel.getType()) {
case INDEX:
return createIndexColumn(columnModel);
case GROUPS:
return createGroupColumn(columnModel);
case FILES:
return createFilesColumn(columnModel);
case LINKED_IDENTIFIER:
return createIdentifierColumn(columnModel);
case LIBRARY_NAME:
return createLibraryColumn(columnModel);
case EXTRAFILE:
if (columnModel.getQualifier().isBlank()) {
return createExtraFileColumn(columnModel);
}
break;
case SPECIALFIELD:
if (!columnModel.getQualifier().isBlank()) {
Field field = FieldFactory.parseField(columnModel.getQualifier());
if (field instanceof SpecialField) {
return createSpecialFieldColumn(columnModel);
} else {
LOGGER.warn("Special field type '{}' is unknown. Using normal column type.", columnModel.getQualifier());
return createFieldColumn(columnModel);
}
}
break;
default:
case NORMALFIELD:
if (!columnModel.getQualifier().isBlank()) {
return createFieldColumn(columnModel);
}
break;
}
return null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you introduce this method, you need to adjust the constructor of the MainTableColumnFactory to reduce code duplication

// Click on the tableColumns
if (!(clickEvent.getTarget() instanceof StackPane)) {
System.out.println("Click on the tableColumns");
// Create radioMenuItemList from tableColumnList
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid code-describing comments, instead try to write self-explaining code and put your ratilonale into a comment.

@calixtus
Copy link
Member

calixtus commented Jun 4, 2022

Any update here?

@ThiloteE
Copy link
Member

To ease organizational workflows I have linked the pull-request to the issue with syntax as described in https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue

Linking a pull request to an issue using a keyword

You can link a pull request to an issue by using a supported keyword in the pull request's description or in a commit message. The pull request must be on the default branch.

  • close
  • closes
  • closed
  • fix
  • fixes
  • fixed
  • resolve
  • resolves
  • resolved

If you use a keyword to reference a pull request comment in another pull request, the pull requests will be linked. Merging the referencing pull request also closes the referenced pull request.

The syntax for closing keywords depends on whether the issue is in the same repository as the pull request.

@ThiloteE ThiloteE changed the title Fix for issue 6601: Right click menu for main table header Fix for issue 6601: Add right click menu for main table header Jul 16, 2022
@calixtus
Copy link
Member

any update here?

@calixtus
Copy link
Member

Closing this issue due to inactivity 💤
Maybe someone eventually will continue your good work already and push it forward.

@calixtus calixtus closed this Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add right click menu for main table header
5 participants