Skip to content

Commit 48c5a20

Browse files
authored
Convert "Customize importer" dialog to JavaFX (#4608)
* Convert "Customize importer" dialog to JavaFX * Use nio methods to access contents of zip files
1 parent b66fa42 commit 48c5a20

12 files changed

+361
-594
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jabref.gui;
22

3+
import java.io.IOException;
34
import java.nio.file.Path;
45
import java.util.Collection;
56
import java.util.List;
@@ -247,4 +248,12 @@ Optional<ButtonType> showCustomButtonDialogAndWait(Alert.AlertType type, String
247248
*/
248249
boolean showPrintDialog(PrinterJob job);
249250

251+
/**
252+
* Shows a new dialog that list all files contained in the given archive and which lets the user select one of these
253+
* files. The method doesn't return until the displayed open dialog is dismissed. The return value specifies the
254+
* file chosen by the user or an empty {@link Optional} if no selection has been made.
255+
*
256+
* @return the selected file or an empty {@link Optional} if no file has been selected
257+
*/
258+
Optional<Path> showFileOpenFromArchiveDialog(Path archivePath) throws IOException;
250259
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.jabref.gui;
22

33
import java.io.File;
4+
import java.io.IOException;
5+
import java.nio.file.FileSystem;
6+
import java.nio.file.FileSystems;
47
import java.nio.file.Path;
58
import java.util.Collection;
69
import java.util.Collections;
@@ -31,6 +34,7 @@
3134
import org.jabref.gui.icon.IconTheme;
3235
import org.jabref.gui.util.DirectoryDialogConfiguration;
3336
import org.jabref.gui.util.FileDialogConfiguration;
37+
import org.jabref.gui.util.ZipFileChooser;
3438
import org.jabref.logic.l10n.Localization;
3539

3640
import org.controlsfx.dialog.ExceptionDialog;
@@ -300,4 +304,13 @@ private FileChooser getConfiguredFileChooser(FileDialogConfiguration fileDialogC
300304
public boolean showPrintDialog(PrinterJob job) {
301305
return job.showPrintDialog(mainWindow);
302306
}
307+
308+
@Override
309+
public Optional<Path> showFileOpenFromArchiveDialog(Path archivePath) throws IOException {
310+
try (FileSystem zipFile = FileSystems.newFileSystem(archivePath, null)) {
311+
return new ZipFileChooser(zipFile).showAndWait();
312+
} catch (NoClassDefFoundError exc) {
313+
throw new IOException("Could not instantiate ZIP-archive reader.", exc);
314+
}
315+
}
303316
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ private MenuBar createMenu() {
928928
new SeparatorMenuItem(),
929929

930930
factory.createMenuItem(StandardActions.SETUP_GENERAL_FIELDS, new SetupGeneralFieldsAction()),
931-
factory.createMenuItem(StandardActions.MANAGE_CUSTOM_IMPORTS, new ManageCustomImportsAction(this)),
931+
factory.createMenuItem(StandardActions.MANAGE_CUSTOM_IMPORTS, new ManageCustomImportsAction()),
932932
factory.createMenuItem(StandardActions.MANAGE_CUSTOM_EXPORTS, new ManageCustomExportsAction()),
933933
factory.createMenuItem(StandardActions.MANAGE_EXTERNAL_FILETYPES, new EditExternalFileTypesAction()),
934934
factory.createMenuItem(StandardActions.MANAGE_JOURNALS, new ManageJournalsAction()),
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
package org.jabref.gui.actions;
22

3-
import org.jabref.gui.JabRefFrame;
43
import org.jabref.gui.importer.ImportCustomizationDialog;
54

65
public class ManageCustomImportsAction extends SimpleCommand {
76

8-
private final JabRefFrame jabRefFrame;
9-
10-
public ManageCustomImportsAction(JabRefFrame jabRefFrame) {
11-
this.jabRefFrame = jabRefFrame;
7+
public ManageCustomImportsAction() {
128
}
139

1410
@Override
1511
public void execute() {
16-
ImportCustomizationDialog ecd = new ImportCustomizationDialog(jabRefFrame);
17-
ecd.setVisible(true);
18-
12+
new ImportCustomizationDialog().showAndWait();
1913
}
2014

2115
}

src/main/java/org/jabref/gui/exporter/ExportCustomizationDialogView.java

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,13 @@ public ExportCustomizationDialogView() {
4141
.load()
4242
.setAsDialogPane(this);
4343

44-
ControlHelper.setAction(addButton, getDialogPane(), event -> addExporter());
45-
ControlHelper.setAction(modifyButton, getDialogPane(), event -> modifyExporter());
46-
ControlHelper.setAction(removeButton, getDialogPane(), event -> removeExporter());
47-
ControlHelper.setAction(closeButton, getDialogPane(), event -> saveAndClose());
48-
}
49-
50-
private void addExporter() {
51-
viewModel.addExporter();
52-
}
53-
54-
private void modifyExporter() {
55-
viewModel.modifyExporter();
56-
}
57-
58-
private void removeExporter() {
59-
viewModel.removeExporters();
44+
ControlHelper.setAction(addButton, getDialogPane(), event -> viewModel.addExporter());
45+
ControlHelper.setAction(modifyButton, getDialogPane(), event -> viewModel.modifyExporter());
46+
ControlHelper.setAction(removeButton, getDialogPane(), event -> viewModel.removeExporters());
47+
ControlHelper.setAction(closeButton, getDialogPane(), event -> {
48+
viewModel.saveToPrefs();
49+
close();
50+
});
6051
}
6152

6253
@FXML
@@ -69,9 +60,4 @@ private void initialize() {
6960
layoutColumn.setCellValueFactory(cellData -> cellData.getValue().layoutFileName());
7061
extensionColumn.setCellValueFactory(cellData -> cellData.getValue().extension());
7162
}
72-
73-
private void saveAndClose() {
74-
viewModel.saveToPrefs();
75-
close();
76-
}
77-
}
63+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.scene.control.ButtonType?>
4+
<?import javafx.scene.control.DialogPane?>
5+
<?import javafx.scene.control.TableColumn?>
6+
<?import javafx.scene.control.TableView?>
7+
<DialogPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171"
8+
fx:controller="org.jabref.gui.importer.ImportCustomizationDialog">
9+
<content>
10+
<TableView fx:id="importerTable">
11+
<columns>
12+
<TableColumn fx:id="nameColumn" prefWidth="150.0" text="%Import name"/>
13+
<TableColumn fx:id="classColumn" prefWidth="100.0" text="%Importer class"/>
14+
<TableColumn fx:id="basePathColumn" prefWidth="100.0" text="%Contained in"/>
15+
</columns>
16+
</TableView>
17+
</content>
18+
<ButtonType fx:id="addButton" text="%Add"/>
19+
<ButtonType fx:id="removeButton" text="%Remove"/>
20+
<ButtonType fx:id="closeButton" fx:constant="OK"/>
21+
<ButtonType fx:constant="CANCEL"/>
22+
</DialogPane>

0 commit comments

Comments
 (0)