Skip to content

Commit

Permalink
Converts integrity check dialog to JavaFX
Browse files Browse the repository at this point in the history
Moreover:
- Show entry by reference and not by id. Fixes #2181.
- Fixes a few issues that occurred when opening the entry editor by code from the integrity dialog
- Reuse gridpane in entry editor (should have a slightly superior performance)
- Improve display of progress dialog
- Invoke copy files task using central task executor
  • Loading branch information
tobiasdiez committed Dec 28, 2018
1 parent 75b147e commit 7269d27
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 244 deletions.
10 changes: 6 additions & 4 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;

import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.geometry.Orientation;
import javafx.scene.Node;
Expand Down Expand Up @@ -693,11 +694,12 @@ public void insertEntry(final BibEntry bibEntry) {
}
}

public void editEntryByIdAndFocusField(final String entryId, final String fieldName) {
bibDatabaseContext.getDatabase().getEntryById(entryId).ifPresent(entry -> {
clearAndSelect(entry);
showAndEdit(entry);
public void editEntryAndFocusField(BibEntry entry, String fieldName) {
showAndEdit(entry);
Platform.runLater(() -> {
// Focus field and entry in main table (async to give entry editor time to load)
entryEditor.setFocusToField(fieldName);
clearAndSelect(entry);
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ Optional<ButtonType> showCustomButtonDialogAndWait(Alert.AlertType type, String
/**
* Constructs and shows a canceable {@link ProgressDialog}. Clicking cancel will cancel the underlying service and close the dialog
*
* @param title title of the dialog
* @param content message to show above the progress bar
* @param task The {@link Task} which executes the work and for which to show the dialog
*/
<V> void showCanceableProgressDialogAndWait(Task<V> task);
<V> void showProgressDialogAndWait(String title, String content, Task<V> task);

/**
* Notify the user in an non-blocking way (i.e., in form of toast in a snackbar).
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/jabref/gui/FXDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import javafx.scene.layout.Region;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.stage.Window;

import org.jabref.JabRefGUI;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -226,8 +228,13 @@ public <R> Optional<R> showCustomDialogAndWait(Dialog<R> dialog) {
}

@Override
public <V> void showCanceableProgressDialogAndWait(Task<V> task) {
public <V> void showProgressDialogAndWait(String title, String content, Task<V> task) {
ProgressDialog progressDialog = new ProgressDialog(task);
progressDialog.setHeaderText(null);
progressDialog.setTitle(title);
progressDialog.setContentText(content);
progressDialog.setGraphic(null);
((Stage) progressDialog.getDialogPane().getScene().getWindow()).getIcons().add(IconTheme.getJabRefImageFX());
progressDialog.setOnCloseRequest(evt -> task.cancel());
DialogPane dialogPane = progressDialog.getDialogPane();
dialogPane.getButtonTypes().add(ButtonType.CANCEL);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.jabref.gui.actions.DatabasePropertiesAction;
import org.jabref.gui.actions.EditExternalFileTypesAction;
import org.jabref.gui.actions.ErrorConsoleAction;
import org.jabref.gui.actions.IntegrityCheckAction;
import org.jabref.gui.actions.LookupIdentifierAction;
import org.jabref.gui.actions.ManageCustomExportsAction;
import org.jabref.gui.actions.ManageCustomImportsAction;
Expand Down Expand Up @@ -94,6 +93,7 @@
import org.jabref.gui.importer.ImportCommand;
import org.jabref.gui.importer.ImportInspectionDialog;
import org.jabref.gui.importer.actions.OpenDatabaseAction;
import org.jabref.gui.integrity.IntegrityCheckAction;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.menus.FileHistoryMenu;
import org.jabref.gui.mergeentries.MergeEntriesAction;
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/org/jabref/gui/actions/CopyFilesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ public CopyFilesAction(JabRefFrame frame) {
this.dialogService = frame.getDialogService();
}

private void startServiceAndshowProgessDialog(Task<List<CopyFilesResultItemViewModel>> exportService) {

dialogService.showCanceableProgressDialogAndWait(exportService);

exportService.run();
exportService.setOnSucceeded((e) -> {
showDialog(exportService.getValue());
});
}

private void showDialog(List<CopyFilesResultItemViewModel> data) {
if (data.isEmpty()) {
dialogService.showInformationDialogAndWait(Localization.lang("Copy linked files to folder..."), Localization.lang("No linked files found for export."));
Expand All @@ -64,7 +54,12 @@ public void execute() {
databaseContext = frame.getCurrentBasePanel().getBibDatabaseContext();

Task<List<CopyFilesResultItemViewModel>> exportTask = new CopyFilesTask(databaseContext, entries, path);
startServiceAndshowProgessDialog(exportTask);
dialogService.showProgressDialogAndWait(
Localization.lang("Copy linked files to folder..."),
Localization.lang("Copy linked files to folder..."),
exportTask);
Globals.TASK_EXECUTOR.execute(exportTask);
exportTask.setOnSucceeded((e) -> showDialog(exportTask.getValue()));
});

}
Expand Down
202 changes: 0 additions & 202 deletions src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java

This file was deleted.

Loading

0 comments on commit 7269d27

Please sign in to comment.