From cf7a48fc4124ece286e1085b13ac0793aae42279 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 17 Feb 2018 17:25:12 +0100 Subject: [PATCH 01/28] Convert String dialog to javafx TODO: store strings back to db --- src/main/java/org/jabref/gui/JabRefFrame.java | 3 +- .../org/jabref/gui/strings/StringAction.java | 12 +++ .../gui/strings/StringDialogController.java | 73 +++++++++++++++++++ .../jabref/gui/strings/StringDialogView.java | 18 +++++ .../gui/strings/StringDialogViewModel.java | 53 ++++++++++++++ .../jabref/gui/strings/StringViewModel.java | 33 +++++++++ .../org/jabref/gui/strings/StringDialog.fxml | 30 ++++++++ 7 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/jabref/gui/strings/StringAction.java create mode 100644 src/main/java/org/jabref/gui/strings/StringDialogController.java create mode 100644 src/main/java/org/jabref/gui/strings/StringDialogView.java create mode 100644 src/main/java/org/jabref/gui/strings/StringDialogViewModel.java create mode 100644 src/main/java/org/jabref/gui/strings/StringViewModel.java create mode 100644 src/main/resources/org/jabref/gui/strings/StringDialog.fxml diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 2534c3fb30c..aa9789f2fcc 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -117,6 +117,7 @@ import org.jabref.gui.push.PushToApplications; import org.jabref.gui.search.GlobalSearchBar; import org.jabref.gui.specialfields.SpecialFieldValueViewModel; +import org.jabref.gui.strings.StringAction; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.autosaveandbackup.AutosaveManager; @@ -965,7 +966,7 @@ private MenuBar createMenu() { factory.createMenuItem(ActionsFX.LIBRARY_PROPERTIES, new LibraryPropertiesAction(this)), factory.createMenuItem(ActionsFX.EDIT_PREAMBLE, new OldDatabaseCommandWrapper(Actions.EDIT_PREAMBLE, this, Globals.stateManager)), - factory.createMenuItem(ActionsFX.EDIT_STRINGS, new OldDatabaseCommandWrapper(Actions.EDIT_STRINGS, this, Globals.stateManager)) + factory.createMenuItem(ActionsFX.EDIT_STRINGS, new StringAction()) ); Menu lookupIdentifiers = factory.createSubMenu(ActionsFX.LOOKUP_DOC_IDENTIFIER); diff --git a/src/main/java/org/jabref/gui/strings/StringAction.java b/src/main/java/org/jabref/gui/strings/StringAction.java new file mode 100644 index 00000000000..c5511536505 --- /dev/null +++ b/src/main/java/org/jabref/gui/strings/StringAction.java @@ -0,0 +1,12 @@ +package org.jabref.gui.strings; + +import org.jabref.gui.actions.SimpleCommand; + +public class StringAction extends SimpleCommand { + + @Override + public void execute() { + new StringDialogView().show(); + } + +} diff --git a/src/main/java/org/jabref/gui/strings/StringDialogController.java b/src/main/java/org/jabref/gui/strings/StringDialogController.java new file mode 100644 index 00000000000..bffe0819205 --- /dev/null +++ b/src/main/java/org/jabref/gui/strings/StringDialogController.java @@ -0,0 +1,73 @@ +package org.jabref.gui.strings; + +import javax.inject.Inject; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableColumn.CellEditEvent; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.TextFieldTableCell; + +import org.jabref.gui.AbstractController; +import org.jabref.gui.StateManager; + +public class StringDialogController extends AbstractController { + + @FXML private Button btnNewString; + + @FXML private Button btnRemove; + + @FXML private Button btnHelp; + + @FXML private TableView tblStrings; + + @FXML private TableColumn colLabel; + + @FXML private TableColumn colContent; + + @Inject private StateManager stateManager; + + @FXML + private void initialize() { + + viewModel = new StringDialogViewModel(stateManager); + colLabel.setCellValueFactory(cellData -> cellData.getValue().getLabel()); + colContent.setCellValueFactory(cellData -> cellData.getValue().getContent()); + + colLabel.setCellFactory(TextFieldTableCell. forTableColumn()); + colContent.setCellFactory(TextFieldTableCell. forTableColumn()); + colLabel.setOnEditCommit( + (CellEditEvent t) -> { + t.getTableView().getItems().get( + t.getTablePosition().getRow()).setLabel(t.getNewValue()); + }); + colContent.setOnEditCommit( + (CellEditEvent t) -> { + t.getTableView().getItems().get( + t.getTablePosition().getRow()).setContent(t.getNewValue()); + }); + + tblStrings.itemsProperty().bindBidirectional(viewModel.allStringsProperty()); + tblStrings.setEditable(true); + } + + @FXML + void addString(ActionEvent event) { + + viewModel.addNewString(); + + } + + @FXML + void openHelp(ActionEvent event) { + + } + + @FXML + void removeString(ActionEvent event) { + StringViewModel selected = tblStrings.getSelectionModel().getSelectedItem(); + viewModel.removeString(selected); + } +} diff --git a/src/main/java/org/jabref/gui/strings/StringDialogView.java b/src/main/java/org/jabref/gui/strings/StringDialogView.java new file mode 100644 index 00000000000..9419e41d102 --- /dev/null +++ b/src/main/java/org/jabref/gui/strings/StringDialogView.java @@ -0,0 +1,18 @@ +package org.jabref.gui.strings; + +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.DialogPane; + +import org.jabref.gui.AbstractDialogView; +import org.jabref.gui.FXDialog; + +public class StringDialogView extends AbstractDialogView { + + @Override + public void show() { + FXDialog stringDialog = new FXDialog(AlertType.INFORMATION, "Edit Strings"); + stringDialog.setDialogPane((DialogPane) this.getView()); + stringDialog.setResizable(true); + stringDialog.show(); + } +} diff --git a/src/main/java/org/jabref/gui/strings/StringDialogViewModel.java b/src/main/java/org/jabref/gui/strings/StringDialogViewModel.java new file mode 100644 index 00000000000..527a377ef62 --- /dev/null +++ b/src/main/java/org/jabref/gui/strings/StringDialogViewModel.java @@ -0,0 +1,53 @@ +package org.jabref.gui.strings; + +import java.util.List; +import java.util.stream.Collectors; + +import javafx.beans.property.SimpleListProperty; +import javafx.collections.FXCollections; + +import org.jabref.gui.AbstractViewModel; +import org.jabref.gui.StateManager; +import org.jabref.logic.bibtex.comparator.BibtexStringComparator; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.entry.BibtexString; + +public class StringDialogViewModel extends AbstractViewModel { + + private final SimpleListProperty allStrings = new SimpleListProperty<>( + FXCollections.observableArrayList()); + + private final StateManager stateManager; + + public StringDialogViewModel(StateManager stateManager) { + this.stateManager = stateManager; + addAllStringsFromDB(); + } + + private void addAllStringsFromDB() { + BibDatabase db = stateManager.getActiveDatabase().get().getDatabase(); + List strings = db.getStringKeySet().stream() + .map(string -> db.getString(string)) + .sorted(new BibtexStringComparator(false)) + .map(this::convertFromBibTexString).collect(Collectors.toList()); + allStrings.addAll(strings); + } + + public SimpleListProperty allStringsProperty() { + return this.allStrings; + } + + public void addNewString() { + allStrings.add(new StringViewModel("new Label", "New Content")); + } + + public void removeString(StringViewModel selected) { + allStrings.remove(selected); + + } + + private StringViewModel convertFromBibTexString(BibtexString bibtexString) { + return new StringViewModel(bibtexString.getName(), bibtexString.getContent()); + + } +} diff --git a/src/main/java/org/jabref/gui/strings/StringViewModel.java b/src/main/java/org/jabref/gui/strings/StringViewModel.java new file mode 100644 index 00000000000..35be1dde8db --- /dev/null +++ b/src/main/java/org/jabref/gui/strings/StringViewModel.java @@ -0,0 +1,33 @@ +package org.jabref.gui.strings; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + + +public class StringViewModel { + + private final StringProperty label; + private final StringProperty content; + + public StringViewModel(String label, String content) { + + this.label = new SimpleStringProperty(label); + this.content = new SimpleStringProperty(content); + } + + public StringProperty getLabel() { + return label; + } + + public StringProperty getContent() { + return content; + } + + public void setLabel(String label) { + this.label.setValue(label); + } + + public void setContent(String content) { + this.content.setValue(content); + } +} diff --git a/src/main/resources/org/jabref/gui/strings/StringDialog.fxml b/src/main/resources/org/jabref/gui/strings/StringDialog.fxml new file mode 100644 index 00000000000..ddd1178c395 --- /dev/null +++ b/src/main/resources/org/jabref/gui/strings/StringDialog.fxml @@ -0,0 +1,30 @@ + + + + + + + + + + + +
+ + +
+ + + + + + + + +
From 5b15f2631b0edbb53dcbc053747068d2a2e48b99 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 17 Feb 2018 17:52:31 +0100 Subject: [PATCH 02/28] add save and cancel buttons --- .../gui/strings/StringDialogController.java | 42 +++++++++++++------ .../org/jabref/gui/strings/StringDialog.fxml | 36 +++++++++++----- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/jabref/gui/strings/StringDialogController.java b/src/main/java/org/jabref/gui/strings/StringDialogController.java index bffe0819205..9b6198013f1 100644 --- a/src/main/java/org/jabref/gui/strings/StringDialogController.java +++ b/src/main/java/org/jabref/gui/strings/StringDialogController.java @@ -8,30 +8,40 @@ import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn.CellEditEvent; import javafx.scene.control.TableView; +import javafx.scene.control.Tooltip; import javafx.scene.control.cell.TextFieldTableCell; import org.jabref.gui.AbstractController; +import org.jabref.gui.IconTheme.JabRefIcons; +import org.jabref.gui.help.HelpAction; +import org.jabref.logic.help.HelpFile; +import org.jabref.logic.l10n.Localization; import org.jabref.gui.StateManager; public class StringDialogController extends AbstractController { @FXML private Button btnNewString; - @FXML private Button btnRemove; - @FXML private Button btnHelp; - + @FXML private Button btnCancel; + @FXML private Button btnSave; @FXML private TableView tblStrings; - @FXML private TableColumn colLabel; - @FXML private TableColumn colContent; - @Inject private StateManager stateManager; @FXML private void initialize() { + btnHelp.setGraphic(JabRefIcons.HELP.getGraphicNode()); + btnHelp.setTooltip(new Tooltip(Localization.lang("Open Help page"))); + + btnNewString.setGraphic(JabRefIcons.ADD.getGraphicNode()); + btnNewString.setTooltip(new Tooltip(Localization.lang("New string"))); + + btnRemove.setGraphic(JabRefIcons.REMOVE.getGraphicNode()); + btnRemove.setTooltip(new Tooltip(Localization.lang("Remove string"))); + viewModel = new StringDialogViewModel(stateManager); colLabel.setCellValueFactory(cellData -> cellData.getValue().getLabel()); colContent.setCellValueFactory(cellData -> cellData.getValue().getContent()); @@ -54,20 +64,28 @@ private void initialize() { } @FXML - void addString(ActionEvent event) { - + private void addString(ActionEvent event) { viewModel.addNewString(); - } @FXML - void openHelp(ActionEvent event) { - + private void openHelp(ActionEvent event) { + HelpAction.openHelpPage(HelpFile.STRING_EDITOR); } @FXML - void removeString(ActionEvent event) { + private void removeString(ActionEvent event) { StringViewModel selected = tblStrings.getSelectionModel().getSelectedItem(); viewModel.removeString(selected); } + + @FXML + private void save() { + + } + + @FXML + private void close() { + getStage().close(); + } } diff --git a/src/main/resources/org/jabref/gui/strings/StringDialog.fxml b/src/main/resources/org/jabref/gui/strings/StringDialog.fxml index ddd1178c395..73b0841de97 100644 --- a/src/main/resources/org/jabref/gui/strings/StringDialog.fxml +++ b/src/main/resources/org/jabref/gui/strings/StringDialog.fxml @@ -1,30 +1,46 @@ + - +
-
- - - - - - + +
+ + + + + + + + + +
+ + + +