-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from all commits
6b91159
cef3afa
ce929a3
2644a9b
923ad41
953304e
be4cc17
22b30e9
9e4dd73
4f39dfa
331778c
3c13860
e72683c
1bb667b
6ad1276
0569388
2463878
18c6761
bcdf26c
a02f962
fc3be4a
6163d4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,4 +256,45 @@ private TableColumn<BibEntryTableViewModel, List<LinkedFile>> createExtraFileCol | |
private TableColumn<BibEntryTableViewModel, String> createLibraryColumn(MainTableColumnModel columnModel) { | ||
return new LibraryColumn(columnModel); | ||
} | ||
|
||
/** | ||
* 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; | ||
} | ||
Comment on lines
+260
to
+299
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.jabref.gui.maintable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javafx.scene.control.ContextMenu; | ||
import javafx.scene.control.MenuItem; | ||
import javafx.scene.control.RadioMenuItem; | ||
import javafx.scene.control.SeparatorMenuItem; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.layout.StackPane; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.LibraryTab; | ||
import org.jabref.gui.maintable.columns.MainTableColumn; | ||
import org.jabref.gui.preferences.PreferencesDialogView; | ||
import org.jabref.logic.l10n.Localization; | ||
|
||
public class MainTableHeaderRightClickMenu extends ContextMenu { | ||
static MainTable mT = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not abbreviate variable names. |
||
|
||
public void show(MainTable mainTable, LibraryTab libraryTab, DialogService dialogService) { | ||
System.out.println("show()"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove these System.out statements... |
||
mT = mainTable; | ||
mainTable.setOnContextMenuRequested(clickEvent -> { | ||
|
||
// Click on the tableColumns | ||
if (!(clickEvent.getTarget() instanceof StackPane)) { | ||
System.out.println("Click on the tableColumns"); | ||
// Create radioMenuItemList from tableColumnList | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
List<RadioMenuItem> radioMenuItems = new ArrayList<>(); | ||
mainTable.getColumns().forEach(tableColumn -> radioMenuItems.add(createRadioMenuItem(tableColumn))); | ||
|
||
SeparatorMenuItem line = new SeparatorMenuItem(); | ||
|
||
// Show preferences Button | ||
MenuItem columnsPreferences = new MenuItem(Localization.lang("Show preferences")); | ||
columnsPreferences.setOnAction(event -> { | ||
|
||
// Show Entry table | ||
PreferencesDialogView preferencesDialogView = new PreferencesDialogView(libraryTab.frame()); | ||
preferencesDialogView.getPreferenceTabList().getSelectionModel().select(3); | ||
dialogService.showCustomDialog(preferencesDialogView); | ||
}); | ||
|
||
// Clean items and add newItems | ||
this.getItems().clear(); | ||
|
||
this.getItems().addAll(radioMenuItems); | ||
this.getItems().addAll(line, columnsPreferences); | ||
|
||
// Show ContextMenu | ||
this.show(mainTable, clickEvent.getScreenX(), clickEvent.getScreenY()); | ||
} | ||
|
||
clickEvent.consume(); | ||
}); | ||
} | ||
|
||
private RadioMenuItem createRadioMenuItem(TableColumn<BibEntryTableViewModel, ?> tableColumn) { | ||
RadioMenuItem radioMenuItem = new RadioMenuItem(((MainTableColumn<?>) tableColumn).getDisplayName()); | ||
// System.out.println(((MainTableColumn<?>) tableColumn).getDisplayName()); | ||
radioMenuItem.setOnAction(event -> { | ||
// Return the column name when we click an item from context menu | ||
// System.out.println(((MainTableColumn) tableColumn).getModel().getName()); | ||
removeColumn(tableColumn); | ||
}); | ||
|
||
return radioMenuItem; | ||
} | ||
|
||
public void addColumn(MainTableColumn column, MainTableColumnFactory creator) { | ||
MainTableColumnModel columnModel = column.getModel(); | ||
creator.createColumn(columnModel); | ||
} | ||
|
||
public void removeColumn(TableColumn<BibEntryTableViewModel, ?> tableColumn) { | ||
mT.getColumns().removeIf(tableCol -> tableCol == tableColumn); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,10 @@ public PreferencesDialogViewModel getViewModel() { | |
return viewModel; | ||
} | ||
|
||
public ListView<PreferencesTab> getPreferenceTabList() { | ||
return preferenceTabList; | ||
} | ||
Comment on lines
+62
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
@FXML | ||
private void initialize() { | ||
viewModel = new PreferencesDialogViewModel(dialogService, preferencesService, frame); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,6 @@ private void setupTable() { | |
event.consume(); | ||
} | ||
}); | ||
|
||
columnsList.itemsProperty().bind(viewModel.columnsListProperty()); | ||
|
||
new ViewModelListCellFactory<MainTableColumnModel>() | ||
|
@@ -147,4 +146,8 @@ public void sortColumnDown() { | |
public void addColumn() { | ||
viewModel.insertColumnInList(); | ||
} | ||
|
||
public TableView<MainTableColumnModel> getList() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would give this a meaningful name There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
return columnsList; | ||
} | ||
} |
There was a problem hiding this comment.
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.