diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index ab8631489d5..9c2f2ddb6d2 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -121,12 +121,12 @@ public class BasePanel extends StackPane { // Keeps track of the string dialog if it is open. private final Map actions = new HashMap<>(); private final SidePaneManager sidePaneManager; - private final BasePanelPreferences preferences; private final ExternalFileTypes externalFileTypes; private final EntryEditor entryEditor; private final DialogService dialogService; private MainTable mainTable; + private BasePanelPreferences preferences; // To contain instantiated entry editors. This is to save time // As most enums, this must not be null private BasePanelMode mode = BasePanelMode.SHOWING_NOTHING; @@ -727,6 +727,8 @@ public void actionPerformed(ActionEvent e) { } public void setupMainPanel() { + preferences = BasePanelPreferences.from(Globals.prefs); + splitPane = new SplitPane(); splitPane.setOrientation(Orientation.VERTICAL); adjustSplitter(); // restore last splitting state (before mainTable is created as creation affects the stored size of the entryEditors) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index d8304f472cd..74c2e327603 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -694,41 +694,17 @@ private MenuBar createMenu() { ); if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) { - boolean menuItemAdded = false; - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) { - edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.RANKING, factory, undoManager)); - menuItemAdded = true; - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RELEVANCE)) { - edit.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.RELEVANCE, factory)); - menuItemAdded = true; - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_QUALITY)) { - edit.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.QUALITY, factory)); - menuItemAdded = true; - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRINTED)) { - edit.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.PRINTED, factory)); - menuItemAdded = true; - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) { - edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.PRIORITY, factory, undoManager)); - menuItemAdded = true; - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) { - edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.READ_STATUS, factory, undoManager)); - menuItemAdded = true; - } - - if (menuItemAdded) { - edit.getItems().add(new SeparatorMenuItem()); - } + edit.getItems().addAll( + SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.RANKING, factory, undoManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.RELEVANCE, factory), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.QUALITY, factory), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.PRINTED, factory), + SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.PRIORITY, factory, undoManager), + SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.READ_STATUS, factory, undoManager), + new SeparatorMenuItem() + ); } + //@formatter:off library.getItems().addAll( factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, Globals.prefs, stateManager)), diff --git a/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java b/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java index c02ab26df61..f2a8364f7c7 100644 --- a/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java +++ b/src/main/java/org/jabref/gui/maintable/ColumnPreferences.java @@ -5,29 +5,31 @@ import javafx.scene.control.TableColumn.SortType; -import org.jabref.model.entry.field.SpecialField; - public class ColumnPreferences { public static final double DEFAULT_FIELD_LENGTH = 100; private final boolean showFileColumn; private final boolean showUrlColumn; private final boolean preferDoiOverUrl; - private final boolean showEprintColumn; - private final List normalColumns; - private final List specialFieldColumns; - private final List extraFileColumns; + private final boolean showEPrintColumn; + private final List columnNames; + private final boolean specialFieldsEnabled; + private final boolean autoSyncSpecialFieldsToKeyWords; + private final boolean serializeSpecialFields; + private final boolean extraFileColumnsEnabled; private final Map columnWidths; private final Map columnSortType; - public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean preferDoiOverUrl, boolean showEprintColumn, List normalColumns, List specialFieldColumns, List extraFileColumns, Map columnWidths, Map columnSortType) { + public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean preferDoiOverUrl, boolean showEPrintColumn, List columnNames, boolean specialFieldsEnabled, boolean autoSyncSpecialFieldsToKeyWords, boolean serializeSpecialFields, boolean extraFileColumnsEnabled, Map columnWidths, Map columnSortType) { this.showFileColumn = showFileColumn; this.showUrlColumn = showUrlColumn; this.preferDoiOverUrl = preferDoiOverUrl; - this.showEprintColumn = showEprintColumn; - this.normalColumns = normalColumns; - this.specialFieldColumns = specialFieldColumns; - this.extraFileColumns = extraFileColumns; + this.showEPrintColumn = showEPrintColumn; + this.columnNames = columnNames; + this.specialFieldsEnabled = specialFieldsEnabled; + this.autoSyncSpecialFieldsToKeyWords = autoSyncSpecialFieldsToKeyWords; + this.serializeSpecialFields = serializeSpecialFields; + this.extraFileColumnsEnabled = extraFileColumnsEnabled; this.columnWidths = columnWidths; this.columnSortType = columnSortType; } @@ -45,22 +47,30 @@ public boolean preferDoiOverUrl() { } public boolean showEprintColumn() { - return showEprintColumn; + return showEPrintColumn; } - public List getExtraFileColumns() { - return extraFileColumns; + public boolean getSpecialFieldsEnabled() { return specialFieldsEnabled; } + + public boolean getAutoSyncSpecialFieldsToKeyWords() { + return autoSyncSpecialFieldsToKeyWords; } - public List getSpecialFieldColumns() { - return specialFieldColumns; + public boolean getSerializeSpecialFields() { + return serializeSpecialFields; + } + + public boolean getExtraFileColumnsEnabled() { return extraFileColumnsEnabled; } + + public List getColumnNames() { + return columnNames; } - public List getNormalColumns() { - return normalColumns; + public Map getColumnWidths() { + return columnWidths; } - public double getPrefColumnWidth(String columnName) { + public double getColumnWidth(String columnName) { return columnWidths.getOrDefault(columnName, DEFAULT_FIELD_LENGTH); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index 2c2845638e5..45fc7c7b72c 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -33,6 +33,7 @@ import org.jabref.gui.icon.JabRefIcon; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; import org.jabref.gui.specialfields.SpecialFieldViewModel; +import org.jabref.gui.util.FieldsUtil; import org.jabref.gui.util.OptionalValueTableCellFactory; import org.jabref.gui.util.ValueTableCellFactory; import org.jabref.gui.util.comparator.RankingFieldComparator; @@ -81,12 +82,11 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre public List> createColumns() { List> columns = new ArrayList<>(); columns.add(createGroupColumn()); - // Add column for linked files + if (preferences.showFileColumn()) { columns.add(createFileColumn()); } - // Add column for DOI/URL if (preferences.showUrlColumn()) { if (preferences.preferDoiOverUrl()) { columns.add(createUrlOrDoiColumn(IconTheme.JabRefIcons.DOI, StandardField.DOI, StandardField.URL)); @@ -95,21 +95,19 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre } } - // Add column for eprints if (preferences.showEprintColumn()) { columns.add(createEprintColumn(IconTheme.JabRefIcons.WWW, StandardField.EPRINT)); } - // Add columns for other file types - columns.addAll(preferences.getExtraFileColumns().stream().map(this::createExtraFileColumn).collect(Collectors.toList())); - - // Add 'normal' bibtex fields as configured in the preferences - columns.addAll(createNormalColumns()); - - // Add the "special" icon columns (e.g., ranking, file, ...) that are enabled in preferences - for (SpecialField field : preferences.getSpecialFieldColumns()) { - columns.add(createSpecialFieldColumn((field))); - } + preferences.getColumnNames().stream().map(FieldFactory::parseField).forEach(field -> { + if (field instanceof FieldsUtil.ExtraFilePseudoField) { + columns.add(createExtraFileColumn(field.getName())); + } else if (field instanceof SpecialField) { + columns.add(createSpecialFieldColumn((SpecialField) field)); + } else { + columns.add(createNormalColumn(field)); + } + }); return columns; } @@ -163,20 +161,15 @@ private Node createGroupColorRegion(BibEntryTableViewModel entry, List> createNormalColumns() { - List> columns = new ArrayList<>(); - - // Read table columns from preferences - for (String columnName : preferences.getNormalColumns()) { - NormalTableColumn column = new NormalTableColumn(columnName, FieldFactory.parseOrFields(columnName), database.getDatabase()); + private TableColumn createNormalColumn(Field field) { + String columnName = field.getName(); + NormalTableColumn column = new NormalTableColumn(columnName, FieldFactory.parseOrFields(columnName), database.getDatabase()); new ValueTableCellFactory() .withText(text -> text) .install(column); column.setSortable(true); - column.setPrefWidth(preferences.getPrefColumnWidth(columnName)); - columns.add(column); - } - return columns; + column.setPrefWidth(preferences.getColumnWidth(columnName)); + return column; } private TableColumn> createSpecialFieldColumn(SpecialField specialField) { diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index dbabf52e37e..7029810a2fa 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -48,29 +48,12 @@ public static ContextMenu create(BibEntryTableViewModel entry, KeyBindingReposit contextMenu.getItems().add(new SeparatorMenuItem()); if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) { - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) { - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, panel)); - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RELEVANCE)) { - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, panel)); - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_QUALITY)) { - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, panel)); - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRINTED)) { - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, panel)); - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) { - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, panel)); - } - - if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) { - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, panel)); - } + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, panel)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, panel)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, panel)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, panel)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, panel)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, panel)); } contextMenu.getItems().add(new SeparatorMenuItem()); diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java index d1a64d69c58..94d9af78de5 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java @@ -49,7 +49,7 @@ public PreferencesDialogViewModel(DialogService dialogService, TaskExecutor task new GeneralTabView(prefs), new FileTabView(prefs), new TablePrefsTab(prefs), - new TableColumnsTab(prefs, frame), + new TableColumnsTabView(prefs), new PreviewTabView(prefs), new ExternalTabView(prefs, frame), new GroupsTabView(prefs), diff --git a/src/main/java/org/jabref/gui/preferences/TableColumnsItemModel.java b/src/main/java/org/jabref/gui/preferences/TableColumnsItemModel.java new file mode 100644 index 00000000000..9ac5faa8fb7 --- /dev/null +++ b/src/main/java/org/jabref/gui/preferences/TableColumnsItemModel.java @@ -0,0 +1,90 @@ +package org.jabref.gui.preferences; + +import java.util.Objects; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.beans.value.ObservableValue; + +import org.jabref.gui.maintable.ColumnPreferences; +import org.jabref.logic.l10n.Localization; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.UnknownField; + +public class TableColumnsItemModel { + + private final ObjectProperty field; + private final StringProperty name = new SimpleStringProperty(""); + private final DoubleProperty length = new SimpleDoubleProperty(ColumnPreferences.DEFAULT_FIELD_LENGTH); + private final BooleanProperty editableProperty = new SimpleBooleanProperty(true); + + public TableColumnsItemModel() { + this.field = new SimpleObjectProperty<>(new UnknownField(Localization.lang("New column"))); + } + + public TableColumnsItemModel(Field field) { + this.field = new SimpleObjectProperty<>(field); + this.editableProperty.setValue(this.field.get() instanceof UnknownField); + } + + public TableColumnsItemModel(Field field, double length) { + this.field = new SimpleObjectProperty<>(field); + this.length.setValue(length); + this.editableProperty.setValue(this.field.get() instanceof UnknownField); + } + + public void setField(Field field) { + this.field.set(field); + } + + public Field getField() { + return field.get(); + } + + public ObservableValue fieldProperty() { return this.field; } + + public void setName(String name) { + if (editableProperty.get()) { + field.setValue(new UnknownField(name)); + } + } + + public String getName() { + return field.get().getName(); + } + + public StringProperty nameProperty() { return this.name; } + + public void setLength(double length) { + this.length.set(length); + } + + public double getLength() { + return length.get(); + } + + public DoubleProperty lengthProperty() { return this.length; } + + public ReadOnlyBooleanProperty editableProperty() { return editableProperty; } + + @Override + public int hashCode() { + return Objects.hash(field); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof TableColumnsItemModel) { + return Objects.equals(this.field, ((TableColumnsItemModel) obj).field); + } else { + return false; + } + } +} diff --git a/src/main/java/org/jabref/gui/preferences/TableColumnsTab.fxml b/src/main/java/org/jabref/gui/preferences/TableColumnsTab.fxml new file mode 100644 index 00000000000..69912ee367c --- /dev/null +++ b/src/main/java/org/jabref/gui/preferences/TableColumnsTab.fxml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + +