From 3d891ca5bd4b1081b0244950d53a32fd7e954072 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Sat, 10 Aug 2019 05:40:12 +0200 Subject: [PATCH 01/28] Initial --- .../gui/preferences/PreferencesActions.java | 97 ++++++++++ .../PreferencesDialogViewModel.java | 2 +- .../TableColumnsNodeViewModel.java | 58 ++++++ .../gui/preferences/TableColumnsTab.fxml | 97 ++++++++++ .../gui/preferences/TableColumnsTabView.java | 142 ++++++++++++++ .../preferences/TableColumnsTabViewModel.java | 176 ++++++++++++++++++ 6 files changed, 571 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/jabref/gui/preferences/PreferencesActions.java create mode 100644 src/main/java/org/jabref/gui/preferences/TableColumnsNodeViewModel.java create mode 100644 src/main/java/org/jabref/gui/preferences/TableColumnsTab.fxml create mode 100644 src/main/java/org/jabref/gui/preferences/TableColumnsTabView.java create mode 100644 src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesActions.java b/src/main/java/org/jabref/gui/preferences/PreferencesActions.java new file mode 100644 index 00000000000..94c091b9166 --- /dev/null +++ b/src/main/java/org/jabref/gui/preferences/PreferencesActions.java @@ -0,0 +1,97 @@ +package org.jabref.gui.preferences; + +import org.jabref.gui.actions.Action; +import org.jabref.gui.icon.IconTheme; +import org.jabref.gui.icon.JabRefIcon; +import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.logic.l10n.Localization; + +import java.util.Optional; + +public enum PreferencesActions implements Action { + COLUMN_SORT_UP(Localization.lang("Sort Up"), Localization.lang("Sort column one step upwards"), IconTheme.JabRefIcons.UP), + COLUMN_SORT_DOWN(Localization.lang("Sort Down"), Localization.lang("Sort column one step downwards"), IconTheme.JabRefIcons.DOWN), + COLUMN_ADD(Localization.lang("Add"), Localization.lang("Add custom column"), IconTheme.JabRefIcons.ADD_NOBOX), + COLUMN_REMOVE(Localization.lang("Remove"), Localization.lang("Remove selected custom column"), IconTheme.JabRefIcons.REMOVE_NOBOX), + COLUMNS_UPDATE(Localization.lang("Update"), Localization.lang("Update to current column order"), IconTheme.JabRefIcons.REFRESH); + + private final String text; + private final String description; + private final Optional icon; + private final Optional keyBinding; + + PreferencesActions(String text) { + this(text, ""); + } + + PreferencesActions(String text, IconTheme.JabRefIcons icon) { + this.text = text; + this.description = ""; + this.icon = Optional.of(icon); + this.keyBinding = Optional.empty(); + } + + PreferencesActions(String text, IconTheme.JabRefIcons icon, KeyBinding keyBinding) { + this.text = text; + this.description = ""; + this.icon = Optional.of(icon); + this.keyBinding = Optional.of(keyBinding); + } + + PreferencesActions(String text, String description, IconTheme.JabRefIcons icon) { + this.text = text; + this.description = description; + this.icon = Optional.of(icon); + this.keyBinding = Optional.empty(); + } + + PreferencesActions(String text, String description, IconTheme.JabRefIcons icon, KeyBinding keyBinding) { + this.text = text; + this.description = description; + this.icon = Optional.of(icon); + this.keyBinding = Optional.of(keyBinding); + } + + PreferencesActions(String text, KeyBinding keyBinding) { + this.text = text; + this.description = ""; + this.keyBinding = Optional.of(keyBinding); + this.icon = Optional.empty(); + } + + PreferencesActions(String text, String description) { + this.text = text; + this.description = description; + this.icon = Optional.empty(); + this.keyBinding = Optional.empty(); + } + + PreferencesActions(String text, String description, KeyBinding keyBinding) { + this.text = text; + this.description = description; + this.icon = Optional.empty(); + this.keyBinding = Optional.of(keyBinding); + } + + @Override + public Optional getIcon() { + return icon; + } + + @Override + public Optional getKeyBinding() { + return keyBinding; + } + + @Override + public String getText() { + return text; + } + + @Override + public String getDescription() { + return description; + } +} + + diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java index 0347e948824..c30c1ad75bc 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java @@ -48,7 +48,7 @@ public PreferencesDialogViewModel(DialogService dialogService, TaskExecutor task preferenceTabs.add(new GeneralTabView(prefs)); preferenceTabs.add(new FileTabView(prefs)); preferenceTabs.add(new TablePrefsTab(prefs)); - preferenceTabs.add(new TableColumnsTab(prefs, frame)); + preferenceTabs.add(new TableColumnsTabView(prefs, frame)); preferenceTabs.add(new PreviewTabView(prefs)); preferenceTabs.add(new ExternalTabView(prefs, frame)); preferenceTabs.add(new GroupsPrefsTab(prefs)); diff --git a/src/main/java/org/jabref/gui/preferences/TableColumnsNodeViewModel.java b/src/main/java/org/jabref/gui/preferences/TableColumnsNodeViewModel.java new file mode 100644 index 00000000000..19b52096c0d --- /dev/null +++ b/src/main/java/org/jabref/gui/preferences/TableColumnsNodeViewModel.java @@ -0,0 +1,58 @@ +package org.jabref.gui.preferences; + +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleObjectProperty; +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 TableColumnsNodeViewModel { + + private final SimpleObjectProperty field; + private final SimpleDoubleProperty length; + private final ReadOnlyBooleanProperty editablePropery; + + public TableColumnsNodeViewModel() { + this.field = new SimpleObjectProperty<>(new UnknownField(Localization.lang("new Column"))); + this.length = new SimpleDoubleProperty(ColumnPreferences.DEFAULT_FIELD_LENGTH); + this.editablePropery = new SimpleBooleanProperty(true); + } + + public TableColumnsNodeViewModel(Field field) { + this.field = new SimpleObjectProperty<>(field); + this.length = new SimpleDoubleProperty(ColumnPreferences.DEFAULT_FIELD_LENGTH); + this.editablePropery = new SimpleBooleanProperty(this.field.get() instanceof UnknownField); + } + + public TableColumnsNodeViewModel(Field field, double length) { + this.field = new SimpleObjectProperty<>(field); + this.length = new SimpleDoubleProperty(length); + this.editablePropery = new SimpleBooleanProperty(this.field.get() instanceof UnknownField); + } + + public Field getField() { + return field.get(); + } + + public void setField(Field field) { + this.field.set(field); + } + + public String getName() { + return field.get().getName(); + } + + public void setName(String name) { + if (editablePropery.get()) { + field.setValue(new UnknownField(name)); + } + } + + public ReadOnlyBooleanProperty editablePropery() { + return editablePropery; + } + +} 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..36e26d199fa --- /dev/null +++ b/src/main/java/org/jabref/gui/preferences/TableColumnsTab.fxml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + +