From 376760c24f7e7e46a189e557618321f5e05e8f4c Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Thu, 24 Mar 2022 01:47:04 +0100 Subject: [PATCH 01/38] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f719dbf8742..a62785db499 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,6 @@ For IntelliJ IDEA, just import the project via a Gradle Import by pointing at th ## Sponsoring -JabRef development is powered by YourKit Java Profiler [![YourKit Java Profiler](https://www.yourkit.com/images/yk_logo.png)](https://www.yourkit.com/java/profiler/) +JabRef development is by YourKit Java Profiler [![YourKit Java Profiler](https://www.yourkit.com/images/yk_logo.png)](https://www.yourkit.com/java/profiler/) [JabRef]: https://www.jabref.org From 4e4372c09233d25a264fd787ad18b30a2ab1d715 Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Tue, 7 Jun 2022 13:41:25 +0100 Subject: [PATCH 02/38] Design layout in FXML --- .../gui/edit/AutomaticFieldEditorDialog.fxml | 92 +++++++++++++++++++ .../gui/edit/AutomaticFieldEditorDialog.java | 6 ++ 2 files changed, 98 insertions(+) create mode 100644 src/main/java/org/jabref/gui/edit/AutomaticFieldEditorDialog.fxml create mode 100644 src/main/java/org/jabref/gui/edit/AutomaticFieldEditorDialog.java diff --git a/src/main/java/org/jabref/gui/edit/AutomaticFieldEditorDialog.fxml b/src/main/java/org/jabref/gui/edit/AutomaticFieldEditorDialog.fxml new file mode 100644 index 00000000000..d0e66e2b4ed --- /dev/null +++ b/src/main/java/org/jabref/gui/edit/AutomaticFieldEditorDialog.fxml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/jabref/gui/edit/automaticfiededitor/renamefield/RenameFieldTabView.java b/src/main/java/org/jabref/gui/edit/automaticfiededitor/renamefield/RenameFieldTabView.java index ce84f1a278c..162a9d22111 100644 --- a/src/main/java/org/jabref/gui/edit/automaticfiededitor/renamefield/RenameFieldTabView.java +++ b/src/main/java/org/jabref/gui/edit/automaticfiededitor/renamefield/RenameFieldTabView.java @@ -1,20 +1,77 @@ package org.jabref.gui.edit.automaticfiededitor.renamefield; +import java.util.Comparator; +import java.util.List; + +import javafx.fxml.FXML; +import javafx.scene.control.ComboBox; +import javafx.scene.control.TextField; +import javafx.util.StringConverter; + import org.jabref.gui.edit.automaticfiededitor.AbstractAutomaticFieldEditorTabView; import org.jabref.gui.edit.automaticfiededitor.AutomaticFieldEditorTab; +import org.jabref.gui.undo.NamedCompound; import org.jabref.logic.l10n.Localization; +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldFactory; import com.airhacks.afterburner.views.ViewLoader; public class RenameFieldTabView extends AbstractAutomaticFieldEditorTabView implements AutomaticFieldEditorTab { - public RenameFieldTabView() { + @FXML + private ComboBox fieldComboBox; + + @FXML + private TextField newFieldNameTextField; + + private final List selectedEntries; + private final BibDatabaseContext databaseContext; + + private final NamedCompound dialogEdits; + private RenameFieldViewModel viewModel; + + public RenameFieldTabView(List selectedEntries, BibDatabaseContext databaseContext, NamedCompound dialogEdits) { + this.selectedEntries = selectedEntries; + this.databaseContext = databaseContext; + this.dialogEdits = dialogEdits; + ViewLoader.view(this) .root(this) .load(); } + @FXML + public void initialize() { + viewModel = new RenameFieldViewModel(selectedEntries, databaseContext, dialogEdits); + + fieldComboBox.getItems().addAll(viewModel.getAllFields().sorted(Comparator.comparing(Field::getName))); + fieldComboBox.setConverter(new StringConverter<>() { + @Override + public String toString(Field field) { + return field.getName(); + } + + @Override + public Field fromString(String name) { + return FieldFactory.parseField(name); + } + }); + + fieldComboBox.getSelectionModel().selectFirst(); + viewModel.selectedFieldProperty().bindBidirectional(fieldComboBox.valueProperty()); + + viewModel.newFieldNameProperty().bindBidirectional(newFieldNameTextField.textProperty()); + } + @Override public String getTabName() { return Localization.lang("Rename field"); } + + @FXML + void renameField() { + viewModel.renameField(); + } } diff --git a/src/main/java/org/jabref/gui/edit/automaticfiededitor/renamefield/RenameFieldViewModel.java b/src/main/java/org/jabref/gui/edit/automaticfiededitor/renamefield/RenameFieldViewModel.java index 090fe85a852..f8e430ccc51 100644 --- a/src/main/java/org/jabref/gui/edit/automaticfiededitor/renamefield/RenameFieldViewModel.java +++ b/src/main/java/org/jabref/gui/edit/automaticfiededitor/renamefield/RenameFieldViewModel.java @@ -1,6 +1,71 @@ package org.jabref.gui.edit.automaticfiededitor.renamefield; +import java.util.List; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + import org.jabref.gui.AbstractViewModel; +import org.jabref.gui.edit.automaticfiededitor.MoveFieldValueAction; +import org.jabref.gui.undo.NamedCompound; +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldFactory; public class RenameFieldViewModel extends AbstractViewModel { + + private final StringProperty newFieldName = new SimpleStringProperty(); + private final ObjectProperty selectedField = new SimpleObjectProperty<>(); + + private final ObservableList allFields = FXCollections.observableArrayList(); + private final List selectedEntries; + private final BibDatabaseContext databaseContext; + private final NamedCompound dialogEdits; + + public RenameFieldViewModel(List selectedEntries, BibDatabaseContext databaseContext, NamedCompound dialogEdits) { + this.selectedEntries = selectedEntries; + this.databaseContext = databaseContext; + this.dialogEdits = dialogEdits; + + allFields.addAll(databaseContext.getDatabase().getAllVisibleFields()); + } + + public String getNewFieldName() { + return newFieldName.get(); + } + + public StringProperty newFieldNameProperty() { + return newFieldName; + } + + public Field getSelectedField() { + return selectedField.get(); + } + + public ObjectProperty selectedFieldProperty() { + return selectedField; + } + + public ObservableList getAllFields() { + return allFields; + } + + public void renameField() { + NamedCompound renameEdit = new NamedCompound("RENAME_EDIT"); + + new MoveFieldValueAction(selectedField.get(), + FieldFactory.parseField(newFieldName.get()), + selectedEntries, + renameEdit).execute(); + + if (renameEdit.hasEdits()) { + renameEdit.end(); + dialogEdits.addEdit(renameEdit); + } + } } From 77e48f4ad02de0dee74591371418d5ea36577c6c Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Fri, 10 Jun 2022 23:56:30 +0100 Subject: [PATCH 18/38] Design UI and bind properties for the Two Fields automatic field editor --- .../AutomaticFieldEditorViewModel.java | 2 +- .../twofields/TwoFieldsTab.fxml | 63 ++++++++++-- .../twofields/TwoFieldsTabView.java | 99 ++++++++++++++++++- .../twofields/TwoFieldsViewModel.java | 69 +++++++++++++ 4 files changed, 223 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/gui/edit/automaticfiededitor/AutomaticFieldEditorViewModel.java b/src/main/java/org/jabref/gui/edit/automaticfiededitor/AutomaticFieldEditorViewModel.java index abce47784fc..0c334ddf6fa 100644 --- a/src/main/java/org/jabref/gui/edit/automaticfiededitor/AutomaticFieldEditorViewModel.java +++ b/src/main/java/org/jabref/gui/edit/automaticfiededitor/AutomaticFieldEditorViewModel.java @@ -26,7 +26,7 @@ public class AutomaticFieldEditorViewModel extends AbstractViewModel { public AutomaticFieldEditorViewModel(List selectedEntries, BibDatabaseContext databaseContext, UndoManager undoManager) { fieldEditorTabs.addAll( new EditFieldValueTabView(selectedEntries, databaseContext, dialogEdits), - new TwoFieldsTabView(), + new TwoFieldsTabView(selectedEntries, databaseContext, dialogEdits), new RenameFieldTabView(selectedEntries, databaseContext, dialogEdits) ); this.databaseContext = databaseContext; diff --git a/src/main/java/org/jabref/gui/edit/automaticfiededitor/twofields/TwoFieldsTab.fxml b/src/main/java/org/jabref/gui/edit/automaticfiededitor/twofields/TwoFieldsTab.fxml index f51771706c0..3fe17a32701 100644 --- a/src/main/java/org/jabref/gui/edit/automaticfiededitor/twofields/TwoFieldsTab.fxml +++ b/src/main/java/org/jabref/gui/edit/automaticfiededitor/twofields/TwoFieldsTab.fxml @@ -1,12 +1,59 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +