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 10 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
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
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
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, 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
13 changes: 13 additions & 0 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 @@ -97,6 +99,16 @@ protected Node createDetailsButton() {
return alert;
}

@Override
public <T> Optional<T> showChoiceDialogAndWait(String title, String content, T defaultChoice, Collection<T> choices)
{
ChoiceDialog<T> choiceDialog = new ChoiceDialog<>(defaultChoice, choices);
choiceDialog.setHeaderText(title);
choiceDialog.setContentText(content);
return choiceDialog.showAndWait();

}

@Override
public Optional<String> showInputDialogAndWait(String title, String content) {
TextInputDialog inputDialog = new TextInputDialog();
Expand All @@ -105,6 +117,7 @@ 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
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
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
15 changes: 8 additions & 7 deletions src/main/java/org/jabref/gui/actions/MassSetFieldAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.undo.UndoableEdit;
Expand Down Expand Up @@ -158,17 +157,19 @@ private void createDialog() {
// Check that any field name is set
String fieldText = (String) field.getSelectedItem();
if ((fieldText == null) || fieldText.trim().isEmpty()) {
JOptionPane.showMessageDialog(diag, Localization.lang("You must enter at least one field name"), "",
JOptionPane.ERROR_MESSAGE);

frame.getDialogService().showErrorDialogAndWait(Localization.lang("You must enter at least one field name"));

return; // Do not close the dialog.
}

// Check if the user tries to rename multiple fields:
if (rename.isSelected()) {
String[] fields = getFieldNames(fieldText);
if (fields.length > 1) {
JOptionPane.showMessageDialog(diag, Localization.lang("You can only rename one field at a time"),
"", JOptionPane.ERROR_MESSAGE);

frame.getDialogService().showErrorDialogAndWait(Localization.lang("You can only rename one field at a time"));

return; // Do not close the dialog.
}
}
Expand Down Expand Up @@ -243,8 +244,8 @@ public void execute() {
NamedCompound compoundEdit = new NamedCompound(Localization.lang("Set field"));
if (rename.isSelected()) {
if (fields.length > 1) {
JOptionPane.showMessageDialog(diag, Localization.lang("You can only rename one field at a time"), "",
JOptionPane.ERROR_MESSAGE);
frame.getDialogService().showErrorDialogAndWait(Localization.lang("You can only rename one field at a time"));

return; // Do not close the dialog.
} else {
compoundEdit.addEdit(MassSetFieldAction.massRenameField(entryList, fields[0], textFieldRename.getText(),
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/org/jabref/gui/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.Optional;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultMutableTreeNode;

Expand Down Expand Up @@ -38,6 +37,7 @@
import org.slf4j.LoggerFactory;

public class ChangeScanner implements Runnable {

private static final Logger LOGGER = LoggerFactory.getLogger(ChangeScanner.class);

private final File file;
Expand Down Expand Up @@ -94,17 +94,21 @@ public void displayResult(final DisplayResultCallback fup) {
});

} else {
JOptionPane.showMessageDialog(null, Localization.lang("No actual changes found."),
Localization.lang("External changes"), JOptionPane.INFORMATION_MESSAGE);
frame.getDialogService().showInformationDialogAndWait(Localization.lang("External changes"),
Localization.lang("No actual changes found."));

fup.scanResultsResolved(true);
}
}

private void storeTempDatabase() {
JabRefExecutorService.INSTANCE.execute(() -> {
try {
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withMakeBackup(false)
.withEncoding(panel.getBibDatabaseContext().getMetaData().getEncoding()
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs)
Copy link
Member

Choose a reason for hiding this comment

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

The code style settings still seem to be off. The dots are not aligned (if this is not an artifact of the way github displays the code)

.withMakeBackup(false)
.withEncoding(panel.getBibDatabaseContext()
.getMetaData()
.getEncoding()
.orElse(Globals.prefs.getDefaultEncoding()));

BibDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new);
Expand Down Expand Up @@ -176,6 +180,7 @@ private ChangeViewModel createBibEntryDiff(BibEntryDiff diff) {

@FunctionalInterface
public interface DisplayResultCallback {

void scanResultsResolved(boolean resolved);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListDataEvent;
Expand Down Expand Up @@ -101,7 +100,7 @@ private void initGui() {
List<String> entryTypes = new ArrayList<>();
entryTypes.addAll(EntryTypes.getAllTypes(bibDatabaseMode));

typeComp = new EntryTypeList(entryTypes, bibDatabaseMode);
typeComp = new EntryTypeList(frame.getDialogService(), entryTypes, bibDatabaseMode);
typeComp.addListSelectionListener(this);
typeComp.addAdditionActionListener(e -> typeComp.selectField(e.getActionCommand()));
typeComp.addDefaultActionListener(new DefaultListener());
Expand Down Expand Up @@ -323,14 +322,14 @@ private void deleteType(String name) {

if (type.isPresent() && (type.get() instanceof CustomEntryType)) {
if (!EntryTypes.getStandardType(name, bibDatabaseMode).isPresent()) {
int reply = JOptionPane.showConfirmDialog
(null, Localization.lang("All entries of this "
+ "type will be declared "
+ "typeless. Continue?"),
Localization.lang("Delete custom format") +
" '" + StringUtil.capitalizeFirst(name) + '\'', JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (reply != JOptionPane.YES_OPTION) {

boolean deleteCustomClicked = frame.getDialogService().showConfirmationDialogAndWait(Localization.lang("Delete custom format") +
" '" + StringUtil.capitalizeFirst(name) + '\'', Localization.lang("All entries of this "
+ "type will be declared "
+ "typeless. Continue?"),
Localization.lang("Delete custom format"), Localization.lang("Cancel"));

if (!deleteCustomClicked) {
return;
}
}
Expand Down
Loading