Skip to content

Commit

Permalink
Converts integrity check dialog to JavaFX (#4559)
Browse files Browse the repository at this point in the history
* Converts integrity check dialog to JavaFX

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

* fix l10n
fix aborting of copy files task and showing of integrity check dialog

* fix l10n
  • Loading branch information
tobiasdiez authored Jan 5, 2019
1 parent 3143190 commit e1cfec9
Show file tree
Hide file tree
Showing 17 changed files with 290 additions and 253 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.

23 changes: 19 additions & 4 deletions src/main/java/org/jabref/gui/copyfiles/CopyFilesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,18 @@ protected List<CopyFilesResultItemViewModel> call() throws InterruptedException,

for (int i = 0; i < entries.size(); i++) {

if (isCancelled()) {
break;
}

List<LinkedFile> files = entries.get(i).getFiles();

for (int j = 0; j < files.size(); j++) {

if (isCancelled()) {
break;
}

updateMessage(Localization.lang("Copying file %0 of entry %1", Integer.toString(j + 1), Integer.toString(i + 1)));

LinkedFile fileName = files.get(j);
Expand All @@ -78,14 +87,18 @@ protected List<CopyFilesResultItemViewModel> call() throws InterruptedException,

newPath = OptionalUtil.combine(Optional.of(exportPath), fileToExport, resolvePathFilename);

newPath.ifPresent(newFile -> {
if (newPath.isPresent()) {

Path newFile = newPath.get();
boolean success = FileUtil.copyFile(fileToExport.get(), newFile, false);
updateProgress(totalFilesCounter++, totalFilesCount);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if (isCancelled()) {
updateMessage("Cancelled");
break;
}
}
if (success) {
updateMessage(localizedSucessMessage);
Expand All @@ -99,7 +112,9 @@ protected List<CopyFilesResultItemViewModel> call() throws InterruptedException,
writeLogMessage(newFile, bw, localizedErrorMessage);
addResultToList(newFile, success, localizedErrorMessage);
}
});

}

}
}
updateMessage(Localization.lang("Finished copying"));
Expand Down
Loading

0 comments on commit e1cfec9

Please sign in to comment.