From 6b91159284626d68c7668c55879631c3bcaecedf Mon Sep 17 00:00:00 2001 From: pratt33k <53478966+pratt33k@users.noreply.github.com> Date: Wed, 30 Mar 2022 15:42:35 +1030 Subject: [PATCH 01/13] Update issue templates --- .github/ISSUE_TEMPLATE/blank.md | 10 ++++++++++ .github/ISSUE_TEMPLATE/user-story.md | 12 ++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/blank.md create mode 100644 .github/ISSUE_TEMPLATE/user-story.md diff --git a/.github/ISSUE_TEMPLATE/blank.md b/.github/ISSUE_TEMPLATE/blank.md new file mode 100644 index 00000000000..8dca1b7d554 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/blank.md @@ -0,0 +1,10 @@ +--- +name: Blank +about: Describe this issue's purpose here. +title: '' +labels: '' +assignees: '' + +--- + + diff --git a/.github/ISSUE_TEMPLATE/user-story.md b/.github/ISSUE_TEMPLATE/user-story.md new file mode 100644 index 00000000000..fbf42b4d689 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/user-story.md @@ -0,0 +1,12 @@ +--- +name: User Story +about: Describe this feature / sub feature name here +title: '' +labels: User Story +assignees: '' + +--- + +As a (end user / developer / others) +I want to +So that I can From 2644a9b2e07aa62109a295e95480e40a3c19b565 Mon Sep 17 00:00:00 2001 From: danglt Date: Wed, 13 Apr 2022 16:18:44 +0930 Subject: [PATCH 02/13] Add MainTableHeaderRightClickMenu class --- .../MainTableHeaderRightClickMenu.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java new file mode 100644 index 00000000000..f6c865aae4e --- /dev/null +++ b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java @@ -0,0 +1,41 @@ +package org.jabref.gui.maintable; + +import javafx.scene.control.ContextMenu; +import javafx.scene.control.RadioMenuItem; +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 java.util.ArrayList; +import java.util.List; + +public class MainTableHeaderRightClickMenu extends ContextMenu { + + public void show(MainTable mainTable, LibraryTab libraryTab, DialogService dialogService) { + mainTable.setOnContextMenuRequested(clickEvent -> { + + // Click on the tableColumns + if (!(clickEvent.getTarget() instanceof StackPane)) { + + // Create radioMenuItemList from tableColumnList + List radioMenuItems = new ArrayList<>(); + mainTable.getColumns().forEach(tableColumn -> radioMenuItems.add(createRadioMenuItem(tableColumn))); + + // Clean items and add newItems + this.getItems().clear(); + this.getItems().addAll(radioMenuItems); + + // Show ContextMenu + this.show(mainTable, clickEvent.getScreenX(), clickEvent.getScreenY()); + } + clickEvent.consume(); + }); + } + + private RadioMenuItem createRadioMenuItem(TableColumn tableColumn) { + RadioMenuItem radioMenuItem = new RadioMenuItem(((MainTableColumn) tableColumn).getDisplayName()); + return radioMenuItem; + } +} From 953304eb2ffad1d153710a1d896bdad19de9d449 Mon Sep 17 00:00:00 2001 From: danglt Date: Fri, 15 Apr 2022 22:00:31 +0930 Subject: [PATCH 03/13] Add MainTableHeaderRightClickMenu.show() to MainTable class --- .../org/jabref/gui/maintable/MainTable.java | 79 ++++++++----------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 4fdc4add495..d2b1d1d05b3 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -1,34 +1,13 @@ package org.jabref.gui.maintable; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -import javax.swing.undo.UndoManager; - +import com.google.common.eventbus.Subscribe; import javafx.collections.ListChangeListener; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableColumn; import javafx.scene.control.TableRow; import javafx.scene.control.TableView; -import javafx.scene.input.ClipboardContent; -import javafx.scene.input.DragEvent; -import javafx.scene.input.Dragboard; -import javafx.scene.input.KeyCode; -import javafx.scene.input.KeyEvent; -import javafx.scene.input.MouseDragEvent; -import javafx.scene.input.MouseEvent; -import javafx.scene.input.TransferMode; - -import org.jabref.gui.DialogService; -import org.jabref.gui.DragAndDropDataFormats; -import org.jabref.gui.Globals; -import org.jabref.gui.LibraryTab; -import org.jabref.gui.StateManager; +import javafx.scene.input.*; +import org.jabref.gui.*; import org.jabref.gui.actions.StandardActions; import org.jabref.gui.edit.EditAction; import org.jabref.gui.externalfiles.ImportHandler; @@ -46,11 +25,18 @@ import org.jabref.model.database.event.EntriesAddedEvent; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.PreferencesService; - -import com.google.common.eventbus.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.swing.undo.UndoManager; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + public class MainTable extends TableView { private static final Logger LOGGER = LoggerFactory.getLogger(MainTable.class); @@ -134,6 +120,9 @@ public MainTable(MainTableDataModel model, this.getSortOrder().clear(); + new MainTableHeaderRightClickMenu().show(this, libraryTab, dialogService); + + /* KEEP for debugging purposes for (var colModel : mainTablePreferences.getColumnPreferences().getColumnSortOrder()) { for (var col : this.getColumns()) { @@ -149,10 +138,10 @@ public MainTable(MainTableDataModel model, mainTablePreferences.getColumnPreferences().getColumnSortOrder().forEach(columnModel -> this.getColumns().stream() - .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))); if (mainTablePreferences.getResizeColumnsToFit()) { this.setColumnResizePolicy(new SmartConstrainedResizePolicy()); @@ -203,16 +192,16 @@ private void jumpToSearchKey(TableColumn sortedColumn lastKeyPressTime = System.currentTimeMillis(); this.getItems().stream() - .filter(item -> Optional.ofNullable(sortedColumn.getCellObservableValue(item).getValue()) - .map(Object::toString) - .orElse("") - .toLowerCase() - .startsWith(columnSearchTerm)) - .findFirst() - .ifPresent(item -> { - this.scrollTo(item); - this.clearAndSelect(item.getEntry()); - }); + .filter(item -> Optional.ofNullable(sortedColumn.getCellObservableValue(item).getValue()) + .map(Object::toString) + .orElse("") + .toLowerCase() + .startsWith(columnSearchTerm)) + .findFirst() + .ifPresent(item -> { + this.scrollTo(item); + this.clearAndSelect(item.getEntry()); + }); } @Subscribe @@ -250,8 +239,8 @@ private void setupKeyBindings(KeyBindingRepository keyBindings) { this.addEventFilter(KeyEvent.KEY_PRESSED, event -> { if (event.getCode() == KeyCode.ENTER) { getSelectedEntries().stream() - .findFirst() - .ifPresent(libraryTab::showAndEdit); + .findFirst() + .ifPresent(libraryTab::showAndEdit); event.consume(); return; } @@ -436,8 +425,8 @@ public List getSelectedEntries() { private Optional findEntry(BibEntry entry) { return model.getEntriesFilteredAndSorted() - .stream() - .filter(viewModel -> viewModel.getEntry().equals(entry)) - .findFirst(); + .stream() + .filter(viewModel -> viewModel.getEntry().equals(entry)) + .findFirst(); } } From be4cc175f7ce71bf61cdfbbc280012735535bd06 Mon Sep 17 00:00:00 2001 From: danglt Date: Sat, 7 May 2022 23:37:06 +0930 Subject: [PATCH 04/13] rearrange import classes --- .../gui/maintable/MainTableColumnModel.java | 16 ++++------------ .../preferences/table/TableTabViewModel.java | 19 ++++++------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java index 5ff872c1426..cf0c5b95399 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java @@ -1,24 +1,16 @@ package org.jabref.gui.maintable; -import java.util.EnumSet; -import java.util.Objects; - -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.ReadOnlyStringWrapper; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; +import javafx.beans.property.*; import javafx.scene.control.TableColumn; - import org.jabref.gui.util.FieldsUtil; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.field.FieldFactory; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.EnumSet; +import java.util.Objects; + /** * Represents the full internal name of a column in the main table. Consists of two parts: The type of the column and a qualifier, like the * field name to be displayed in the column. diff --git a/src/main/java/org/jabref/gui/preferences/table/TableTabViewModel.java b/src/main/java/org/jabref/gui/preferences/table/TableTabViewModel.java index 2184469c933..04714678f60 100644 --- a/src/main/java/org/jabref/gui/preferences/table/TableTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/table/TableTabViewModel.java @@ -1,17 +1,13 @@ package org.jabref.gui.preferences.table; -import java.util.EnumSet; - -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.ListProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleListProperty; -import javafx.beans.property.SimpleObjectProperty; +import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; +import de.saxsys.mvvmfx.utils.validation.ValidationMessage; +import de.saxsys.mvvmfx.utils.validation.ValidationStatus; +import de.saxsys.mvvmfx.utils.validation.Validator; +import javafx.beans.property.*; import javafx.collections.FXCollections; import javafx.scene.control.SelectionModel; import javafx.util.StringConverter; - import org.jabref.gui.DialogService; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; @@ -31,10 +27,7 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.preferences.PreferencesService; -import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; -import de.saxsys.mvvmfx.utils.validation.ValidationMessage; -import de.saxsys.mvvmfx.utils.validation.ValidationStatus; -import de.saxsys.mvvmfx.utils.validation.Validator; +import java.util.EnumSet; public class TableTabViewModel implements PreferenceTabViewModel { From 22b30e9152c67e2fb4140c1c44a50ee1a366dc4a Mon Sep 17 00:00:00 2001 From: danglt Date: Sat, 7 May 2022 23:39:03 +0930 Subject: [PATCH 05/13] Create getList() in TableTab and new MainTableHeaderRightClickMenu --- .../org/jabref/gui/maintable/MainTable.java | 4 +-- .../MainTableHeaderRightClickMenu.java | 26 +++++++++++++++++-- .../gui/preferences/table/TableTab.java | 5 +++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index d2b1d1d05b3..274152fc7b0 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -120,8 +120,8 @@ public MainTable(MainTableDataModel model, this.getSortOrder().clear(); - new MainTableHeaderRightClickMenu().show(this, libraryTab, dialogService); - + new MainTableHeaderRightClickMenu().show(this); + new MainTableHeaderRightClickMenu().removeColumns(this, dialogService, preferencesService); /* KEEP for debugging purposes for (var colModel : mainTablePreferences.getColumnPreferences().getColumnSortOrder()) { diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java index f6c865aae4e..7d68fa0dc6d 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java @@ -5,15 +5,17 @@ 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.table.TableTab; +import org.jabref.gui.preferences.table.TableTabViewModel; +import org.jabref.preferences.PreferencesService; import java.util.ArrayList; import java.util.List; public class MainTableHeaderRightClickMenu extends ContextMenu { - public void show(MainTable mainTable, LibraryTab libraryTab, DialogService dialogService) { + public void show(MainTable mainTable) { mainTable.setOnContextMenuRequested(clickEvent -> { // Click on the tableColumns @@ -25,17 +27,37 @@ public void show(MainTable mainTable, LibraryTab libraryTab, DialogService dialo // Clean items and add newItems this.getItems().clear(); + this.getItems().addAll(radioMenuItems); // Show ContextMenu this.show(mainTable, clickEvent.getScreenX(), clickEvent.getScreenY()); } + + clickEvent.consume(); }); } private RadioMenuItem createRadioMenuItem(TableColumn tableColumn) { RadioMenuItem radioMenuItem = new RadioMenuItem(((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()); + }); + return radioMenuItem; } + + //Need help!!! + //We know the column name but cannot pass it in the parameters of the removeColumn() + public void removeColumns(MainTable mainTable, DialogService dialogService, PreferencesService preferencesService){ + TableTab tableTab = new TableTab(); + TableTabViewModel tableTabViewModel = new TableTabViewModel(dialogService, preferencesService); + +// tableTabViewModel.removeColumn(tableTab.getList().getSelectionModel().getSelectedItem()); + + } } diff --git a/src/main/java/org/jabref/gui/preferences/table/TableTab.java b/src/main/java/org/jabref/gui/preferences/table/TableTab.java index 6014d21ae90..bcd44109c32 100644 --- a/src/main/java/org/jabref/gui/preferences/table/TableTab.java +++ b/src/main/java/org/jabref/gui/preferences/table/TableTab.java @@ -94,7 +94,6 @@ private void setupTable() { event.consume(); } }); - columnsList.itemsProperty().bind(viewModel.columnsListProperty()); new ViewModelListCellFactory() @@ -147,4 +146,8 @@ public void sortColumnDown() { public void addColumn() { viewModel.insertColumnInList(); } + + public TableView getList() { + return columnsList; + } } From 331778c314ef79fc6bc183c789b8b04d9245cf0f Mon Sep 17 00:00:00 2001 From: Prateek28a Date: Sun, 8 May 2022 01:34:18 +0930 Subject: [PATCH 06/13] Deleted unneccessary files --- .github/ISSUE_TEMPLATE/blank.md | 10 ---------- .github/ISSUE_TEMPLATE/user-story.md | 12 ------------ 2 files changed, 22 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/blank.md delete mode 100644 .github/ISSUE_TEMPLATE/user-story.md diff --git a/.github/ISSUE_TEMPLATE/blank.md b/.github/ISSUE_TEMPLATE/blank.md deleted file mode 100644 index 8dca1b7d554..00000000000 --- a/.github/ISSUE_TEMPLATE/blank.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: Blank -about: Describe this issue's purpose here. -title: '' -labels: '' -assignees: '' - ---- - - diff --git a/.github/ISSUE_TEMPLATE/user-story.md b/.github/ISSUE_TEMPLATE/user-story.md deleted file mode 100644 index fbf42b4d689..00000000000 --- a/.github/ISSUE_TEMPLATE/user-story.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: User Story -about: Describe this feature / sub feature name here -title: '' -labels: User Story -assignees: '' - ---- - -As a (end user / developer / others) -I want to -So that I can From 3c1386098718a9571c5c05863520cc96b1a8a193 Mon Sep 17 00:00:00 2001 From: Prateek28a Date: Sun, 8 May 2022 01:35:38 +0930 Subject: [PATCH 07/13] Fix for checkstyle errors & Disabled optimize imports on the fly --- .../org/jabref/gui/maintable/MainTable.java | 40 +++++++++++++------ .../gui/maintable/MainTableColumnModel.java | 16 ++++++-- .../MainTableHeaderRightClickMenu.java | 20 +++++----- .../preferences/table/TableTabViewModel.java | 19 ++++++--- 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 7dd3db8d13e..28132657e17 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -1,13 +1,34 @@ package org.jabref.gui.maintable; -import com.google.common.eventbus.Subscribe; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +import javax.swing.undo.UndoManager; + import javafx.collections.ListChangeListener; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableColumn; import javafx.scene.control.TableRow; import javafx.scene.control.TableView; -import javafx.scene.input.*; -import org.jabref.gui.*; +import javafx.scene.input.ClipboardContent; +import javafx.scene.input.DragEvent; +import javafx.scene.input.Dragboard; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; +import javafx.scene.input.MouseDragEvent; +import javafx.scene.input.MouseEvent; +import javafx.scene.input.TransferMode; + +import org.jabref.gui.DialogService; +import org.jabref.gui.DragAndDropDataFormats; +import org.jabref.gui.Globals; +import org.jabref.gui.LibraryTab; +import org.jabref.gui.StateManager; import org.jabref.gui.actions.StandardActions; import org.jabref.gui.edit.EditAction; import org.jabref.gui.externalfiles.ImportHandler; @@ -25,18 +46,11 @@ import org.jabref.model.database.event.EntriesAddedEvent; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.PreferencesService; + +import com.google.common.eventbus.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.swing.undo.UndoManager; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - public class MainTable extends TableView { private static final Logger LOGGER = LoggerFactory.getLogger(MainTable.class); @@ -121,7 +135,7 @@ public MainTable(MainTableDataModel model, this.getSortOrder().clear(); new MainTableHeaderRightClickMenu().show(this); - new MainTableHeaderRightClickMenu().removeColumns(this, dialogService, preferencesService); + new MainTableHeaderRightClickMenu().removeColumns(dialogService, preferencesService); /* KEEP for debugging purposes for (var colModel : mainTablePreferences.getColumnPreferences().getColumnSortOrder()) { diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java index cf0c5b95399..5ff872c1426 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java @@ -1,16 +1,24 @@ package org.jabref.gui.maintable; -import javafx.beans.property.*; +import java.util.EnumSet; +import java.util.Objects; + +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyStringWrapper; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; import javafx.scene.control.TableColumn; + import org.jabref.gui.util.FieldsUtil; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.field.FieldFactory; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.EnumSet; -import java.util.Objects; - /** * Represents the full internal name of a column in the main table. Consists of two parts: The type of the column and a qualifier, like the * field name to be displayed in the column. diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java index 7d68fa0dc6d..86c2d4b3ef4 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java @@ -1,18 +1,19 @@ package org.jabref.gui.maintable; +import java.util.ArrayList; +import java.util.List; + import javafx.scene.control.ContextMenu; import javafx.scene.control.RadioMenuItem; import javafx.scene.control.TableColumn; import javafx.scene.layout.StackPane; + import org.jabref.gui.DialogService; import org.jabref.gui.maintable.columns.MainTableColumn; import org.jabref.gui.preferences.table.TableTab; import org.jabref.gui.preferences.table.TableTabViewModel; import org.jabref.preferences.PreferencesService; -import java.util.ArrayList; -import java.util.List; - public class MainTableHeaderRightClickMenu extends ContextMenu { public void show(MainTable mainTable) { @@ -20,7 +21,6 @@ public void show(MainTable mainTable) { // Click on the tableColumns if (!(clickEvent.getTarget() instanceof StackPane)) { - // Create radioMenuItemList from tableColumnList List radioMenuItems = new ArrayList<>(); mainTable.getColumns().forEach(tableColumn -> radioMenuItems.add(createRadioMenuItem(tableColumn))); @@ -34,30 +34,28 @@ public void show(MainTable mainTable) { this.show(mainTable, clickEvent.getScreenX(), clickEvent.getScreenY()); } - clickEvent.consume(); }); } - private RadioMenuItem createRadioMenuItem(TableColumn tableColumn) { + private RadioMenuItem createRadioMenuItem(TableColumn tableColumn) { RadioMenuItem radioMenuItem = new RadioMenuItem(((MainTableColumn) tableColumn).getDisplayName()); radioMenuItem.setOnAction(event -> { - //return the column name when we click an item from context menu + // Return the column name when we click an item from context menu System.out.println(((MainTableColumn) tableColumn).getModel().getName()); }); return radioMenuItem; } - //Need help!!! - //We know the column name but cannot pass it in the parameters of the removeColumn() - public void removeColumns(MainTable mainTable, DialogService dialogService, PreferencesService preferencesService){ + // Need help!!! + // We know the column name but cannot pass it in the parameters of the removeColumn() + public void removeColumns(DialogService dialogService, PreferencesService preferencesService) { TableTab tableTab = new TableTab(); TableTabViewModel tableTabViewModel = new TableTabViewModel(dialogService, preferencesService); // tableTabViewModel.removeColumn(tableTab.getList().getSelectionModel().getSelectedItem()); - } } diff --git a/src/main/java/org/jabref/gui/preferences/table/TableTabViewModel.java b/src/main/java/org/jabref/gui/preferences/table/TableTabViewModel.java index 04714678f60..2184469c933 100644 --- a/src/main/java/org/jabref/gui/preferences/table/TableTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/table/TableTabViewModel.java @@ -1,13 +1,17 @@ package org.jabref.gui.preferences.table; -import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; -import de.saxsys.mvvmfx.utils.validation.ValidationMessage; -import de.saxsys.mvvmfx.utils.validation.ValidationStatus; -import de.saxsys.mvvmfx.utils.validation.Validator; -import javafx.beans.property.*; +import java.util.EnumSet; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ListProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; import javafx.scene.control.SelectionModel; import javafx.util.StringConverter; + import org.jabref.gui.DialogService; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; @@ -27,7 +31,10 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.preferences.PreferencesService; -import java.util.EnumSet; +import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; +import de.saxsys.mvvmfx.utils.validation.ValidationMessage; +import de.saxsys.mvvmfx.utils.validation.ValidationStatus; +import de.saxsys.mvvmfx.utils.validation.Validator; public class TableTabViewModel implements PreferenceTabViewModel { From e72683c535e92e86cb3d01dce131471bc5ad6ac0 Mon Sep 17 00:00:00 2001 From: a1781326 Date: Sat, 14 May 2022 20:26:29 +0930 Subject: [PATCH 08/13] Added function that will remove the column in the mainTable when we click that column right context menu --- .../MainTableHeaderRightClickMenu.java | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java index 86c2d4b3ef4..d9be2d9aaa6 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java @@ -15,12 +15,16 @@ import org.jabref.preferences.PreferencesService; public class MainTableHeaderRightClickMenu extends ContextMenu { + static MainTable mT = null; public void show(MainTable mainTable) { + System.out.println("show()"); + 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 List radioMenuItems = new ArrayList<>(); mainTable.getColumns().forEach(tableColumn -> radioMenuItems.add(createRadioMenuItem(tableColumn))); @@ -40,16 +44,43 @@ public void show(MainTable mainTable) { private RadioMenuItem createRadioMenuItem(TableColumn 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()); + //System.out.println(((MainTableColumn) tableColumn).getModel().getName()); + update(tableColumn); }); return radioMenuItem; } + private void update(TableColumn tableColumn) { + System.out.println("update()"); + mT.setOnContextMenuRequested(clickEvent -> { + + // Click on the tableColumns + if (!(clickEvent.getTarget() instanceof StackPane)) { + System.out.println("Click on the tableColumns"); + // Create radioMenuItemList from tableColumnList + List radioMenuItems = new ArrayList<>(); + + // delete + mT.getColumns().removeIf(tableCol -> tableCol == tableColumn); + + mT.getColumns().forEach(tC-> radioMenuItems.add(createRadioMenuItem(tC))); + + // Clean items and add newItems + this.getItems().clear(); + + this.getItems().addAll(radioMenuItems); + + // Show ContextMenu + this.show(mT, clickEvent.getScreenX(), clickEvent.getScreenY()); + } + clickEvent.consume(); + }); + } + // Need help!!! // We know the column name but cannot pass it in the parameters of the removeColumn() public void removeColumns(DialogService dialogService, PreferencesService preferencesService) { From 1bb667b045f1159d287d1a7cc726912b1122a259 Mon Sep 17 00:00:00 2001 From: Prateek28a Date: Mon, 16 May 2022 18:50:09 +0930 Subject: [PATCH 09/13] Fixed checkstyle errors --- .../jabref/gui/maintable/MainTableHeaderRightClickMenu.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java index d9be2d9aaa6..1ce8091054e 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java @@ -44,10 +44,10 @@ public void show(MainTable mainTable) { private RadioMenuItem createRadioMenuItem(TableColumn tableColumn) { RadioMenuItem radioMenuItem = new RadioMenuItem(((MainTableColumn) tableColumn).getDisplayName()); - //System.out.println(((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()); + // System.out.println(((MainTableColumn) tableColumn).getModel().getName()); update(tableColumn); }); From 6ad12763f01b1f12172b014bfb27eca77f5b7fc0 Mon Sep 17 00:00:00 2001 From: Prateek28a Date: Mon, 16 May 2022 20:26:22 +0930 Subject: [PATCH 10/13] Fixed checkstyle errors & optimized deletion of column --- .../org/jabref/gui/maintable/MainTable.java | 1 - .../MainTableHeaderRightClickMenu.java | 44 ++----------------- 2 files changed, 4 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 28132657e17..3be9d99229f 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -135,7 +135,6 @@ public MainTable(MainTableDataModel model, this.getSortOrder().clear(); new MainTableHeaderRightClickMenu().show(this); - new MainTableHeaderRightClickMenu().removeColumns(dialogService, preferencesService); /* KEEP for debugging purposes for (var colModel : mainTablePreferences.getColumnPreferences().getColumnSortOrder()) { diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java index 1ce8091054e..66a1460d719 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java @@ -8,11 +8,7 @@ import javafx.scene.control.TableColumn; import javafx.scene.layout.StackPane; -import org.jabref.gui.DialogService; import org.jabref.gui.maintable.columns.MainTableColumn; -import org.jabref.gui.preferences.table.TableTab; -import org.jabref.gui.preferences.table.TableTabViewModel; -import org.jabref.preferences.PreferencesService; public class MainTableHeaderRightClickMenu extends ContextMenu { static MainTable mT = null; @@ -30,7 +26,7 @@ public void show(MainTable mainTable) { mainTable.getColumns().forEach(tableColumn -> radioMenuItems.add(createRadioMenuItem(tableColumn))); // Clean items and add newItems - this.getItems().clear(); + // this.getItems().clear(); this.getItems().addAll(radioMenuItems); @@ -48,45 +44,13 @@ private RadioMenuItem createRadioMenuItem(TableColumn radioMenuItem.setOnAction(event -> { // Return the column name when we click an item from context menu // System.out.println(((MainTableColumn) tableColumn).getModel().getName()); - update(tableColumn); + removeColumns(tableColumn); }); return radioMenuItem; } - private void update(TableColumn tableColumn) { - System.out.println("update()"); - mT.setOnContextMenuRequested(clickEvent -> { - - // Click on the tableColumns - if (!(clickEvent.getTarget() instanceof StackPane)) { - System.out.println("Click on the tableColumns"); - // Create radioMenuItemList from tableColumnList - List radioMenuItems = new ArrayList<>(); - - // delete - mT.getColumns().removeIf(tableCol -> tableCol == tableColumn); - - mT.getColumns().forEach(tC-> radioMenuItems.add(createRadioMenuItem(tC))); - - // Clean items and add newItems - this.getItems().clear(); - - this.getItems().addAll(radioMenuItems); - - // Show ContextMenu - this.show(mT, clickEvent.getScreenX(), clickEvent.getScreenY()); - } - clickEvent.consume(); - }); - } - - // Need help!!! - // We know the column name but cannot pass it in the parameters of the removeColumn() - public void removeColumns(DialogService dialogService, PreferencesService preferencesService) { - TableTab tableTab = new TableTab(); - TableTabViewModel tableTabViewModel = new TableTabViewModel(dialogService, preferencesService); - -// tableTabViewModel.removeColumn(tableTab.getList().getSelectionModel().getSelectedItem()); + public void removeColumns(TableColumn tableColumn) { + mT.getColumns().removeIf(tableCol -> tableCol == tableColumn); } } From 246387873a4ba168233a44646bba6f4d895bab9d Mon Sep 17 00:00:00 2001 From: Prateek28a Date: Tue, 17 May 2022 10:30:52 +0930 Subject: [PATCH 11/13] Uncommented clear() to avoid having duplicate columns --- .../org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java index 66a1460d719..2df211db256 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java @@ -26,7 +26,7 @@ public void show(MainTable mainTable) { mainTable.getColumns().forEach(tableColumn -> radioMenuItems.add(createRadioMenuItem(tableColumn))); // Clean items and add newItems - // this.getItems().clear(); + this.getItems().clear(); this.getItems().addAll(radioMenuItems); From 18c67613b217abe460819548cb03f606c493daee Mon Sep 17 00:00:00 2001 From: danglt Date: Tue, 17 May 2022 10:50:29 +0930 Subject: [PATCH 12/13] Add link to the preferences entry table in context menu. (credit to @sj30001) --- .../org/jabref/gui/maintable/MainTable.java | 2 +- .../MainTableHeaderRightClickMenu.java | 23 +++++++++++++++++-- .../preferences/PreferencesDialogView.java | 4 ++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 3be9d99229f..f4ea98d0817 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -134,7 +134,7 @@ public MainTable(MainTableDataModel model, this.getSortOrder().clear(); - new MainTableHeaderRightClickMenu().show(this); + new MainTableHeaderRightClickMenu().show(this, libraryTab, dialogService); /* KEEP for debugging purposes for (var colModel : mainTablePreferences.getColumnPreferences().getColumnSortOrder()) { diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java index 66a1460d719..fa18a373fac 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java @@ -4,16 +4,22 @@ 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; - public void show(MainTable mainTable) { + public void show(MainTable mainTable, LibraryTab libraryTab, DialogService dialogService) { System.out.println("show()"); mT = mainTable; mainTable.setOnContextMenuRequested(clickEvent -> { @@ -25,10 +31,23 @@ public void show(MainTable mainTable) { List 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().clear(); this.getItems().addAll(radioMenuItems); + this.getItems().addAll(line, columnsPreferences); // Show ContextMenu this.show(mainTable, clickEvent.getScreenX(), clickEvent.getScreenY()); diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java index 4615300d502..6b778de7ae0 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java @@ -59,6 +59,10 @@ public PreferencesDialogViewModel getViewModel() { return viewModel; } + public ListView getPreferenceTabList() { + return preferenceTabList; + } + @FXML private void initialize() { viewModel = new PreferencesDialogViewModel(dialogService, preferencesService, frame); From a02f962f2c3c79bd0d963af5931ab87d9d6cfa51 Mon Sep 17 00:00:00 2001 From: Prateek28a Date: Wed, 18 May 2022 19:08:45 +0930 Subject: [PATCH 13/13] Created a new function to create any type of column --- .../gui/maintable/MainTableColumnFactory.java | 41 +++++++++++++++++++ .../MainTableHeaderRightClickMenu.java | 9 +++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index ece234f9ff4..b0d678aa3ec 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -256,4 +256,45 @@ private TableColumn> createExtraFileCol private TableColumn createLibraryColumn(MainTableColumnModel columnModel) { return new LibraryColumn(columnModel); } + + /** + * Create any single column + */ + public TableColumn 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; + } } diff --git a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java index 2df211db256..f8ee97921db 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableHeaderRightClickMenu.java @@ -44,13 +44,18 @@ private RadioMenuItem createRadioMenuItem(TableColumn radioMenuItem.setOnAction(event -> { // Return the column name when we click an item from context menu // System.out.println(((MainTableColumn) tableColumn).getModel().getName()); - removeColumns(tableColumn); + removeColumn(tableColumn); }); return radioMenuItem; } - public void removeColumns(TableColumn tableColumn) { + public void addColumn(MainTableColumn column, MainTableColumnFactory creator) { + MainTableColumnModel columnModel = column.getModel(); + creator.createColumn(columnModel); + } + + public void removeColumn(TableColumn tableColumn) { mT.getColumns().removeIf(tableCol -> tableCol == tableColumn); } }