diff --git a/src/main/java/org/jabref/gui/preferences/ExternalTab.java b/src/main/java/org/jabref/gui/preferences/ExternalTab.java index 8ce4dced4e7..fc6603f9a95 100644 --- a/src/main/java/org/jabref/gui/preferences/ExternalTab.java +++ b/src/main/java/org/jabref/gui/preferences/ExternalTab.java @@ -177,7 +177,7 @@ private void addSettingsButton(final PushToApplication application, GridPane pan PushToApplicationSettings settings = PushToApplications.getSettings(application); Button button = new Button(Localization.lang("Settings for %0", application.getApplicationName())); button.setPrefSize(150, 20); - button.setOnAction(e -> PushToApplicationSettingsDialog.showSettingsDialog(null, settings, index)); + button.setOnAction(e -> PushToApplicationSettingsDialog.showSettingsDialog(dialogService, settings, index)); if ((index % 2) == 0) { panel.add(button, 1, (index / 2) + 1); } else { diff --git a/src/main/java/org/jabref/gui/push/PushToApplication.java b/src/main/java/org/jabref/gui/push/PushToApplication.java index 62a2649a2a8..a892becd602 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplication.java +++ b/src/main/java/org/jabref/gui/push/PushToApplication.java @@ -21,6 +21,7 @@ public interface PushToApplication { JabRefIcon getIcon(); + /** * The actual operation. This method will not be called on the event dispatch thread, so it should not do GUI * operations without utilizing invokeLater(). diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationAction.java b/src/main/java/org/jabref/gui/push/PushToApplicationAction.java index e514a8fec55..3231a2a5e21 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationAction.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationAction.java @@ -3,10 +3,7 @@ import java.util.List; import java.util.Optional; -import javax.swing.SwingUtilities; - import org.jabref.Globals; -import org.jabref.JabRefExecutorService; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; import org.jabref.gui.StateManager; @@ -14,6 +11,7 @@ import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.icon.JabRefIcon; import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.util.BackgroundTask; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; @@ -23,10 +21,10 @@ /** * An Action class representing the process of invoking a PushToApplication operation. */ -public class PushToApplicationAction extends SimpleCommand implements Runnable { +public class PushToApplicationAction extends SimpleCommand { - private PushToApplication operation; - private JabRefFrame frame; + private final PushToApplication operation; + private final JabRefFrame frame; private BasePanel panel; private List entries; @@ -50,6 +48,7 @@ private PushToApplication getLastUsedApplication(List pushAct public Action getActionInformation() { return new Action() { + @Override public Optional getIcon() { return Optional.of(operation.getIcon()); @@ -85,7 +84,7 @@ public void execute() { entries = panel.getSelectedEntries(); if (entries.isEmpty()) { frame.getDialogService().showErrorDialogAndWait(operation.getApplicationName(), - Localization.lang("This operation requires one or more entries to be selected.")); + Localization.lang("This operation requires one or more entries to be selected.")); return; } @@ -95,7 +94,7 @@ public void execute() { for (BibEntry entry : entries) { if (!(entry.getCiteKeyOptional().isPresent()) || entry.getCiteKeyOptional().get().trim().isEmpty()) { frame.getDialogService().showErrorDialogAndWait(operation.getApplicationName(), - Localization.lang("This operation requires all selected entries to have BibTeX keys defined.")); + Localization.lang("This operation requires all selected entries to have BibTeX keys defined.")); return; } @@ -103,16 +102,15 @@ public void execute() { } // All set, call the operation in a new thread: - JabRefExecutorService.INSTANCE.execute(this); + + BackgroundTask.wrap(this::pushentries) + .onSuccess(s -> operation.operationCompleted(panel)) + .executeWith(Globals.TASK_EXECUTOR); + } - @Override - public void run() { - // Do the operation: + private void pushentries() { operation.pushEntries(panel.getDatabase(), entries, getKeyString(entries), panel.getBibDatabaseContext().getMetaData()); - - // Call the operationCompleted() method on the event dispatch thread: - SwingUtilities.invokeLater(() -> operation.operationCompleted(panel)); } private static String getKeyString(List bibentries) { diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationSettings.java b/src/main/java/org/jabref/gui/push/PushToApplicationSettings.java index 7f35bb9f59a..d0818faf106 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationSettings.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationSettings.java @@ -1,9 +1,5 @@ package org.jabref.gui.push; -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.JTextField; - import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; @@ -11,92 +7,50 @@ import org.jabref.Globals; import org.jabref.gui.DialogService; -import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; - public class PushToApplicationSettings { - protected final JTextField path = new JTextField(30); - protected final TextField path1 = new TextField(); - protected JPanel settings; + + protected final TextField path = new TextField(); + protected Label commandLabel = new Label(); protected GridPane jfxSettings; - protected FormBuilder builder; protected AbstractPushToApplication application; private DialogService dialogService; - /** - * This method asks the implementing class to return a JPanel populated with the imlementation's options panel, if - * necessary. If the JPanel is shown to the user, and the user indicates that settings should be stored, the - * implementation's storeSettings() method will be called. This method must make sure all widgets in the panel are - * in the correct selection states. - * - * @return a JPanel containing options, or null if options are not needed. - */ - public JPanel getSettingsPanel(int n) { + public GridPane getJFXSettingPane(int n) { switch (n) { - case 0: application = new PushToEmacs(dialogService); - break; - case 1: application = new PushToLyx(dialogService); - break; - case 2: application = new PushToTexmaker(dialogService); - break; - case 3: application = new PushToTeXstudio(dialogService); - break; - case 4: application = new PushToVim(dialogService); - break; - case 5: application = new PushToWinEdt(dialogService); - break; - default: application = null; - break; + case 0: + application = new PushToEmacs(dialogService); + break; + case 1: + application = new PushToLyx(dialogService); + break; + case 2: + application = new PushToTexmaker(dialogService); + break; + case 3: + application = new PushToTeXstudio(dialogService); + break; + case 4: + application = new PushToVim(dialogService); + break; + case 5: + application = new PushToWinEdt(dialogService); + break; + default: + application = null; + break; } - application.initParameters(); - String commandPath = Globals.prefs.get(application.commandPathPreferenceKey); - if (settings == null) { - initSettingsPanel(); - } - path.setText(commandPath); - return settings; - } - - public GridPane getJFXSettingPane() { application.initParameters(); String commandPath = Globals.prefs.get(application.commandPathPreferenceKey); if (jfxSettings == null) { initJFXSettingsPanel(); } - path1.setText(commandPath); - return jfxSettings; - } - - /** - * Create a FormBuilder, fill it with a textbox for the path and store the JPanel in settings - */ - protected void initSettingsPanel() { - builder = FormBuilder.create(); - builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p")); - StringBuilder label = new StringBuilder(Localization.lang("Path to %0", application.commandPathPreferenceKey)); - // In case the application name and the actual command is not the same, add the command in brackets - if (application.getCommandName() == null) { - label.append(':'); - } else { - label.append(" (").append(application.getCommandName()).append("):"); - } - builder.add(label.toString()).xy(1, 1); - builder.add(path).xy(3, 1); - JButton browse = new JButton(Localization.lang("Browse")); - - FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); + path.setText(commandPath); - browse.addActionListener( - e -> DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.showFileOpenDialog(fileDialogConfiguration)) - .ifPresent(f -> path.setText(f.toAbsolutePath().toString()))); - builder.add(browse).xy(5, 1); - settings = builder.build(); + return jfxSettings; } protected void initJFXSettingsPanel() { @@ -108,17 +62,17 @@ protected void initJFXSettingsPanel() { } else { label.append(" (").append(application.getCommandName()).append("):"); } - jfxSettings.add(new Label(label.toString()),1,1); - jfxSettings.add(path1,2, 1); + commandLabel = new Label(label.toString()); + jfxSettings.add(commandLabel, 0, 0); + jfxSettings.add(path, 1, 0); Button browse = new Button(Localization.lang("Browse")); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); + .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); - browse.setOnAction( - e -> DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.showFileOpenDialog(fileDialogConfiguration)) - .ifPresent(f -> path.setText(f.toAbsolutePath().toString()))); - jfxSettings.add(browse,3, 1); + browse.setOnAction(e -> dialogService.showFileOpenDialog(fileDialogConfiguration) + .ifPresent(f -> path.setText(f.toAbsolutePath().toString()))); + jfxSettings.add(browse, 2, 0); } /** diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationSettingsDialog.java b/src/main/java/org/jabref/gui/push/PushToApplicationSettingsDialog.java index f754941839e..4374c7322a0 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationSettingsDialog.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationSettingsDialog.java @@ -1,61 +1,22 @@ package org.jabref.gui.push; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; +import javafx.scene.control.ButtonType; +import javafx.scene.control.DialogPane; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JPanel; - -import org.jabref.Globals; -import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.DialogService; import org.jabref.logic.l10n.Localization; -import com.jgoodies.forms.builder.ButtonBarBuilder; - public class PushToApplicationSettingsDialog { - public static void showSettingsDialog(JFrame parent, PushToApplicationSettings toApp, int n) { - final JDialog diag = new JDialog(parent, Localization.lang("Settings"), true); - JPanel options = toApp.getSettingsPanel(n); - options.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - diag.getContentPane().add(options, BorderLayout.CENTER); - ButtonBarBuilder bb = new ButtonBarBuilder(); - JButton ok = new JButton(Localization.lang("OK")); - JButton cancel = new JButton(Localization.lang("Cancel")); - bb.addGlue(); - bb.addButton(ok); - bb.addButton(cancel); - bb.addGlue(); - bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); - ok.addActionListener(e -> { - // If the user pressed Ok, ask the PushToApplication implementation to store its settings: - toApp.storeSettings(); - diag.dispose(); - }); - cancel.addActionListener(e -> diag.dispose()); - // Key bindings: - ActionMap am = bb.getPanel().getActionMap(); - InputMap im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); - im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close"); - am.put("close", new AbstractAction() { + public static void showSettingsDialog(DialogService dialogService, PushToApplicationSettings toApp, int n) { - @Override - public void actionPerformed(ActionEvent e) { - diag.dispose(); + DialogPane dialogPane = new DialogPane(); + dialogPane.setContent(toApp.getJFXSettingPane(n)); + + dialogService.showCustomDialogAndWait(Localization.lang("App settings"), dialogPane, ButtonType.OK, ButtonType.CANCEL).ifPresent(btn -> { + if (btn == ButtonType.OK) { + toApp.storeSettings(); } }); - diag.pack(); - diag.setLocationRelativeTo(parent); - - // Show the dialog: - diag.setVisible(true); } } diff --git a/src/main/java/org/jabref/gui/push/PushToEmacsSettings.java b/src/main/java/org/jabref/gui/push/PushToEmacsSettings.java index e0a44562625..ca4cee137ac 100644 --- a/src/main/java/org/jabref/gui/push/PushToEmacsSettings.java +++ b/src/main/java/org/jabref/gui/push/PushToEmacsSettings.java @@ -1,9 +1,7 @@ package org.jabref.gui.push; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import javafx.scene.layout.GridPane; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; import org.jabref.Globals; import org.jabref.logic.l10n.Localization; @@ -11,19 +9,7 @@ public class PushToEmacsSettings extends PushToApplicationSettings { - private final JTextField additionalParams = new JTextField(30); - - @Override - public JPanel getSettingsPanel(int n) { - additionalParams.setText(Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS)); - return super.getSettingsPanel(n); - } - - @Override - public GridPane getJFXSettingPane() { - additionalParams.setText(Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS)); - return super.getJFXSettingPane(); - } + private final TextField additionalParams = new TextField(); @Override public void storeSettings() { @@ -32,11 +18,10 @@ public void storeSettings() { } @Override - protected void initSettingsPanel() { - super.initSettingsPanel(); - builder.appendRows("2dlu, p, 2dlu, p"); - builder.add(Localization.lang("Additional parameters") + ":").xy(1, 3); - builder.add(additionalParams).xy(3, 3); - settings = builder.build(); + protected void initJFXSettingsPanel() { + super.initJFXSettingsPanel(); + jfxSettings.add(new Label(Localization.lang("Additional parameters") + ":"), 0, 1); + jfxSettings.add(additionalParams, 1, 1); + additionalParams.setText(Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS)); } } diff --git a/src/main/java/org/jabref/gui/push/PushToLyx.java b/src/main/java/org/jabref/gui/push/PushToLyx.java index 265d9f0fbbe..f1b58c1ec6f 100644 --- a/src/main/java/org/jabref/gui/push/PushToLyx.java +++ b/src/main/java/org/jabref/gui/push/PushToLyx.java @@ -61,7 +61,6 @@ public void operationCompleted(BasePanel panel) { @Override public void pushEntries(BibDatabase database, final List entries, final String keyString, MetaData metaData) { - couldNotConnect = false; couldNotCall = false; notDefined = false; diff --git a/src/main/java/org/jabref/gui/push/PushToLyxSettings.java b/src/main/java/org/jabref/gui/push/PushToLyxSettings.java index eeb35ed812d..856f6fc86be 100644 --- a/src/main/java/org/jabref/gui/push/PushToLyxSettings.java +++ b/src/main/java/org/jabref/gui/push/PushToLyxSettings.java @@ -1,17 +1,15 @@ package org.jabref.gui.push; -import javax.swing.JLabel; -import javax.swing.JPanel; - +import org.jabref.Globals; import org.jabref.logic.l10n.Localization; +import org.jabref.preferences.JabRefPreferences; public class PushToLyxSettings extends PushToApplicationSettings { @Override - protected void initSettingsPanel() { - super.initSettingsPanel(); - settings = new JPanel(); - settings.add(new JLabel(Localization.lang("Path to LyX pipe") + ":")); - settings.add(path); + protected void initJFXSettingsPanel() { + super.initJFXSettingsPanel(); + path.setText(Globals.prefs.get(JabRefPreferences.LYXPIPE)); + commandLabel.setText(Localization.lang("Path to LyX pipe") + ":"); } } diff --git a/src/main/java/org/jabref/gui/push/PushToVimSettings.java b/src/main/java/org/jabref/gui/push/PushToVimSettings.java index 89ceab1d37b..ce94973675d 100644 --- a/src/main/java/org/jabref/gui/push/PushToVimSettings.java +++ b/src/main/java/org/jabref/gui/push/PushToVimSettings.java @@ -1,7 +1,7 @@ package org.jabref.gui.push; -import javax.swing.JPanel; -import javax.swing.JTextField; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; import org.jabref.Globals; import org.jabref.logic.l10n.Localization; @@ -9,13 +9,7 @@ public class PushToVimSettings extends PushToApplicationSettings { - private final JTextField vimServer = new JTextField(30); - - @Override - public JPanel getSettingsPanel(int n) { - vimServer.setText(Globals.prefs.get(JabRefPreferences.VIM_SERVER)); - return super.getSettingsPanel(n); - } + private final TextField vimServer = new TextField(); @Override public void storeSettings() { @@ -24,11 +18,10 @@ public void storeSettings() { } @Override - protected void initSettingsPanel() { - super.initSettingsPanel(); - builder.appendRows("2dlu, p"); - builder.add(Localization.lang("Vim server name") + ":").xy(1, 3); - builder.add(vimServer).xy(3, 3); - settings = builder.build(); + protected void initJFXSettingsPanel() { + super.initJFXSettingsPanel(); + jfxSettings.add(new Label(Localization.lang("Vim server name") + ":"), 0, 1); + jfxSettings.add(vimServer, 1, 1); + vimServer.setText(Globals.prefs.get(JabRefPreferences.VIM_SERVER)); } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 31c3d5adc5d..1546ff133c3 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2091,3 +2091,6 @@ Executing\ command\ "%0"...=Executing command "%0"... Rename\ file\ to\ a\ given\ name=Rename file to a given name New\ Filename=New Filename Rename\ file\ to\ defined\ pattern=Rename file to defined pattern + +App\ settings=App settings +