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 1 commit
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
15 changes: 8 additions & 7 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 @@ -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
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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, T defaultChoice, Collection<T> 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
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/org/jabref/gui/FXDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,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 @@ -77,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 @@ -100,9 +101,10 @@ protected Node createDetailsButton() {
}

@Override
public <T> Optional<T> showChoiceDialogAndWait(String title, String content, T defaultChoice, Collection<T> choices)
{
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();
Expand All @@ -117,7 +119,6 @@ public Optional<String> showInputDialogAndWait(String title, String content) {
return inputDialog.showAndWait();
}


@Override
public void showInformationDialogAndWait(String title, String content) {
FXDialog alert = createDialog(AlertType.INFORMATION, title, content);
Expand Down Expand Up @@ -173,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 @@ -183,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
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
10 changes: 6 additions & 4 deletions src/main/java/org/jabref/gui/exporter/ExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import java.util.List;
import java.util.stream.Collectors;

import javax.swing.JOptionPane;

import javafx.stage.FileChooser;

import org.jabref.Globals;
Expand Down Expand Up @@ -62,9 +60,13 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt

if (Files.exists(file)) {
// Warn that the file exists:
if (JOptionPane.showConfirmDialog(null,

boolean overwriteFilePressed = frame.getDialogService().showConfirmationDialogAndWait(Localization.lang("Export"),
Localization.lang("'%0' exists. Overwrite file?", file.getFileName().toString()),
Localization.lang("Export"), JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) {
Localization.lang("Overwrite file"),
Localization.lang("Cancel"));

if (!overwriteFilePressed) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding)

if (answer == JOptionPane.NO_OPTION) {
// The user wants to use another encoding.
Optional<Charset> selectedCharSet = frame.getDialogService().showChoiceDialogAndWait(Localization.lang("Save library"), Localization.lang("Select encoding"), encoding, Encodings.getCharsets());
Optional<Charset> selectedCharSet = frame.getDialogService().showChoiceDialogAndWait(Localization.lang("Save library"), Localization.lang("Select encoding"), Localization.lang("Save library"), encoding, Encodings.getCharsets());

if (selectedCharSet.isPresent()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Optional;
import java.util.stream.Collectors;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import org.jabref.Globals;
Expand Down Expand Up @@ -191,21 +190,25 @@ private void openTheFile(Path file, boolean raisePanel) {
if ((modificationTime.isPresent()) && ((System.currentTimeMillis()
- modificationTime.get().toMillis()) > FileBasedLock.LOCKFILE_CRITICAL_AGE)) {
// The lock file is fairly old, so we can offer to "steal" the file:
int answer = JOptionPane.showConfirmDialog(null,
"<html>" + Localization.lang("Error opening file") + " '" + fileName + "'. "
+ Localization.lang("File is locked by another JabRef instance.") + "<p>"

boolean overWriteFileLockPressed = frame.getDialogService().showConfirmationDialogAndWait(Localization.lang("File locked"),
Localization.lang("Error opening file") + " '" + fileName + "'. "
+ Localization.lang("File is locked by another JabRef instance.") + "\n"
+ Localization.lang("Do you want to override the file lock?"),
Localization.lang("File locked"), JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION) {
Localization.lang("Overwrite file lock"),
Localization.lang("Cancel"));

if (overWriteFileLockPressed) {
FileBasedLock.deleteLockFile(file);
} else {
return;
}
} else if (!FileBasedLock.waitForFileLock(file)) {
JOptionPane.showMessageDialog(null,

frame.getDialogService().showErrorDialogAndWait(Localization.lang("Error"),
Localization.lang("Error opening file") + " '" + fileName + "'. "
+ Localization.lang("File is locked by another JabRef instance."),
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
+ Localization.lang("File is locked by another JabRef instance."));

return;
}
}
Expand All @@ -226,9 +229,10 @@ private void openTheFile(Path file, boolean raisePanel) {
result.getDatabaseContext().clearDatabaseFile(); // do not open the original file
result.getDatabase().clearSharedDatabaseID();
LOGGER.error("Connection error", e);
JOptionPane.showMessageDialog(null,
e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."),
Localization.lang("Connection error"), JOptionPane.WARNING_MESSAGE);

frame.getDialogService().showErrorDialogAndWait(Localization.lang("Connection error"),
e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."));

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ public ConnectToSharedDatabaseDialog(JabRefFrame frame) {
public void openSharedDatabase() {

if (isSharedDatabaseAlreadyPresent()) {
JOptionPane.showMessageDialog(ConnectToSharedDatabaseDialog.this,
Localization.lang("You are already connected to a database using entered connection details."),
Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);

frame.getDialogService().showWarningDialogAndWait(Localization.lang("Warning"),
Copy link
Member

Choose a reason for hiding this comment

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

Use a better title?

Localization.lang("You are already connected to a database using entered connection details."));

return;
}

Expand All @@ -126,10 +127,13 @@ public void openSharedDatabase() {
Path localFilePath = Paths.get(fileLocationField.getText());

if (Files.exists(localFilePath) && !Files.isDirectory(localFilePath)) {
int answer = JOptionPane.showConfirmDialog(this,

boolean overwriteFilePressed = frame.getDialogService().showConfirmationDialogAndWait(Localization.lang("Existing file"),
Localization.lang("'%0' exists. Overwrite file?", localFilePath.getFileName().toString()),
Localization.lang("Existing file"), JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.NO_OPTION) {
Localization.lang("Overwrite file"),
Localization.lang("Cancel"));

if (!overwriteFilePressed) {
fileLocationField.requestFocus();
return;
}
Expand Down