Skip to content

Commit

Permalink
Make it easier to create FXML dialogs (#3880)
Browse files Browse the repository at this point in the history
* Extract swing dialog display to dialog service

* Embed preference dialog in JavaFX window

* Use new version of afterburner

* Fix injection into controller classes

* Fix build and code cleanup
  • Loading branch information
tobiasdiez authored Mar 23, 2018
1 parent 06d6736 commit 3c4a3ef
Show file tree
Hide file tree
Showing 52 changed files with 1,677 additions and 1,855 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ configurations {
}

dependencies {
// Include all jar-files in the 'lib' folder as dependencies
compile fileTree(dir: 'lib', includes: ['*.jar'])

compile 'com.jgoodies:jgoodies-common:1.8.1'
Expand Down Expand Up @@ -123,7 +124,6 @@ dependencies {
compile 'com.google.guava:guava:24.1-jre'

// JavaFX stuff
compile 'com.airhacks:afterburner.fx:1.7.0'
compile 'de.codecentric.centerdevice:javafxsvg:1.3.0'
compile 'de.jensd:fontawesomefx-materialdesignfont:1.7.22-4'
compile 'de.saxsys:mvvmfx-validation:1.7.0'
Expand All @@ -132,6 +132,7 @@ dependencies {
compile 'org.fxmisc.flowless:flowless:0.6'
compile 'org.fxmisc.richtext:richtextfx:0.8.2'
compile 'com.sibvisions.external.jvxfx:dndtabpane:0.1'
compile 'javax.inject:javax.inject:1'


// Cannot be updated to 9.*.* until Jabref works with Java 9
Expand Down
5 changes: 5 additions & 0 deletions javafx/scene/control/annotations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<root>
<item name='javafx.scene.control.Dialog dialogPane'>
<annotation name='javafx.fxml.FXML'/>
</item>
</root>
Binary file added lib/afterburner.fx.jar
Binary file not shown.
35 changes: 0 additions & 35 deletions src/main/java/org/jabref/gui/AbstractController.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/org/jabref/gui/AbstractDialogView.java

This file was deleted.

50 changes: 0 additions & 50 deletions src/main/java/org/jabref/gui/AbstractView.java

This file was deleted.

10 changes: 10 additions & 0 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,14 @@ public <T> T instantiatePresenter(Class<T> clazz, Function<String, Object> injec

return Injector.instantiatePresenter(clazz, injectionContext);
}

@Override
public void injectMembers(Object instance, Function<String, Object> injectionContext) {
LOGGER.debug("Inject into " + instance.getClass().getName());

// Use our own method to construct dependencies
Injector.setInstanceSupplier(DefaultInjector::createDependency);

Injector.injectMembers(instance, injectionContext);
}
}
27 changes: 5 additions & 22 deletions src/main/java/org/jabref/gui/actions/CleanupAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
import java.util.Optional;

import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

import javafx.embed.swing.SwingNode;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;

import org.jabref.Globals;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.cleanup.CleanupDialog;
import org.jabref.gui.cleanup.CleanupPresetPanel;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableFieldChange;
Expand Down Expand Up @@ -67,27 +63,14 @@ public void run() {
if (canceled) {
return;
}
CleanupPresetPanel presetPanel = new CleanupPresetPanel(panel.getBibDatabaseContext(),
CleanupPreset.loadFromPreferences(preferences));

SwingNode node = new SwingNode();
presetPanel.getScrollPane().setVisible(true);

JScrollPane scrollPane = presetPanel.getScrollPane();
node.setContent(scrollPane);
node.setVisible(true);

DialogPane pane = new DialogPane();
pane.setContent(node);
pane.setPrefSize(600, 600);

Optional<ButtonType> ok = dialogService.showCustomDialogAndWait(Localization.lang("Cleanup entries"), pane, ButtonType.OK, ButtonType.CANCEL);
CleanupDialog cleanupDialog = new CleanupDialog(panel.getBibDatabaseContext(), CleanupPreset.loadFromPreferences(preferences));

if (!ok.isPresent() || ((ok.isPresent() && (ok.get() == ButtonType.CANCEL)))) {
Optional<CleanupPreset> chosenPreset = cleanupDialog.showAndWait();
if (!chosenPreset.isPresent()) {
canceled = true;
return;
}
CleanupPreset cleanupPreset = presetPanel.getCleanupPreset();
CleanupPreset cleanupPreset = chosenPreset.get();
cleanupPreset.storeInPreferences(preferences);

if (cleanupPreset.isRenamePDF() && Globals.prefs.getBoolean(JabRefPreferences.ASK_AUTO_NAMING_PDFS_AGAIN)) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/actions/CopyFilesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ private void showDialog(List<CopyFilesResultItemViewModel> data) {
dialogService.showInformationDialogAndWait(Localization.lang("Copy linked files to folder..."), Localization.lang("No linked files found for export."));
return;
}
CopyFilesDialogView dlg = new CopyFilesDialogView(databaseContext, new CopyFilesResultListDependency(data));
dlg.show();
CopyFilesDialogView dialog = new CopyFilesDialogView(databaseContext, new CopyFilesResultListDependency(data));
dialog.show();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@ public ShowPreferencesAction(JabRefFrame jabRefFrame) {

@Override
public void execute() {
// output(Localization.lang("Opening preferences..."));
if (prefsDialog == null) {
prefsDialog = new PreferencesDialog(jabRefFrame);
//prefsDialog.setLocationRelativeTo(JabRefFrame.this);
} else {
prefsDialog.setValues();
}

prefsDialog.setVisible(true);
//output("");

prefsDialog.show();
}

}
34 changes: 34 additions & 0 deletions src/main/java/org/jabref/gui/cleanup/CleanupDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jabref.gui.cleanup;

import javax.swing.JScrollPane;

import javafx.scene.control.ButtonType;

import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.ControlHelper;
import org.jabref.logic.cleanup.CleanupPreset;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;

public class CleanupDialog extends BaseDialog<CleanupPreset> {

public CleanupDialog(BibDatabaseContext databaseContext, CleanupPreset initialPreset) {
setTitle(Localization.lang("Cleanup entries"));
getDialogPane().setPrefSize(600, 600);
getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL);

CleanupPresetPanel presetPanel = new CleanupPresetPanel(databaseContext, initialPreset);
presetPanel.getScrollPane().setVisible(true);
JScrollPane scrollPane = presetPanel.getScrollPane();

setResultConverter(button -> {
if (button == ButtonType.OK) {
return presetPanel.getCleanupPreset();
} else {
return null;
}
});

ControlHelper.setSwingContent(getDialogPane(), scrollPane);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.BorderPane?>

<DialogPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="484.0" prefWidth="604.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.copyfiles.CopyFilesDialogController">
<DialogPane xmlns:fx="http://javafx.com/fxml/1" minHeight="-Infinity" minWidth="-Infinity" prefHeight="484.0"
prefWidth="604.0" xmlns="http://javafx.com/javafx/8.0.141"
fx:controller="org.jabref.gui.copyfiles.CopyFilesDialogView">
<content>
<BorderPane>
<center>
Expand Down

This file was deleted.

Loading

0 comments on commit 3c4a3ef

Please sign in to comment.