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 4 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
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));
Copy link
Member

Choose a reason for hiding this comment

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

could you please pass the DialogService directly, instead of the frame (makes the dependency clearer).


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, this));
Copy link
Member

Choose a reason for hiding this comment

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

dito

}

/**
Expand Down
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
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, entryTypes, bibDatabaseMode);
Copy link
Member

Choose a reason for hiding this comment

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

here also

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
35 changes: 21 additions & 14 deletions src/main/java/org/jabref/gui/customentrytypes/EntryTypeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import java.util.Optional;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.jabref.Globals;
import org.jabref.gui.JabRefFrame;
import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.EntryTypes;
Expand All @@ -29,11 +29,14 @@ public class EntryTypeList extends FieldSetComponent implements ListSelectionLis

private final JButton def = new JButton(Localization.lang("Default"));
private final BibDatabaseMode mode;
private final JabRefFrame frame;

/** Creates a new instance of EntryTypeList */
public EntryTypeList(List<String> fields, BibDatabaseMode mode) {
super(Localization.lang("Entry types"), fields, false, true);
/** Creates a new instance of EntryTypeList
* @param frame */
public EntryTypeList(JabRefFrame frame, List<String> fields, BibDatabaseMode mode) {
super(Localization.lang("Entry types"), fields, fields, false, true);
this.mode = mode;
this.frame = frame;

con.gridx = 0;
con.gridy = 2;
Expand Down Expand Up @@ -61,15 +64,17 @@ protected void addField(String str) {
Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
if (!testString.equals(s) || (s.indexOf('&') >= 0)) {
// Report error and exit.
JOptionPane.showMessageDialog(this, Localization.lang("Entry type names are not allowed to contain white space or the following "
+ "characters") + ": # { } ~ , ^ &",
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);

frame.getDialogService().showErrorDialogAndWait(Localization.lang("Error"),
Localization.lang("Entry type names are not allowed to contain white space or the following "
+ "characters") + ": # { } ~ , ^ &");

return;
}
else if ("comment".equalsIgnoreCase(s)) {
} else if ("comment".equalsIgnoreCase(s)) {
// Report error and exit.
JOptionPane.showMessageDialog(this, Localization.lang("The name 'comment' cannot be used as an entry type name."),
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
frame.getDialogService().showErrorDialogAndWait(Localization.lang("Error"),
Localization.lang("The name 'comment' cannot be used as an entry type name."));

return;
}
addFieldUncritically(s);
Expand All @@ -92,9 +97,11 @@ protected void removeSelected() {
if (type.isPresent() && (type.get() instanceof CustomEntryType)) {
listModel.removeElementAt(selected[selected.length - 1 - i]);
} else {
// This shouldn't happen, since the Remove button should be disabled.
JOptionPane.showMessageDialog(null, Localization.lang("This entry type cannot be removed."),
Localization.lang("Remove entry type"), JOptionPane.ERROR_MESSAGE);
// This shouldn't happen, since the Remove button should be disabled.

frame.getDialogService().showErrorDialogAndWait(Localization.lang("Remove entry type"),
Localization.lang("This entry type cannot be removed."));

}
}
}
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/org/jabref/gui/exporter/ExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ public void execute() {
Globals.exportFactory = ExporterFactory.create(Globals.prefs, Globals.journalAbbreviationLoader);
FileDialogConfiguration fileDialogConfiguration = createExportFileChooser(Globals.exportFactory, Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY));
DialogService dialogService = frame.getDialogService();
DefaultTaskExecutor.runInJavaFXThread(() ->
dialogService.showFileSaveDialog(fileDialogConfiguration)
.ifPresent(path -> export(path, fileDialogConfiguration.getSelectedExtensionFilter(), Globals.exportFactory.getExporters())));
DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.showFileSaveDialog(fileDialogConfiguration)
.ifPresent(path -> export(path, fileDialogConfiguration.getSelectedExtensionFilter(), Globals.exportFactory.getExporters())));
}

private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilter, List<Exporter> exporters) {
Expand Down Expand Up @@ -82,8 +81,9 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt
// Set the global variable for this database's file directory before exporting,
// so formatters can resolve linked files correctly.
// (This is an ugly hack!)
Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext()
.getFileDirectories(Globals.prefs.getFileDirectoryPreferences());
Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel()
.getBibDatabaseContext()
.getFileDirectories(Globals.prefs.getFileDirectoryPreferences());

// Make sure we remember which filter was used, to set
// the default for next time:
Expand All @@ -100,8 +100,11 @@ public void run() {
try {
format.export(frame.getCurrentBasePanel().getBibDatabaseContext(),
file,
frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getEncoding()
.orElse(Globals.prefs.getDefaultEncoding()),
frame.getCurrentBasePanel()
.getBibDatabaseContext()
.getMetaData()
.getEncoding()
.orElse(Globals.prefs.getDefaultEncoding()),
finEntries);
} catch (Exception ex) {
LOGGER.warn("Problem exporting", ex);
Expand All @@ -123,9 +126,8 @@ public void update() {
else {
frame.output(Localization.lang("Could not save file.") + " - " + errorMessage);
// Need to warn the user that saving failed!
JOptionPane.showMessageDialog(null,
Localization.lang("Could not save file.") + "\n" + errorMessage,
Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
frame.getDialogService().showErrorDialogAndWait(Localization.lang("Save library"), Localization.lang("Could not save file.") + "\n" + errorMessage);

}
}
};
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public void run() {

// Save the database
success = saveDatabase(panel.getBibDatabaseContext().getDatabaseFile().get(), false,
panel.getBibDatabaseContext().getMetaData().getEncoding()
panel.getBibDatabaseContext()
Copy link
Member

Choose a reason for hiding this comment

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

Do these restylings happen automatically? If yes, could eclipse be configured differently? Sometimes they are good, sometimes they feel a bit over aggressive (like here, the two-lines solution was fine in my opinion)

.getMetaData()
.getEncoding()
.orElse(Globals.prefs.getDefaultEncoding()));

panel.updateTimeStamp();
Expand Down Expand Up @@ -288,7 +290,8 @@ public void saveAs() throws Exception {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.addExtensionFilter(FileType.BIBTEX_DB)
.withDefaultExtension(FileType.BIBTEX_DB)
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))
.build();
DialogService dialogService = frame.getDialogService();
Optional<Path> path = dialogService.showFileSaveDialog(fileDialogConfiguration);
if (path.isPresent()) {
Expand Down Expand Up @@ -428,10 +431,10 @@ private boolean checkExternalModification() {
return true;
} else { // User indicated to store anyway.
if (panel.getBibDatabaseContext().getMetaData().isProtected()) {
JOptionPane.showMessageDialog(null,
Localization
.lang("Library is protected. Cannot save until external changes have been reviewed."),
Localization.lang("Protected library"), JOptionPane.ERROR_MESSAGE);

frame.getDialogService().showErrorDialogAndWait(Localization.lang("Protected library"),
Localization.lang("Library is protected. Cannot save until external changes have been reviewed."));

canceled = true;
} else {
panel.markExternalChangesAsResolved();
Expand Down
Loading