Skip to content

Commit e1cfec9

Browse files
authored
Converts integrity check dialog to JavaFX (#4559)
* 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
1 parent 3143190 commit e1cfec9

17 files changed

+290
-253
lines changed

src/main/java/org/jabref/gui/BasePanel.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javax.swing.undo.CannotRedoException;
2020
import javax.swing.undo.CannotUndoException;
2121

22+
import javafx.application.Platform;
2223
import javafx.beans.binding.Bindings;
2324
import javafx.geometry.Orientation;
2425
import javafx.scene.Node;
@@ -693,11 +694,12 @@ public void insertEntry(final BibEntry bibEntry) {
693694
}
694695
}
695696

696-
public void editEntryByIdAndFocusField(final String entryId, final String fieldName) {
697-
bibDatabaseContext.getDatabase().getEntryById(entryId).ifPresent(entry -> {
698-
clearAndSelect(entry);
699-
showAndEdit(entry);
697+
public void editEntryAndFocusField(BibEntry entry, String fieldName) {
698+
showAndEdit(entry);
699+
Platform.runLater(() -> {
700+
// Focus field and entry in main table (async to give entry editor time to load)
700701
entryEditor.setFocusToField(fieldName);
702+
clearAndSelect(entry);
701703
});
702704
}
703705

src/main/java/org/jabref/gui/DialogService.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,11 @@ Optional<ButtonType> showCustomButtonDialogAndWait(Alert.AlertType type, String
183183
/**
184184
* Constructs and shows a canceable {@link ProgressDialog}. Clicking cancel will cancel the underlying service and close the dialog
185185
*
186+
* @param title title of the dialog
187+
* @param content message to show above the progress bar
186188
* @param task The {@link Task} which executes the work and for which to show the dialog
187189
*/
188-
<V> void showCanceableProgressDialogAndWait(Task<V> task);
190+
<V> void showProgressDialogAndWait(String title, String content, Task<V> task);
189191

190192
/**
191193
* Notify the user in an non-blocking way (i.e., in form of toast in a snackbar).

src/main/java/org/jabref/gui/FXDialogService.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import javafx.scene.layout.Region;
2525
import javafx.stage.DirectoryChooser;
2626
import javafx.stage.FileChooser;
27+
import javafx.stage.Stage;
2728
import javafx.stage.Window;
2829

2930
import org.jabref.JabRefGUI;
31+
import org.jabref.gui.icon.IconTheme;
3032
import org.jabref.gui.util.DirectoryDialogConfiguration;
3133
import org.jabref.gui.util.FileDialogConfiguration;
3234
import org.jabref.logic.l10n.Localization;
@@ -226,8 +228,13 @@ public <R> Optional<R> showCustomDialogAndWait(Dialog<R> dialog) {
226228
}
227229

228230
@Override
229-
public <V> void showCanceableProgressDialogAndWait(Task<V> task) {
231+
public <V> void showProgressDialogAndWait(String title, String content, Task<V> task) {
230232
ProgressDialog progressDialog = new ProgressDialog(task);
233+
progressDialog.setHeaderText(null);
234+
progressDialog.setTitle(title);
235+
progressDialog.setContentText(content);
236+
progressDialog.setGraphic(null);
237+
((Stage) progressDialog.getDialogPane().getScene().getWindow()).getIcons().add(IconTheme.getJabRefImageFX());
231238
progressDialog.setOnCloseRequest(evt -> task.cancel());
232239
DialogPane dialogPane = progressDialog.getDialogPane();
233240
dialogPane.getButtonTypes().add(ButtonType.CANCEL);

src/main/java/org/jabref/gui/JabRefFrame.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import org.jabref.gui.actions.DatabasePropertiesAction;
6363
import org.jabref.gui.actions.EditExternalFileTypesAction;
6464
import org.jabref.gui.actions.ErrorConsoleAction;
65-
import org.jabref.gui.actions.IntegrityCheckAction;
6665
import org.jabref.gui.actions.LookupIdentifierAction;
6766
import org.jabref.gui.actions.ManageCustomExportsAction;
6867
import org.jabref.gui.actions.ManageCustomImportsAction;
@@ -94,6 +93,7 @@
9493
import org.jabref.gui.importer.ImportCommand;
9594
import org.jabref.gui.importer.ImportInspectionDialog;
9695
import org.jabref.gui.importer.actions.OpenDatabaseAction;
96+
import org.jabref.gui.integrity.IntegrityCheckAction;
9797
import org.jabref.gui.keyboard.KeyBinding;
9898
import org.jabref.gui.menus.FileHistoryMenu;
9999
import org.jabref.gui.mergeentries.MergeEntriesAction;

src/main/java/org/jabref/gui/actions/CopyFilesAction.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@ public CopyFilesAction(JabRefFrame frame) {
3232
this.dialogService = frame.getDialogService();
3333
}
3434

35-
private void startServiceAndshowProgessDialog(Task<List<CopyFilesResultItemViewModel>> exportService) {
36-
37-
dialogService.showCanceableProgressDialogAndWait(exportService);
38-
39-
exportService.run();
40-
exportService.setOnSucceeded((e) -> {
41-
showDialog(exportService.getValue());
42-
});
43-
}
44-
4535
private void showDialog(List<CopyFilesResultItemViewModel> data) {
4636
if (data.isEmpty()) {
4737
dialogService.showInformationDialogAndWait(Localization.lang("Copy linked files to folder..."), Localization.lang("No linked files found for export."));
@@ -64,7 +54,12 @@ public void execute() {
6454
databaseContext = frame.getCurrentBasePanel().getBibDatabaseContext();
6555

6656
Task<List<CopyFilesResultItemViewModel>> exportTask = new CopyFilesTask(databaseContext, entries, path);
67-
startServiceAndshowProgessDialog(exportTask);
57+
dialogService.showProgressDialogAndWait(
58+
Localization.lang("Copy linked files to folder..."),
59+
Localization.lang("Copy linked files to folder..."),
60+
exportTask);
61+
Globals.TASK_EXECUTOR.execute(exportTask);
62+
exportTask.setOnSucceeded((e) -> showDialog(exportTask.getValue()));
6863
});
6964

7065
}

src/main/java/org/jabref/gui/actions/IntegrityCheckAction.java

-202
This file was deleted.

src/main/java/org/jabref/gui/copyfiles/CopyFilesTask.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,18 @@ protected List<CopyFilesResultItemViewModel> call() throws InterruptedException,
6767

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

70+
if (isCancelled()) {
71+
break;
72+
}
73+
7074
List<LinkedFile> files = entries.get(i).getFiles();
7175

7276
for (int j = 0; j < files.size(); j++) {
77+
78+
if (isCancelled()) {
79+
break;
80+
}
81+
7382
updateMessage(Localization.lang("Copying file %0 of entry %1", Integer.toString(j + 1), Integer.toString(i + 1)));
7483

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

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

81-
newPath.ifPresent(newFile -> {
90+
if (newPath.isPresent()) {
91+
92+
Path newFile = newPath.get();
8293
boolean success = FileUtil.copyFile(fileToExport.get(), newFile, false);
8394
updateProgress(totalFilesCounter++, totalFilesCount);
8495
try {
8596
Thread.sleep(300);
8697
} catch (InterruptedException e) {
87-
// TODO Auto-generated catch block
88-
e.printStackTrace();
98+
if (isCancelled()) {
99+
updateMessage("Cancelled");
100+
break;
101+
}
89102
}
90103
if (success) {
91104
updateMessage(localizedSucessMessage);
@@ -99,7 +112,9 @@ protected List<CopyFilesResultItemViewModel> call() throws InterruptedException,
99112
writeLogMessage(newFile, bw, localizedErrorMessage);
100113
addResultToList(newFile, success, localizedErrorMessage);
101114
}
102-
});
115+
116+
}
117+
103118
}
104119
}
105120
updateMessage(Localization.lang("Finished copying"));

0 commit comments

Comments
 (0)