From 919fcdb397015ebdb60255938522543984f46130 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 4 Jan 2020 16:57:02 +0100 Subject: [PATCH 01/19] refactor to display entry types and all fields --- .../CustomEntryTypeDialogViewModel.java | 59 +++++++++---------- .../CustomizeEntryTypeDialogView.java | 42 ++++++------- .../model/entry/field/FieldFactory.java | 2 +- 3 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java index 0dddfbead21..36403143a24 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java @@ -1,57 +1,56 @@ package org.jabref.gui.customentrytypes; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.collections.FXCollections; + +import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.field.Field; -import org.jabref.model.entry.types.EntryType; +import org.jabref.model.entry.field.FieldFactory; +import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; public class CustomEntryTypeDialogViewModel { + private ListProperty entryTypesProperty; + private ListProperty fieldsProperty; + public CustomEntryTypeDialogViewModel() { + entryTypesProperty = new SimpleListProperty(FXCollections.observableArrayList(BiblatexEntryTypeDefinitions.ALL)); + fieldsProperty = new SimpleListProperty(FXCollections.observableArrayList(FieldFactory.getAllFields())); } - public void addNewOptionalField2() { - // TODO Auto-generated method stub - + public ListProperty entryTypesProperty() { + return this.entryTypesProperty; } - public void addNewOptionalField() { - // TODO Auto-generated method stub - + public ListProperty fieldsProperty() { + return this.fieldsProperty; } - public void addNewRequiredField() { - // TODO Auto-generated method stub + public enum FieldType { - } + REQUIRED("Required"), + OTPIONAL("Optional"); - public void addNewCustomEntryType() { - // TODO Auto-generated method stub + private String name; - } + FieldType(String name) { + this.name = name; + } - public Object removeEntryType(EntryType focusedItem) { - // TODO Auto-generated method stub - return null; + public String getDisplayName() { + return this.name; + } } - public Object removeRequiredField(Field focusedItem) { - // TODO Auto-generated method stub - return null; - } + public void addNewField() { + //We need to add a new unknown field - public Object removeOptionalField(Field focusedItem) { - // TODO Auto-generated method stub - return null; } - public Object removeOptional2Field(Field focusedItem) { + public void addNewCustomEntryType() { // TODO Auto-generated method stub - return null; - } - public enum FieldType { - REQUIRED, - PRIMARY_OPTIONAL, - SECONDARY_OPTIONAL } } diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java index fd02326b7e2..e50472b18d6 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java @@ -1,5 +1,7 @@ package org.jabref.gui.customentrytypes; +import java.util.EnumSet; + import javafx.beans.property.ReadOnlyStringWrapper; import javafx.fxml.FXML; import javafx.scene.control.ButtonType; @@ -7,8 +9,11 @@ import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; +import org.jabref.gui.customentrytypes.CustomEntryTypeDialogViewModel.FieldType; import org.jabref.gui.util.BaseDialog; +import org.jabref.gui.util.ValueTableCellFactory; import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.types.EntryType; @@ -16,13 +21,13 @@ public class CustomizeEntryTypeDialogView extends BaseDialog { - @FXML private TableView entryTypes; - @FXML private TableColumn entryTypColumn; - @FXML private TableColumn entryTypeActionsColumn; - @FXML private ComboBox addNewEntryType; + @FXML private TableView entryTypes; + @FXML private TableColumn entryTypColumn; + @FXML private TableColumn entryTypeActionsColumn; + @FXML private ComboBox addNewEntryType; @FXML private TableView requiredFields; @FXML private TableColumn requiredFieldsNameColumn; - @FXML private TableColumn fieldTypeColumn; + @FXML private TableColumn fieldTypeColumn; @FXML private TableColumn fieldTypeActionColumn; @FXML private ComboBox addNewField; @FXML private ButtonType applyButton; @@ -44,30 +49,27 @@ private void initialize() { } private void setupTable() { - entryTypColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getDisplayName())); - } + entryTypColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getType().getDisplayName())); + fieldTypeColumn.setCellFactory(cellData -> new RadioButtonCell<>(EnumSet.allOf(FieldType.class))); + new ValueTableCellFactory().withText(FieldType::getDisplayName).install(fieldTypeColumn); - @FXML - void addEntryType() { - viewModel.addNewCustomEntryType(); - } - - @FXML - void addRequiredFields() { - viewModel.addNewRequiredField(); + requiredFieldsNameColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getDisplayName())); + new ValueTableCellFactory().withText(FieldType::getDisplayName).install(fieldTypeColumn); + entryTypes.itemsProperty().bind(viewModel.entryTypesProperty()); + //TODO Change to the new viewmodel + requiredFields.itemsProperty().bind(viewModel.fieldsProperty()); } @FXML - void addOptionalField() { - viewModel.addNewOptionalField(); - + void addEntryType() { + viewModel.addNewCustomEntryType(); } @FXML - void addOptionalField2() { - viewModel.addNewOptionalField2(); + void addNewField() { + viewModel.addNewField(); } diff --git a/src/main/java/org/jabref/model/entry/field/FieldFactory.java b/src/main/java/org/jabref/model/entry/field/FieldFactory.java index a5086283f6a..7372ffc1345 100644 --- a/src/main/java/org/jabref/model/entry/field/FieldFactory.java +++ b/src/main/java/org/jabref/model/entry/field/FieldFactory.java @@ -118,7 +118,7 @@ private static Set getFieldsFiltered(Predicate selector) { .collect(Collectors.toSet()); } - private static Set getAllFields() { + public static Set getAllFields() { Set fields = new HashSet<>(); fields.addAll(EnumSet.allOf(IEEEField.class)); fields.addAll(EnumSet.allOf(InternalField.class)); From 0c8c8c55f75874c1d646ab06418f6b86a103be92 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 5 Jan 2020 18:59:15 +0100 Subject: [PATCH 02/19] remove logger plugin needed for eclipse --- .../jabref/gui/logging/plugins/Log4jPlugins.java | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/logging/plugins/Log4jPlugins.java diff --git a/src/main/java/org/jabref/gui/logging/plugins/Log4jPlugins.java b/src/main/java/org/jabref/gui/logging/plugins/Log4jPlugins.java deleted file mode 100644 index d43e19ed567..00000000000 --- a/src/main/java/org/jabref/gui/logging/plugins/Log4jPlugins.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.jabref.gui.logging.plugins; - -import org.apache.logging.log4j.plugins.processor.PluginEntry; -import org.apache.logging.log4j.plugins.processor.PluginService; - -public class Log4jPlugins extends PluginService { - - private static PluginEntry[] entries = new PluginEntry[] { - new PluginEntry("ourapplicationinsightsappender", "org.jabref.gui.logging.ApplicationInsightsAppender", "appender", true, false, "Core"), - new PluginEntry("guiappender", "org.jabref.gui.logging.GuiAppender", "appender", true, false, "Core") - }; - @Override - public PluginEntry[] getEntries() { return entries;} -} From 7b4bf0e1f161282ad3b20d6d723b6d60f1416875 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 6 Jan 2020 17:07:40 +0100 Subject: [PATCH 03/19] add data to table when entry type selected --- .../CustomEntryTypeDialogViewModel.java | 26 ++++++++++++ .../CustomizeEntryTypeDialogView.java | 26 +++++++----- .../gui/customentrytypes/FieldViewModel.java | 41 +++++++++++++++++++ 3 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java index 36403143a24..3f4265927b9 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java @@ -1,7 +1,12 @@ package org.jabref.gui.customentrytypes; +import java.util.List; +import java.util.stream.Collectors; + import javafx.beans.property.ListProperty; +import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleListProperty; +import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; import org.jabref.model.entry.BibEntryType; @@ -9,15 +14,27 @@ import org.jabref.model.entry.field.FieldFactory; import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; +import org.fxmisc.easybind.EasyBind; + public class CustomEntryTypeDialogViewModel { private ListProperty entryTypesProperty; private ListProperty fieldsProperty; + private ObjectProperty selectedEntryTypesProperty = new SimpleObjectProperty<>(); + private ListProperty fieldsForTypeProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); public CustomEntryTypeDialogViewModel() { entryTypesProperty = new SimpleListProperty(FXCollections.observableArrayList(BiblatexEntryTypeDefinitions.ALL)); fieldsProperty = new SimpleListProperty(FXCollections.observableArrayList(FieldFactory.getAllFields())); + + EasyBind.subscribe(selectedEntryTypesProperty, type -> { + if (type != null) { + List fields = type.getAllFields().stream().map(bibField -> new FieldViewModel(bibField.getField(), type.isRequired(bibField.getField()))).collect(Collectors.toList()); + this.fieldsForTypeProperty.setValue(FXCollections.observableArrayList(fields)); + } + }); + } public ListProperty entryTypesProperty() { @@ -53,4 +70,13 @@ public void addNewCustomEntryType() { // TODO Auto-generated method stub } + + public ObjectProperty selectedEntryTypeProperty() { + return this.selectedEntryTypesProperty; + } + + public ListProperty fieldsforTypesProperty() { + return this.fieldsForTypeProperty; + } + } diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java index e50472b18d6..3e0ecff1da2 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java @@ -25,11 +25,11 @@ public class CustomizeEntryTypeDialogView extends BaseDialog { @FXML private TableColumn entryTypColumn; @FXML private TableColumn entryTypeActionsColumn; @FXML private ComboBox addNewEntryType; - @FXML private TableView requiredFields; - @FXML private TableColumn requiredFieldsNameColumn; - @FXML private TableColumn fieldTypeColumn; - @FXML private TableColumn fieldTypeActionColumn; - @FXML private ComboBox addNewField; + @FXML private TableView requiredFields; + @FXML private TableColumn requiredFieldsNameColumn; + @FXML private TableColumn fieldTypeColumn; + @FXML private TableColumn fieldTypeActionColumn; + @FXML private ComboBox addNewField; @FXML private ButtonType applyButton; private final CustomEntryTypeDialogViewModel viewModel; @@ -51,15 +51,21 @@ private void initialize() { private void setupTable() { entryTypColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getType().getDisplayName())); + entryTypes.setItems(viewModel.entryTypesProperty()); + entryTypes.getSelectionModel().selectFirst(); + fieldTypeColumn.setCellFactory(cellData -> new RadioButtonCell<>(EnumSet.allOf(FieldType.class))); - new ValueTableCellFactory().withText(FieldType::getDisplayName).install(fieldTypeColumn); + fieldTypeColumn.setCellValueFactory(item -> item.getValue().fieldTypeProperty()); - requiredFieldsNameColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getDisplayName())); - new ValueTableCellFactory().withText(FieldType::getDisplayName).install(fieldTypeColumn); + requiredFieldsNameColumn.setCellValueFactory(item -> item.getValue().fieldNameProperty()); - entryTypes.itemsProperty().bind(viewModel.entryTypesProperty()); + viewModel.selectedEntryTypeProperty().bind(entryTypes.getSelectionModel().selectedItemProperty()); + addNewEntryType.setItems(viewModel.entryTypesProperty()); //TODO Change to the new viewmodel - requiredFields.itemsProperty().bind(viewModel.fieldsProperty()); + + addNewField.setItems(viewModel.fieldsProperty()); + requiredFields.itemsProperty().bindBidirectional(viewModel.fieldsforTypesProperty()); + } @FXML diff --git a/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java new file mode 100644 index 00000000000..9e8f4358ff4 --- /dev/null +++ b/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java @@ -0,0 +1,41 @@ +package org.jabref.gui.customentrytypes; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +import org.jabref.gui.customentrytypes.CustomEntryTypeDialogViewModel.FieldType; +import org.jabref.model.entry.field.Field; + +public class FieldViewModel { + + private final ObjectProperty fieldTypeProperty = new SimpleObjectProperty<>(); + private final StringProperty fieldNameProperty = new SimpleStringProperty(""); + private final Field field; + + public FieldViewModel(Field field, FieldType fieldType) { + this.field = field; + this.fieldNameProperty.setValue(field.getDisplayName()); + this.fieldTypeProperty.setValue(fieldType); + } + + public FieldViewModel(Field field, boolean required) { + this.field = field; + + this.fieldNameProperty.setValue(field.getDisplayName()); + this.fieldTypeProperty.setValue(required ? FieldType.REQUIRED : FieldType.OTPIONAL); + } + + public ObjectProperty fieldTypeProperty() { + return this.fieldTypeProperty; + } + + public StringProperty fieldNameProperty() { + return this.fieldNameProperty; + } + + public Field getField() { + return this.field; + } +} From 5bdd610a98b3147ee7fd1dcdeb8e8f663b37446a Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 6 Jan 2020 17:34:07 +0100 Subject: [PATCH 04/19] some layout improvements --- .../CustomizeEntryTypeDialog.fxml | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml index 39b9892d363..bec99b8bd3e 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml @@ -1,5 +1,6 @@ + @@ -10,38 +11,41 @@ - + - + - + + + + + + + + + + + From 391aaca41762eeb0b5049f0bcc6946a66e0e4ed5 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Wed, 8 Jan 2020 15:11:55 +0100 Subject: [PATCH 08/19] add new entry type to the list --- .../CustomEntryTypeDialogViewModel.java | 40 +++++++++++++++---- .../CustomizeEntryTypeDialogView.java | 10 ++++- .../gui/customentrytypes/FieldViewModel.java | 17 +++++--- src/main/resources/l10n/JabRef_en.properties | 7 +++- 4 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java index 116c608143b..a85054853c3 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui.customentrytypes; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -12,10 +13,14 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; +import org.jabref.model.entry.types.BibtexEntryTypeDefinitions; +import org.jabref.model.entry.types.EntryType; +import org.jabref.model.entry.types.UnknownEntryType; import org.fxmisc.easybind.EasyBind; @@ -24,23 +29,33 @@ public class CustomEntryTypeDialogViewModel { private ListProperty entryTypesProperty; private ListProperty fieldsProperty; private ObjectProperty selectedEntryTypesProperty = new SimpleObjectProperty<>(); - private ListProperty fieldsForTypeProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); + private ListProperty fieldsForTypeProperty; private ObjectProperty selectedFieldToAddProperty = new SimpleObjectProperty<>(); private StringProperty entryTypeToAddProperty = new SimpleStringProperty(""); private ObservableList entryTypes; + private ObservableList existingFieldsForType; private ObjectProperty newFieldToAddProperty = new SimpleObjectProperty<>(); + private BibDatabaseMode mode; + private ObservableList allFieldsForType; - public CustomEntryTypeDialogViewModel() { + public CustomEntryTypeDialogViewModel(BibDatabaseMode mode) { + this.mode = mode; - entryTypes = FXCollections.observableArrayList(BiblatexEntryTypeDefinitions.ALL); + List alllTypes = mode == mode.BIBLATEX ? BiblatexEntryTypeDefinitions.ALL : BibtexEntryTypeDefinitions.ALL; + entryTypes = FXCollections.observableArrayList(alllTypes); entryTypesProperty = new SimpleListProperty<>(entryTypes); - fieldsProperty = new SimpleListProperty(FXCollections.observableArrayList(FieldFactory.getAllFields())); + fieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList(FieldFactory.getAllFields())); + + existingFieldsForType = FXCollections.observableArrayList(); + allFieldsForType = FXCollections.observableArrayList(); + + this.fieldsForTypeProperty = new SimpleListProperty<>(existingFieldsForType); EasyBind.subscribe(selectedEntryTypesProperty, type -> { if (type != null) { - List fields = type.getAllFields().stream().map(bibField -> new FieldViewModel(bibField.getField(), type.isRequired(bibField.getField()))).collect(Collectors.toList()); - this.fieldsForTypeProperty.setValue(FXCollections.observableArrayList(fields)); + List fields = type.getAllFields().stream().map(bibField -> new FieldViewModel(bibField.getField(), type.isRequired(bibField.getField()), type)).collect(Collectors.toList()); + existingFieldsForType.setAll(fields); } }); @@ -76,14 +91,23 @@ public String toString() { } public void addNewField() { - // Field field = FieldFactory.parseField(newFieldToAddProperty.getValue()); + + Field field = newFieldToAddProperty.getValue(); + + FieldViewModel model = new FieldViewModel(field, true, selectedEntryTypesProperty.getValue()); + //TODO: How should I add the field to the type? - //Field fieldToAdd = new UnknownField(name) + //BibEntryType type = new BibEntryType(type, fields, requiredFields) + // Globals.entryTypesManager.addCustomOrModifiedType(entryType, mode); } public void addNewCustomEntryType() { + EntryType newentryType = new UnknownEntryType(entryTypeToAddProperty.getValue()); + BibEntryType type = new BibEntryType(newentryType, Collections.emptyList(), Collections.emptyList()); + this.entryTypes.add(type); + // entryTypesManager.addCustomOrModifiedType(overwrittenStandardType ? // BibEntryTypeBuilder //new UnknownEntryType(null). diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java index f237738d163..6995897df08 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java @@ -2,6 +2,8 @@ import java.util.EnumSet; +import javax.inject.Inject; + import javafx.beans.property.ReadOnlyStringWrapper; import javafx.fxml.FXML; import javafx.scene.control.ButtonType; @@ -14,9 +16,11 @@ import org.jabref.gui.customentrytypes.CustomEntryTypeDialogViewModel.FieldType; import org.jabref.gui.util.BaseDialog; import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.UnknownField; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; @@ -33,11 +37,15 @@ public class CustomizeEntryTypeDialogView extends BaseDialog { @FXML private ComboBox addNewField; @FXML private ButtonType applyButton; + @Inject PreferencesService preferencesService; + private final CustomEntryTypeDialogViewModel viewModel; + private BibDatabaseMode mode; public CustomizeEntryTypeDialogView(BibDatabaseContext bibDatabaseContext) { - viewModel = new CustomEntryTypeDialogViewModel(); + viewModel = new CustomEntryTypeDialogViewModel(mode); + this.mode = bibDatabaseContext.getMode(); ViewLoader.view(this) .load() diff --git a/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java index 9e8f4358ff4..ca4b6c1ef80 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java @@ -6,6 +6,7 @@ import javafx.beans.property.StringProperty; import org.jabref.gui.customentrytypes.CustomEntryTypeDialogViewModel.FieldType; +import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.field.Field; public class FieldViewModel { @@ -13,18 +14,17 @@ public class FieldViewModel { private final ObjectProperty fieldTypeProperty = new SimpleObjectProperty<>(); private final StringProperty fieldNameProperty = new SimpleStringProperty(""); private final Field field; + private BibEntryType entryType; - public FieldViewModel(Field field, FieldType fieldType) { + public FieldViewModel(Field field, FieldType fieldType, BibEntryType entryType) { this.field = field; + this.entryType = entryType; this.fieldNameProperty.setValue(field.getDisplayName()); this.fieldTypeProperty.setValue(fieldType); } - public FieldViewModel(Field field, boolean required) { - this.field = field; - - this.fieldNameProperty.setValue(field.getDisplayName()); - this.fieldTypeProperty.setValue(required ? FieldType.REQUIRED : FieldType.OTPIONAL); + public FieldViewModel(Field field, boolean required, BibEntryType entryType) { + this(field, required ? FieldType.REQUIRED : FieldType.OTPIONAL, entryType); } public ObjectProperty fieldTypeProperty() { @@ -38,4 +38,9 @@ public StringProperty fieldNameProperty() { public Field getField() { return this.field; } + + public BibEntryType getEntryType() { + return entryType; + + } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index d87eac682b5..bc96f035096 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2097,4 +2097,9 @@ Select\ all\ changes\ on\ the\ right=Select all changes on the right Dismiss=Dismiss Mark\ all\ changes\ as\ accepted=Mark all changes as accepted -Unmark\ all\ changes=Unmark all changes \ No newline at end of file +Unmark\ all\ changes=Unmark all changes + +Add\ new\ Field=Add new Field +Add\ new\ entry\ type=Add new entry type +Field\ type=Field type +Required\ and\ optional\ fields=Required and optional fields \ No newline at end of file From 7208e0a1d03aae20e24be24c82e38fddda6ac799 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Wed, 8 Jan 2020 23:28:56 +0100 Subject: [PATCH 09/19] use hashmap to associate fields and types TODO: Find out why there are some invisible fields --- .../CustomEntryTypeDialogViewModel.java | 22 ++++++++++++++----- .../CustomizeEntryTypeDialogView.java | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java index a85054853c3..fc067754021 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java @@ -1,7 +1,10 @@ package org.jabref.gui.customentrytypes; +import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import javafx.beans.property.ListProperty; @@ -37,6 +40,7 @@ public class CustomEntryTypeDialogViewModel { private ObjectProperty newFieldToAddProperty = new SimpleObjectProperty<>(); private BibDatabaseMode mode; private ObservableList allFieldsForType; + private Map> typesWithField = new HashMap<>(); public CustomEntryTypeDialogViewModel(BibDatabaseMode mode) { this.mode = mode; @@ -48,14 +52,18 @@ public CustomEntryTypeDialogViewModel(BibDatabaseMode mode) { fieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList(FieldFactory.getAllFields())); existingFieldsForType = FXCollections.observableArrayList(); - allFieldsForType = FXCollections.observableArrayList(); + + for (BibEntryType entryType : alllTypes) { + List fields = entryType.getAllFields().stream().map(bibField -> new FieldViewModel(bibField.getField(), entryType.isRequired(bibField.getField()), entryType)).collect(Collectors.toList()); + typesWithField.put(entryType, fields); + } this.fieldsForTypeProperty = new SimpleListProperty<>(existingFieldsForType); EasyBind.subscribe(selectedEntryTypesProperty, type -> { if (type != null) { - List fields = type.getAllFields().stream().map(bibField -> new FieldViewModel(bibField.getField(), type.isRequired(bibField.getField()), type)).collect(Collectors.toList()); - existingFieldsForType.setAll(fields); + List typesForField = typesWithField.get(type); + existingFieldsForType.setAll(typesForField); } }); @@ -93,9 +101,9 @@ public String toString() { public void addNewField() { Field field = newFieldToAddProperty.getValue(); - FieldViewModel model = new FieldViewModel(field, true, selectedEntryTypesProperty.getValue()); - + typesWithField.computeIfAbsent(selectedEntryTypesProperty.getValue(), key -> new ArrayList<>()).add(model); + existingFieldsForType.add(model); //TODO: How should I add the field to the type? //BibEntryType type = new BibEntryType(type, fields, requiredFields) @@ -105,9 +113,11 @@ public void addNewField() { public void addNewCustomEntryType() { EntryType newentryType = new UnknownEntryType(entryTypeToAddProperty.getValue()); - BibEntryType type = new BibEntryType(newentryType, Collections.emptyList(), Collections.emptyList()); + BibEntryType type = new BibEntryType(newentryType, new ArrayList<>(), Collections.emptyList()); this.entryTypes.add(type); + this.typesWithField.put(type, new ArrayList<>()); + // entryTypesManager.addCustomOrModifiedType(overwrittenStandardType ? // BibEntryTypeBuilder //new UnknownEntryType(null). diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java index 6995897df08..83383a15ca7 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java @@ -60,7 +60,7 @@ private void initialize() { private void setupTable() { entryTypColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getType().getDisplayName())); - entryTypes.setItems(viewModel.entryTypesProperty()); + entryTypes.itemsProperty().bind(viewModel.entryTypesProperty()); entryTypes.getSelectionModel().selectFirst(); fieldTypeColumn.setCellFactory(cellData -> new RadioButtonCell<>(EnumSet.allOf(FieldType.class))); From 9850a673bcc3642d96f390eebf671d37d537895a Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Thu, 9 Jan 2020 19:01:51 +0100 Subject: [PATCH 10/19] add Delete icons to table colums Code proudly reused from calixtus implementation in the preferences --- .../CustomEntryTypeDialogViewModel.java | 28 +++++++++++-- .../CustomizeEntryTypeDialog.fxml | 10 ++++- .../CustomizeEntryTypeDialogView.java | 42 ++++++++++++------- .../gui/customentrytypes/FieldViewModel.java | 6 +++ .../gui/customentrytypes/RadioButtonCell.java | 2 + 5 files changed, 67 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java index fc067754021..607eba298c7 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.stream.Collectors; +import javafx.beans.Observable; import javafx.beans.property.ListProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleListProperty; @@ -15,11 +16,13 @@ import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import javafx.util.StringConverter; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; +import org.jabref.model.entry.field.UnknownField; import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; import org.jabref.model.entry.types.BibtexEntryTypeDefinitions; import org.jabref.model.entry.types.EntryType; @@ -29,6 +32,19 @@ public class CustomEntryTypeDialogViewModel { + public static final StringConverter fieldStringConverter = new StringConverter() { + + @Override + public String toString(Field object) { + return object != null ? object.getDisplayName() : ""; + } + + @Override + public Field fromString(String string) { + return new UnknownField(string); + } + }; + private ListProperty entryTypesProperty; private ListProperty fieldsProperty; private ObjectProperty selectedEntryTypesProperty = new SimpleObjectProperty<>(); @@ -36,10 +52,9 @@ public class CustomEntryTypeDialogViewModel { private ObjectProperty selectedFieldToAddProperty = new SimpleObjectProperty<>(); private StringProperty entryTypeToAddProperty = new SimpleStringProperty(""); private ObservableList entryTypes; - private ObservableList existingFieldsForType; + private ObservableList existingFieldsForType = FXCollections.observableArrayList(extractor -> new Observable[] {extractor.fieldNameProperty(), extractor.fieldTypeProperty()}); private ObjectProperty newFieldToAddProperty = new SimpleObjectProperty<>(); private BibDatabaseMode mode; - private ObservableList allFieldsForType; private Map> typesWithField = new HashMap<>(); public CustomEntryTypeDialogViewModel(BibDatabaseMode mode) { @@ -51,8 +66,6 @@ public CustomEntryTypeDialogViewModel(BibDatabaseMode mode) { fieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList(FieldFactory.getAllFields())); - existingFieldsForType = FXCollections.observableArrayList(); - for (BibEntryType entryType : alllTypes) { List fields = entryType.getAllFields().stream().map(bibField -> new FieldViewModel(bibField.getField(), entryType.isRequired(bibField.getField()), entryType)).collect(Collectors.toList()); typesWithField.put(entryType, fields); @@ -143,4 +156,11 @@ public StringProperty entryTypeToAddProperty() { public ObjectProperty newFieldToAddProperty() { return this.newFieldToAddProperty; } + + public void removeEntryType(BibEntryType focusedItem) { + } + + public void removeField(FieldViewModel focusedItem) { + // TODO Auto-generated method stub + } } diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml index 81a89ce4892..e9f4a680102 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml @@ -32,8 +32,11 @@ + maxWidth="40.0" minWidth="40.0" resizable="false" /> + + + @@ -66,8 +69,11 @@ + maxWidth="40.0" minWidth="40.0" resizable="false" /> + + + diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java index 83383a15ca7..0cf9a428ab3 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java @@ -11,18 +11,20 @@ import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextField; -import javafx.util.StringConverter; import org.jabref.gui.customentrytypes.CustomEntryTypeDialogViewModel.FieldType; +import org.jabref.gui.icon.IconTheme; import org.jabref.gui.util.BaseDialog; +import org.jabref.gui.util.ValueTableCellFactory; +import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.field.Field; -import org.jabref.model.entry.field.UnknownField; import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; +import org.fxmisc.easybind.EasyBind; public class CustomizeEntryTypeDialogView extends BaseDialog { @@ -63,33 +65,43 @@ private void setupTable() { entryTypes.itemsProperty().bind(viewModel.entryTypesProperty()); entryTypes.getSelectionModel().selectFirst(); + + entryTypeActionsColumn.setSortable(false); + entryTypeActionsColumn.setReorderable(false); + entryTypeActionsColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getType().getDisplayName())); + new ValueTableCellFactory() + .withGraphic(item -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode()) + .withTooltip(name -> Localization.lang("Remove entry type") + " " + name) + .withOnMouseClickedEvent(item -> evt -> viewModel.removeEntryType(entryTypes.getFocusModel().getFocusedItem())) + .install(entryTypeActionsColumn); + fieldTypeColumn.setCellFactory(cellData -> new RadioButtonCell<>(EnumSet.allOf(FieldType.class))); fieldTypeColumn.setCellValueFactory(item -> item.getValue().fieldTypeProperty()); - fieldNameColumn.setCellValueFactory(item -> item.getValue().fieldNameProperty()); viewModel.selectedEntryTypeProperty().bind(entryTypes.getSelectionModel().selectedItemProperty()); - viewModel.entryTypeToAddProperty().bind(addNewEntryType.textProperty()); addNewField.setItems(viewModel.fieldsProperty()); + addNewField.setConverter(viewModel.fieldStringConverter); - addNewField.setConverter(new StringConverter() { - - @Override - public String toString(Field object) { + fieldTypeActionColumn.setSortable(false); + fieldTypeActionColumn.setReorderable(false); + fieldTypeActionColumn.setCellValueFactory(cellData -> cellData.getValue().fieldNameProperty()); - return object != null ? object.getDisplayName() : ""; - } + new ValueTableCellFactory() + .withGraphic(item -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode()) + .withTooltip(name -> Localization.lang("Remove field from entry type") + " " + name) + .withOnMouseClickedEvent(item -> evt -> viewModel.removeField(requiredFields.getFocusModel().getFocusedItem())) + .install(fieldTypeActionColumn); - @Override - public Field fromString(String string) { - return new UnknownField(string); - } - }); viewModel.newFieldToAddProperty().bind(addNewField.valueProperty()); requiredFields.itemsProperty().bindBidirectional(viewModel.fieldsforTypesProperty()); + EasyBind.subscribe(requiredFields.getSelectionModel().selectedItemProperty(), field -> { + System.out.println("selected field " + field); + }); + } @FXML diff --git a/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java index ca4b6c1ef80..34f027456e7 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/FieldViewModel.java @@ -21,6 +21,7 @@ public FieldViewModel(Field field, FieldType fieldType, BibEntryType entryType) this.entryType = entryType; this.fieldNameProperty.setValue(field.getDisplayName()); this.fieldTypeProperty.setValue(fieldType); + } public FieldViewModel(Field field, boolean required, BibEntryType entryType) { @@ -43,4 +44,9 @@ public BibEntryType getEntryType() { return entryType; } + + @Override + public String toString() { + return this.field.getDisplayName(); + } } diff --git a/src/main/java/org/jabref/gui/customentrytypes/RadioButtonCell.java b/src/main/java/org/jabref/gui/customentrytypes/RadioButtonCell.java index cd1b15a51bd..1ccc9fdff8f 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/RadioButtonCell.java +++ b/src/main/java/org/jabref/gui/customentrytypes/RadioButtonCell.java @@ -10,6 +10,7 @@ import javafx.scene.control.Toggle; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; public class RadioButtonCell> extends TableCell { @@ -37,6 +38,7 @@ protected void updateItem(T item, boolean empty) { if (enumElement.equals(item)) { radioButton.setSelected(true); } + hb.setHgrow(radioButton, Priority.ALWAYS); } // issue events on change of the selected radio button From 25350c194f85b7b7abb10c30de8b2ebd4c171dd5 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Thu, 9 Jan 2020 21:22:45 +0100 Subject: [PATCH 11/19] fix issue with empty rows --- .../java/org/jabref/gui/customentrytypes/RadioButtonCell.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/customentrytypes/RadioButtonCell.java b/src/main/java/org/jabref/gui/customentrytypes/RadioButtonCell.java index 1ccc9fdff8f..ec3bfdc890e 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/RadioButtonCell.java +++ b/src/main/java/org/jabref/gui/customentrytypes/RadioButtonCell.java @@ -23,7 +23,9 @@ public RadioButtonCell(EnumSet enumeration) { @Override protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); - if (!empty) { + if (empty || (item == null)) { + setGraphic(null); + } else { // gui setup HBox hb = new HBox(7); hb.setAlignment(Pos.CENTER); From dff616388cf5638cbebc6ade758a5463eafe13ad Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 10 Jan 2020 23:04:03 +0100 Subject: [PATCH 12/19] refactorings add delete from lists --- .../CustomEntryTypeDialogViewModel.java | 50 +++++++++++-------- .../CustomizeEntryTypeDialog.fxml | 2 +- .../CustomizeEntryTypeDialogView.java | 12 +++-- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java index 607eba298c7..4a3390143d2 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java @@ -32,7 +32,7 @@ public class CustomEntryTypeDialogViewModel { - public static final StringConverter fieldStringConverter = new StringConverter() { + public static final StringConverter fieldStringConverter = new StringConverter<>() { @Override public String toString(Field object) { @@ -52,10 +52,10 @@ public Field fromString(String string) { private ObjectProperty selectedFieldToAddProperty = new SimpleObjectProperty<>(); private StringProperty entryTypeToAddProperty = new SimpleStringProperty(""); private ObservableList entryTypes; - private ObservableList existingFieldsForType = FXCollections.observableArrayList(extractor -> new Observable[] {extractor.fieldNameProperty(), extractor.fieldTypeProperty()}); + private ObservableList fieldsForType = FXCollections.observableArrayList(extractor -> new Observable[] {extractor.fieldNameProperty(), extractor.fieldTypeProperty()}); private ObjectProperty newFieldToAddProperty = new SimpleObjectProperty<>(); private BibDatabaseMode mode; - private Map> typesWithField = new HashMap<>(); + private Map> typesWithFields = new HashMap<>(); public CustomEntryTypeDialogViewModel(BibDatabaseMode mode) { this.mode = mode; @@ -68,15 +68,15 @@ public CustomEntryTypeDialogViewModel(BibDatabaseMode mode) { for (BibEntryType entryType : alllTypes) { List fields = entryType.getAllFields().stream().map(bibField -> new FieldViewModel(bibField.getField(), entryType.isRequired(bibField.getField()), entryType)).collect(Collectors.toList()); - typesWithField.put(entryType, fields); + typesWithFields.put(entryType, fields); } - this.fieldsForTypeProperty = new SimpleListProperty<>(existingFieldsForType); + this.fieldsForTypeProperty = new SimpleListProperty<>(fieldsForType); EasyBind.subscribe(selectedEntryTypesProperty, type -> { if (type != null) { - List typesForField = typesWithField.get(type); - existingFieldsForType.setAll(typesForField); + List typesForField = typesWithFields.get(type); + fieldsForType.setAll(typesForField); } }); @@ -115,13 +115,8 @@ public void addNewField() { Field field = newFieldToAddProperty.getValue(); FieldViewModel model = new FieldViewModel(field, true, selectedEntryTypesProperty.getValue()); - typesWithField.computeIfAbsent(selectedEntryTypesProperty.getValue(), key -> new ArrayList<>()).add(model); - existingFieldsForType.add(model); - //TODO: How should I add the field to the type? - - //BibEntryType type = new BibEntryType(type, fields, requiredFields) - // Globals.entryTypesManager.addCustomOrModifiedType(entryType, mode); - + typesWithFields.computeIfAbsent(selectedEntryTypesProperty.getValue(), key -> new ArrayList<>()).add(model); + fieldsForType.add(model); } public void addNewCustomEntryType() { @@ -129,11 +124,7 @@ public void addNewCustomEntryType() { BibEntryType type = new BibEntryType(newentryType, new ArrayList<>(), Collections.emptyList()); this.entryTypes.add(type); - this.typesWithField.put(type, new ArrayList<>()); - - // entryTypesManager.addCustomOrModifiedType(overwrittenStandardType ? - // BibEntryTypeBuilder - //new UnknownEntryType(null). + this.typesWithFields.put(type, new ArrayList<>()); } @@ -158,9 +149,28 @@ public ObjectProperty newFieldToAddProperty() { } public void removeEntryType(BibEntryType focusedItem) { + typesWithFields.remove(focusedItem); + entryTypes.remove(focusedItem); } public void removeField(FieldViewModel focusedItem) { - // TODO Auto-generated method stub + typesWithFields.computeIfAbsent(selectedEntryTypesProperty.getValue(), key -> new ArrayList<>()).remove(focusedItem); + fieldsForType.remove(focusedItem); + } + + public void apply() { + + for (var entry : typesWithFields.entrySet()) { + entry.getKey(); + //TODO: store them as BibEntry types again + //Find out if we simply can dump all the types with fields or do we need to check for custom ones before adding them? + + + // entryTypesManager.addCustomOrModifiedType(overwrittenStandardType ? + // BibEntryTypeBuilder + //new UnknownEntryType(null). + + + } } } diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml index e9f4a680102..6ed035d2754 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialog.fxml @@ -61,7 +61,7 @@ HBox.hgrow="ALWAYS">