Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialogstojavafx #3801

Merged
merged 24 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
67c489e
convert dialogs to javafx
Siedlerchr Mar 2, 2018
ad502c4
convert open office and other preferences
Siedlerchr Mar 2, 2018
55a985f
Convert entryTypeList and entry customization and shared database
Siedlerchr Mar 2, 2018
bb66b22
And convert some more
Siedlerchr Mar 2, 2018
ce6837f
Merge remote-tracking branch 'upstream/maintable-beta' into dialogsto…
Siedlerchr Mar 3, 2018
86dfdc3
Pass dialogService instead of frame
Siedlerchr Mar 3, 2018
13500fe
entry types list
Siedlerchr Mar 3, 2018
d05d253
create choice dialog
Siedlerchr Mar 3, 2018
f4b84d6
ADd method for returning list in Encodings
Siedlerchr Mar 3, 2018
71b17c2
Convert some more confirmation dialogs
Siedlerchr Mar 3, 2018
469a834
convert some more dialogs
Siedlerchr Mar 3, 2018
6b1ef6f
Merge branch 'maintable-beta' into dialogstojavafx
Siedlerchr Mar 3, 2018
cbb1df3
fix checkstyle and add missing lang keys
Siedlerchr Mar 3, 2018
9e7ff57
fix dialog conditions
Siedlerchr Mar 4, 2018
5b8b745
Merge remote-tracking branch 'upstream/maintable-beta' into dialogsto…
Siedlerchr Mar 4, 2018
9a04aa6
add better title for share db dialog
Siedlerchr Mar 4, 2018
4d1b6e7
Add dialogservice to push to apps
Siedlerchr Mar 4, 2018
74391d4
add new keys
Siedlerchr Mar 4, 2018
44bceed
fix dialog service in push
Siedlerchr Mar 4, 2018
cf82ad3
checkstyle
Siedlerchr Mar 4, 2018
a43a7de
use dialogservice as local variable
Siedlerchr Mar 4, 2018
7d4afe0
pass Dialog service to push dialogs as ctor arg
Siedlerchr Mar 5, 2018
3dc6068
Merge remote-tracking branch 'upstream/maintable-beta' into dialogsto…
Siedlerchr Mar 5, 2018
43d38db
checkstyle
Siedlerchr Mar 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.jabref.gui.AbstractView;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.FXDialogService;
import org.jabref.gui.GUIGlobals;
import org.jabref.gui.IconTheme;
Expand Down Expand Up @@ -51,12 +52,14 @@ public class JabRefGUI {
private final boolean isBlank;
private final List<ParserResult> failed = new ArrayList<>();
private final List<ParserResult> toOpenTab = new ArrayList<>();
private final DialogService dialogService;

private final String focusedFile;

public JabRefGUI(Stage mainStage, List<ParserResult> argsDatabases, boolean isBlank) {
this.bibDatabases = argsDatabases;
this.isBlank = isBlank;
this.dialogService = new FXDialogService(mainStage);

// passed file (we take the first one) should be focused
focusedFile = argsDatabases.stream().findFirst().flatMap(ParserResult::getFile).map(File::getAbsolutePath)
Expand Down Expand Up @@ -87,7 +90,7 @@ private void openWindow(Stage mainStage) {

// If the option is enabled, open the last edited libraries, if any.
if (!isBlank && Globals.prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) {
openLastEditedDatabases(mainStage);
openLastEditedDatabases();
}

GUIGlobals.init();
Expand Down Expand Up @@ -159,12 +162,11 @@ private void openWindow(Stage mainStage) {
});

for (ParserResult pr : failed) {
String message = "<html>" + Localization.lang("Error opening file '%0'.", pr.getFile().get().getName())
+ "<p>"
+ pr.getErrorMessage() + "</html>";
String message = Localization.lang("Error opening file '%0'.", pr.getFile().get().getName()) + "\n"
+ pr.getErrorMessage();

dialogService.showErrorDialogAndWait(Localization.lang("Error opening file"), message);

JOptionPane.showMessageDialog(null, message, Localization.lang("Error opening file"),
JOptionPane.ERROR_MESSAGE);
}

// Display warnings, if any
Expand All @@ -191,7 +193,7 @@ private void openWindow(Stage mainStage) {
LOGGER.debug("Finished adding panels");
}

private void openLastEditedDatabases(Stage mainStage) {
private void openLastEditedDatabases() {
if (Globals.prefs.get(JabRefPreferences.LAST_EDITED) == null) {
return;
}
Expand All @@ -206,7 +208,7 @@ private void openLastEditedDatabases(Stage mainStage) {
}

if (BackupManager.checkForBackupFile(dbFile.toPath())) {
BackupUIManager.showRestoreBackupDialog(new FXDialogService(mainStage), dbFile.toPath());
BackupUIManager.showRestoreBackupDialog(dialogService, dbFile.toPath());
}

ParserResult parsedDatabase = OpenDatabase.loadDatabase(fileName,
Expand Down Expand Up @@ -264,11 +266,11 @@ private void setLookAndFeel() {
// also set system l&f as default
Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel);
// notify the user
JOptionPane.showMessageDialog(null,
Localization
.lang("Unable to find the requested look and feel and thus the default one is used."),
Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);

LOGGER.warn("Unable to find requested look and feel", e);
dialogService.showWarningDialogAndWait(Localization.lang("Warning"),
Localization.lang("Unable to find the requested look and feel and thus the default one is used."));

}
}

Expand Down
19 changes: 10 additions & 9 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
import org.jabref.gui.undo.UndoableRemoveEntry;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.component.CheckBoxMessage;
import org.jabref.gui.worker.AbstractWorker;
import org.jabref.gui.worker.CallBack;
import org.jabref.gui.worker.CitationStyleToClipboardWorker;
Expand Down Expand Up @@ -420,15 +419,16 @@ public void run() {
// if we're going to override some cite keys warn the user about it
} else if (Globals.prefs.getBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY)) {
if (entries.parallelStream().anyMatch(BibEntry::hasCiteKey)) {
CheckBoxMessage cbm = new CheckBoxMessage(

boolean overwriteKeysPressed = dialogService.showConfirmationDialogWithOptOutAndWait(Localization.lang("Overwrite keys"),
Localization.lang("One or more keys will be overwritten. Continue?"),
Localization.lang("Disable this confirmation dialog"), false);
final int answer = JOptionPane.showConfirmDialog(null, cbm,
Localization.lang("Overwrite keys"), JOptionPane.YES_NO_OPTION);
Globals.prefs.putBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY, !cbm.isSelected());
Localization.lang("Overwrite keys"),
Localization.lang("Cancel"),
Localization.lang("Disable this confirmation dialog"),
optOut -> Globals.prefs.putBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY, !optOut));

// The user doesn't want to overide cite keys
if (answer == JOptionPane.NO_OPTION) {
if (!overwriteKeysPressed) {
canceled = true;
return;
}
Expand Down Expand Up @@ -525,7 +525,7 @@ public void update() {

actions.put(Actions.OPEN_URL, new OpenURLAction());

actions.put(Actions.MERGE_WITH_FETCHED_ENTRY, new MergeWithFetchedEntryAction(this));
actions.put(Actions.MERGE_WITH_FETCHED_ENTRY, new MergeWithFetchedEntryAction(this, frame.getDialogService()));

actions.put(Actions.REPLACE_ALL, (BaseAction) () -> {
final ReplaceStringDialog rsd = new ReplaceStringDialog(frame);
Expand Down Expand Up @@ -657,7 +657,7 @@ public void update() {
actions.put(Actions.REMOVE_FROM_GROUP, new GroupAddRemoveDialog(this, false, false));
actions.put(Actions.MOVE_TO_GROUP, new GroupAddRemoveDialog(this, true, true));

actions.put(Actions.DOWNLOAD_FULL_TEXT, new FindFullTextAction(this));
actions.put(Actions.DOWNLOAD_FULL_TEXT, new FindFullTextAction(frame.getDialogService(), this));
}

/**
Expand Down Expand Up @@ -966,6 +966,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc,
new String[] {Localization.lang("Save"), tryDiff, Localization.lang("Cancel")}, tryDiff);

if (answer == JOptionPane.NO_OPTION) {

// The user wants to use another encoding.
Object choice = JOptionPane.showInputDialog(null, Localization.lang("Select encoding"), SAVE_DATABASE,
JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, enc);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui;

import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
Expand All @@ -9,7 +10,9 @@
import javafx.print.PrinterJob;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextInputDialog;

import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.gui.util.FileDialogConfiguration;
Expand All @@ -22,6 +25,14 @@
*/
public interface DialogService {

/**
* This will create and display new {@link ChoiceDialog} of type T with a default choice and a collection of possible choices
*/
<T> Optional<T> showChoiceDialogAndWait(String title, String content, String okButtonLabel, T defaultChoice, Collection<T> choices);

/**
* This will create and display new {@link TextInputDialog} with a text fields to enter data
*/
Optional<String> showInputDialogAndWait(String title, String content);

/**
Expand Down Expand Up @@ -224,4 +235,6 @@ Optional<ButtonType> showCustomButtonDialogAndWait(Alert.AlertType type, String
* @return false if the user opts to cancel printing
*/
boolean showPrintDialog(PrinterJob job);


}
11 changes: 5 additions & 6 deletions src/main/java/org/jabref/gui/EntryTypeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
Expand Down Expand Up @@ -331,13 +330,13 @@ protected void done() {

dispose();
} else if (searchID.trim().isEmpty()) {
JOptionPane.showMessageDialog(null, Localization.lang("The given search ID was empty."), Localization.lang("Empty search ID"), JOptionPane.WARNING_MESSAGE);
frame.getDialogService().showWarningDialogAndWait(Localization.lang("Empty search ID"),
Localization.lang("The given search ID was empty."));
} else if (!fetcherException) {
JOptionPane.showMessageDialog(null, Localization.lang("Fetcher '%0' did not find an entry for id '%1'.", fetcher.getName(), searchID) + "\n" + fetcherExceptionMessage, Localization.lang("No files found."), JOptionPane.WARNING_MESSAGE);
frame.getDialogService().showErrorDialogAndWait(Localization.lang("No files found.",
Localization.lang("Fetcher '%0' did not find an entry for id '%1'.", fetcher.getName(), searchID) + "\n" + fetcherExceptionMessage));
} else {
JOptionPane.showMessageDialog(null,
Localization.lang("Error while fetching from %0", fetcher.getName()) + "." + "\n" + fetcherExceptionMessage,
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
frame.getDialogService().showErrorDialogAndWait(Localization.lang("Error"), Localization.lang("Error while fetching from %0", fetcher.getName()) + "." + "\n" + fetcherExceptionMessage);
}
fetcherWorker = new FetcherWorker();
SwingUtilities.invokeLater(() -> {
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/org/jabref/gui/FXDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand All @@ -17,6 +18,7 @@
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.Region;
Expand Down Expand Up @@ -66,7 +68,7 @@ private static FXDialog createDialog(AlertType type, String title, String conten
}

private static FXDialog createDialogWithOptOut(AlertType type, String title, String content,
String optOutMessage, Consumer<Boolean> optOutAction) {
String optOutMessage, Consumer<Boolean> optOutAction) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be another inconsistency between eclipse and intellj style

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will investigate that

FXDialog alert = new FXDialog(type, title, true);
// Need to force the alert to layout in order to grab the graphic as we are replacing the dialog pane with a custom pane
alert.getDialogPane().applyCss();
Expand All @@ -75,6 +77,7 @@ private static FXDialog createDialogWithOptOut(AlertType type, String title, Str
// Create a new dialog pane that has a checkbox instead of the hide/show details button
// Use the supplied callback for the action of the checkbox
alert.setDialogPane(new DialogPane() {

@Override
protected Node createDetailsButton() {
CheckBox optOut = new CheckBox();
Expand All @@ -97,6 +100,17 @@ protected Node createDetailsButton() {
return alert;
}

@Override
public <T> Optional<T> showChoiceDialogAndWait(String title, String content, String okButtonLabel, T defaultChoice, Collection<T> choices) {
ChoiceDialog<T> choiceDialog = new ChoiceDialog<>(defaultChoice, choices);
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE);
choiceDialog.getDialogPane().getButtonTypes().setAll(ButtonType.CANCEL, okButtonType);
choiceDialog.setHeaderText(title);
choiceDialog.setContentText(content);
return choiceDialog.showAndWait();

}

@Override
public Optional<String> showInputDialogAndWait(String title, String content) {
TextInputDialog inputDialog = new TextInputDialog();
Expand Down Expand Up @@ -160,7 +174,7 @@ public boolean showConfirmationDialogAndWait(String title, String content, Strin

@Override
public boolean showConfirmationDialogAndWait(String title, String content,
String okButtonLabel, String cancelButtonLabel) {
String okButtonLabel, String cancelButtonLabel) {
FXDialog alert = createDialog(AlertType.CONFIRMATION, title, content);
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE);
ButtonType cancelButtonType = new ButtonType(cancelButtonLabel, ButtonBar.ButtonData.NO);
Expand All @@ -170,16 +184,16 @@ public boolean showConfirmationDialogAndWait(String title, String content,

@Override
public boolean showConfirmationDialogWithOptOutAndWait(String title, String content,
String optOutMessage, Consumer<Boolean> optOutAction) {
String optOutMessage, Consumer<Boolean> optOutAction) {
FXDialog alert = createDialogWithOptOut(AlertType.CONFIRMATION, title, content, optOutMessage, optOutAction);
alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO);
return alert.showAndWait().filter(buttonType -> buttonType == ButtonType.YES).isPresent();
}

@Override
public boolean showConfirmationDialogWithOptOutAndWait(String title, String content,
String okButtonLabel, String cancelButtonLabel,
String optOutMessage, Consumer<Boolean> optOutAction) {
String okButtonLabel, String cancelButtonLabel,
String optOutMessage, Consumer<Boolean> optOutAction) {
FXDialog alert = createDialogWithOptOut(AlertType.CONFIRMATION, title, content, optOutMessage, optOutAction);
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.YES);
ButtonType cancelButtonType = new ButtonType(cancelButtonLabel, ButtonBar.ButtonData.NO);
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/org/jabref/gui/actions/ActionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import javafx.scene.control.Button;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tooltip;

import org.jabref.gui.keyboard.KeyBindingRepository;

import de.saxsys.mvvmfx.utils.commands.Command;
Expand All @@ -17,7 +15,7 @@
*/
public class ActionFactory {

private KeyBindingRepository keyBindingRepository;
private final KeyBindingRepository keyBindingRepository;

public ActionFactory(KeyBindingRepository keyBindingRepository) {
this.keyBindingRepository = Objects.requireNonNull(keyBindingRepository);
Expand Down Expand Up @@ -59,8 +57,7 @@ public Menu createSubMenu(Action action, MenuItem... children) {
public Button createIconButton(Action action, Command command) {
Button button = ActionUtils.createButton(new JabRefAction(action, command, keyBindingRepository), ActionUtils.ActionTextBehavior.HIDE);
button.getStyleClass().add("flatButton");
button.setTooltip(new Tooltip(action.getDescription()));


// For some reason the graphic is not set correctly, so let's fix this
button.graphicProperty().unbind();
action.getIcon().ifPresent(icon -> button.setGraphic(icon.getGraphicNode()));
Expand Down
35 changes: 17 additions & 18 deletions src/main/java/org/jabref/gui/actions/CleanupAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.component.CheckBoxMessage;
import org.jabref.gui.worker.AbstractWorker;
import org.jabref.logic.cleanup.CleanupPreset;
import org.jabref.logic.cleanup.CleanupWorker;
Expand Down Expand Up @@ -73,15 +72,15 @@ public void run() {
cleanupPreset.storeInPreferences(preferences);

if (cleanupPreset.isRenamePDF() && Globals.prefs.getBoolean(JabRefPreferences.ASK_AUTO_NAMING_PDFS_AGAIN)) {
CheckBoxMessage cbm = new CheckBoxMessage(

boolean autogeneratePressed = dialogService.showConfirmationDialogWithOptOutAndWait(Localization.lang("Autogenerate PDF Names"),
Localization.lang("Auto-generating PDF-Names does not support undo. Continue?"),
Localization.lang("Disable this confirmation dialog"), false);
int answer = JOptionPane.showConfirmDialog(null, cbm, Localization.lang("Autogenerate PDF Names"),
JOptionPane.YES_NO_OPTION);
if (cbm.isSelected()) {
Globals.prefs.putBoolean(JabRefPreferences.ASK_AUTO_NAMING_PDFS_AGAIN, false);
}
if (answer == JOptionPane.NO_OPTION) {
Localization.lang("Autogenerate PDF Names"),
Localization.lang("Cancel"),
Localization.lang("Disable this confirmation dialog"),
optOut -> Globals.prefs.putBoolean(JabRefPreferences.ASK_AUTO_NAMING_PDFS_AGAIN, !optOut));

if (!autogeneratePressed) {
canceled = true;
return;
}
Expand Down Expand Up @@ -117,15 +116,15 @@ public void update() {
}
String message;
switch (modifiedEntriesCount) {
case 0:
message = Localization.lang("No entry needed a clean up");
break;
case 1:
message = Localization.lang("One entry needed a clean up");
break;
default:
message = Localization.lang("%0 entries needed a clean up", Integer.toString(modifiedEntriesCount));
break;
case 0:
message = Localization.lang("No entry needed a clean up");
break;
case 1:
message = Localization.lang("One entry needed a clean up");
break;
default:
message = Localization.lang("%0 entries needed a clean up", Integer.toString(modifiedEntriesCount));
break;
}
panel.output(message);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/actions/JabRefAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
*/
class JabRefAction extends org.controlsfx.control.action.Action {


public JabRefAction(Action action, KeyBindingRepository keyBindingRepository) {
super(action.getText());
action.getIcon()
.ifPresent(icon -> setGraphic(icon.getGraphicNode()));
action.getKeyBinding()
.ifPresent(keyBinding -> setAccelerator(keyBindingRepository.getKeyCombination(keyBinding)));

setLongText(action.getDescription());

}

public JabRefAction(Action action, Command command, KeyBindingRepository keyBindingRepository) {
Expand Down
Loading