From 8a53ddd2c84e0ca45da92d10fd795224cfa2ad8a Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 13 Aug 2018 11:34:25 +0200 Subject: [PATCH 1/2] Fix "Manage journal abbreviations" dialog --- .../journals/ManageJournalAbbreviations.css | 10 --- .../journals/ManageJournalAbbreviations.fxml | 74 +++++++++---------- .../ManageJournalAbbreviationsView.java | 21 ++---- .../ManageJournalAbbreviationsViewModel.java | 3 +- 4 files changed, 43 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviations.css b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviations.css index 8e2948e5f46..86fe501eb2e 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviations.css +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviations.css @@ -1,8 +1,3 @@ -.custom-buttons { - -fx-margin-top: 10px; - -fx-padding: 5px; -} - .abbreviations-table { -fx-table-cell-border-color: transparent; } @@ -20,8 +15,3 @@ .table-row-cell:selected > .table-cell > .icon, .table-row-cell:pressed > .table-cell > .icon { -fx-fill: white; } - -.dialog-pane *.button-bar { - -fx-max-height: 0; - -fx-pref-height: 0; -} \ No newline at end of file diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviations.fxml b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviations.fxml index 93115e01b8e..9044de941dc 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviations.fxml +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviations.fxml @@ -1,7 +1,7 @@ - + @@ -9,57 +9,51 @@ - - -
- + - - - - + + + + - - - - -
- - - -
diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java index c6ded9668f3..0f640aa17ce 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java @@ -5,6 +5,7 @@ import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.ProgressIndicator; @@ -13,11 +14,11 @@ import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.scene.input.KeyCode; -import javafx.stage.Stage; import org.jabref.gui.DialogService; import org.jabref.gui.icon.IconTheme; import org.jabref.gui.util.BaseDialog; +import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.TaskExecutor; import org.jabref.gui.util.ValueTableCellFactory; import org.jabref.logic.journals.JournalAbbreviationLoader; @@ -34,12 +35,12 @@ public class ManageJournalAbbreviationsView extends BaseDialog { @FXML public Label loadingLabel; @FXML public ProgressIndicator progressIndicator; + @FXML private ButtonType saveButton; @FXML private TableView journalAbbreviationsTable; @FXML private TableColumn journalTableNameColumn; @FXML private TableColumn journalTableAbbreviationColumn; @FXML private TableColumn journalTableEditColumn; @FXML private TableColumn journalTableDeleteColumn; - @FXML private Button cancelButton; @FXML private ComboBox journalFilesBox; @FXML private Button addJournalFileButton; @FXML private Button addNewJournalFileButton; @@ -57,6 +58,8 @@ public ManageJournalAbbreviationsView() { ViewLoader.view(this) .load() .setAsDialogPane(this); + + ControlHelper.setAction(saveButton, getDialogPane(), event -> saveAbbreviationsAndCloseDialog()); } @FXML @@ -129,11 +132,7 @@ private void setUpTable() { private void setBindings() { journalAbbreviationsTable.itemsProperty().bindBidirectional(viewModel.abbreviationsProperty()); journalFilesBox.itemsProperty().bindBidirectional(viewModel.journalFilesProperty()); - - viewModel.currentFileProperty().addListener((observable, oldvalue, newvalue) -> - journalFilesBox.getSelectionModel().select(newvalue)); - journalFilesBox.getSelectionModel().selectedItemProperty() - .addListener((observable, oldvalue, newvalue) -> viewModel.currentFileProperty().set(newvalue)); + journalFilesBox.valueProperty().bindBidirectional(viewModel.currentFileProperty()); viewModel.currentAbbreviationProperty().addListener((observable, oldvalue, newvalue) -> journalAbbreviationsTable.getSelectionModel().select(newvalue)); @@ -185,12 +184,6 @@ private void removeAbbreviation() { viewModel.deleteAbbreviation(); } - @FXML - private void closeDialog() { - Stage stage = (Stage) cancelButton.getScene().getWindow(); - stage.close(); - } - @FXML private void saveAbbreviationsAndCloseDialog() { Task task = new Task() { @@ -202,7 +195,7 @@ protected Void call() { } }; new Thread(task).start(); - closeDialog(); + close(); } diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java index 46ceada6cfe..9006e695d68 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java @@ -99,7 +99,7 @@ public ManageJournalAbbreviationsViewModel(PreferencesService preferences, Dialo } } }); - isLoading.bind(isLoadingBuiltIn.and(isLoadingBuiltIn)); + isLoading.bind(isLoadingBuiltIn.or(isLoadingIeee)); } public SimpleBooleanProperty isLoadingProperty() { @@ -121,6 +121,7 @@ void addBuiltInLists() { .onSuccess(result -> { isLoadingBuiltIn.setValue(false); addList(Localization.lang("JabRef built in list"), result); + selectLastJournalFile(); }) .onFailure(dialogService::showErrorDialogAndWait) .executeWith(taskExecutor); From c98fc939e462cdbe02f459b1de9e0b915c328282 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 13 Aug 2018 14:13:35 +0200 Subject: [PATCH 2/2] Use task executor for async task --- .../ManageJournalAbbreviationsView.java | 11 +---------- .../ManageJournalAbbreviationsViewModel.java | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java index 0f640aa17ce..42611dccbed 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java @@ -2,7 +2,6 @@ import javax.inject.Inject; -import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.ButtonType; @@ -186,15 +185,7 @@ private void removeAbbreviation() { @FXML private void saveAbbreviationsAndCloseDialog() { - Task task = new Task() { - - @Override - protected Void call() { - viewModel.saveEverythingAndUpdateAutoCompleter(); - return null; - } - }; - new Thread(task).start(); + viewModel.saveEverythingAndUpdateAutoCompleter(); close(); } diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java index 9006e695d68..bce2327a58f 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsViewModel.java @@ -351,17 +351,19 @@ public void selectLastJournalFile() { * {@link JournalAbbreviationLoader#update(JournalAbbreviationPreferences)}. */ public void saveEverythingAndUpdateAutoCompleter() { - saveExternalFilesList(); + BackgroundTask.wrap(() -> { + saveExternalFilesList(); - if (shouldWriteLists) { - saveJournalAbbreviationFiles(); - shouldWriteLists = false; - } + if (shouldWriteLists) { + saveJournalAbbreviationFiles(); + shouldWriteLists = false; + } - // Update journal abbreviation loader - journalAbbreviationLoader.update(abbreviationsPreferences); + // Update journal abbreviation loader + journalAbbreviationLoader.update(abbreviationsPreferences); - preferences.storeJournalAbbreviationPreferences(abbreviationsPreferences); + preferences.storeJournalAbbreviationPreferences(abbreviationsPreferences); + }).executeWith(taskExecutor); } public SimpleListProperty journalFilesProperty() {