Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/maintable-beta' into fixdragan…
Browse files Browse the repository at this point in the history
…drop

* upstream/maintable-beta: (24 commits)
  Fixes #3796: Pretend that we have every translation for every key (#3820)
  adjust line wrapping on column
  replace open office install selection dialog with choice dialog Wrap error messages in fx executor (because abstract worker is swing thread)
  Convert swing error dialog in save db action to custom fx dialog
  Replace swing export dialog in ExportToClipboardAction with fx choices dlg
  run find fulltext dialog in fx thread
  fix cut, copy & paste action from toolbar
  Set resizable for custom dialog with dialog pane convert merge entries dlg to javafx and make action working again
  checkstyle argh!
  Update test order -> Execute checkstyle first (#3807)
  embed cleanup dialog in javafx
  Fix some non FX Thread issues Main drawback: Cleanup panel is in backgroung due to swing thread)
  Allow search field to be smaller
  Fix Codacy Unused Params, Fields (#3753)
  Dialogstojavafx (#3801)
  Remove unused import
  Add group coloring in maintable as replacement for marked entries (#3769)
  Enable travis build for maintable-beta (#3804)
  Remove setting of tooltip manually
  Change open last edited dialgo to javafx (#3800)
  ...

# Conflicts:
#	src/main/java/org/jabref/gui/maintable/MainTable.java
  • Loading branch information
Siedlerchr committed Mar 9, 2018
2 parents d8ee0e8 + 13f59f0 commit 744726a
Show file tree
Hide file tree
Showing 93 changed files with 1,447 additions and 1,632 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ env:
global:
- GRADLE_OPTS=-Dorg.gradle.daemon=false
matrix:
- TEST_SUITE=checkstyle
- TEST_SUITE=check OPTIONS=modernizer
- TEST_SUITE=fetcherTest
- TEST_SUITE=databaseTest
- TEST_SUITE=guiTest
- TEST_SUITE=checkstyle
- TEST_SUITE=codecov
- DEPENDENCY_UPDATES=check

Expand Down Expand Up @@ -60,6 +60,7 @@ after_failure:
branches:
only:
- master
- maintable-beta

# cache gradle dependencies
# https://docs.travis-ci.com/user/languages/java#Caching
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

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;
import org.jabref.gui.JabRefFrame;
Expand Down Expand Up @@ -50,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 @@ -158,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 Down Expand Up @@ -205,7 +208,7 @@ private void openLastEditedDatabases() {
}

if (BackupManager.checkForBackupFile(dbFile.toPath())) {
BackupUIManager.showRestoreBackupDialog(null, dbFile.toPath());
BackupUIManager.showRestoreBackupDialog(dialogService, dbFile.toPath());
}

ParserResult parsedDatabase = OpenDatabase.loadDatabase(fileName,
Expand Down Expand Up @@ -263,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
92 changes: 24 additions & 68 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.jabref.gui.journals.UnabbreviateAction;
import org.jabref.gui.maintable.MainTable;
import org.jabref.gui.maintable.MainTableDataModel;
import org.jabref.gui.mergeentries.MergeEntriesDialog;
import org.jabref.gui.mergeentries.MergeWithFetchedEntryAction;
import org.jabref.gui.specialfields.SpecialFieldDatabaseChangeListener;
import org.jabref.gui.specialfields.SpecialFieldValueViewModel;
Expand All @@ -84,7 +85,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 @@ -158,7 +158,7 @@ public class BasePanel extends StackPane implements ClipboardOwner {
// Keeps track of the string dialog if it is open.
private final Map<Actions, Object> actions = new HashMap<>();
private final SidePaneManager sidePaneManager;
private final PreviewPanel preview;
private PreviewPanel preview;
private final BasePanelPreferences preferences;
private final ExternalFileTypes externalFileTypes;

Expand Down Expand Up @@ -237,7 +237,7 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas

this.entryEditor = new EntryEditor(this, preferences.getEntryEditorPreferences(), Globals.getFileUpdateMonitor(), dialogService);

this.preview = new PreviewPanel(this, getBibDatabaseContext(), preferences.getKeyBindings(), preferences.getPreviewPreferences(), dialogService);
DefaultTaskExecutor.runInJavaFXThread(() -> this.preview = new PreviewPanel(this, getBibDatabaseContext(), preferences.getKeyBindings(), preferences.getPreviewPreferences(), dialogService));
DefaultTaskExecutor.runInJavaFXThread(() -> frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview));
}

Expand Down Expand Up @@ -349,8 +349,6 @@ private void setupActions() {

actions.put(Actions.CUT, (BaseAction) mainTable::cut);

//when you modify this action be sure to adjust Actions.CUT,
//they are the same except of the Localization, delete confirmation and Actions.COPY call
actions.put(Actions.DELETE, (BaseAction) () -> delete(false));

// The action for pasting entries or cell contents.
Expand Down Expand Up @@ -422,15 +420,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 @@ -467,7 +466,7 @@ public void update() {
// The action for cleaning up entry.
actions.put(Actions.CLEANUP, cleanUpAction);

//actions.put(Actions.MERGE_ENTRIES, (BaseAction) () -> new MergeEntriesDialog(BasePanel.this));
actions.put(Actions.MERGE_ENTRIES, (BaseAction) () -> new MergeEntriesDialog(BasePanel.this, dialogService));

actions.put(Actions.SEARCH, (BaseAction) frame.getGlobalSearchBar()::focus);
actions.put(Actions.GLOBAL_SEARCH, (BaseAction) frame.getGlobalSearchBar()::performGlobalSearch);
Expand Down Expand Up @@ -527,7 +526,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 @@ -560,47 +559,6 @@ public void update() {
(BaseAction) () -> JabRefExecutorService.INSTANCE.execute(new DuplicateSearch(BasePanel.this)));
*/

// TODO
//actions.put(Actions.MARK_ENTRIES, new MarkEntriesAction(frame, 0));

actions.put(Actions.UNMARK_ENTRIES, (BaseAction) () -> {
try {
List<BibEntry> bes = mainTable.getSelectedEntries();
if (bes.isEmpty()) {
output(Localization.lang("This operation requires one or more entries to be selected."));
return;
}
NamedCompound ce = new NamedCompound(Localization.lang("Unmark entries"));
for (BibEntry be : bes) {
EntryMarker.unmarkEntry(be, false, bibDatabaseContext.getDatabase(), ce);
}
ce.end();
getUndoManager().addEdit(ce);
markBaseChanged();
String outputStr;
if (bes.size() == 1) {
outputStr = Localization.lang("Unmarked selected entry");
} else {
outputStr = Localization.lang("Unmarked all %0 selected entries", Integer.toString(bes.size()));
}
output(outputStr);
} catch (Throwable ex) {
LOGGER.warn("Could not unmark", ex);
}
});

actions.put(Actions.UNMARK_ALL, (BaseAction) () -> {
NamedCompound ce = new NamedCompound(Localization.lang("Unmark all"));

for (BibEntry be : bibDatabaseContext.getDatabase().getEntries()) {
EntryMarker.unmarkEntry(be, false, bibDatabaseContext.getDatabase(), ce);
}
ce.end();
getUndoManager().addEdit(ce);
markBaseChanged();
output(Localization.lang("Unmarked all entries"));
});

// Note that we can't put the number of entries that have been reverted into the undoText as the concrete number cannot be injected
actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(),
new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager).getSpecialFieldAction(
Expand Down Expand Up @@ -659,7 +617,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 @@ -968,6 +926,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 Expand Up @@ -1562,22 +1521,21 @@ private void changeType(List<BibEntry> entries, String newType) {

public boolean showDeleteConfirmationDialog(int numberOfEntries) {
if (Globals.prefs.getBoolean(JabRefPreferences.CONFIRM_DELETE)) {
String msg;
msg = Localization.lang("Really delete the selected entry?");
String title = Localization.lang("Delete entry");
String message = Localization.lang("Really delete the selected entry?");
String okButton = Localization.lang("Delete entry");
String cancelButton = Localization.lang("Keep entry");
if (numberOfEntries > 1) {
msg = Localization.lang("Really delete the %0 selected entries?", Integer.toString(numberOfEntries));
title = Localization.lang("Delete multiple entries");
message = Localization.lang("Really delete the %0 selected entries?", Integer.toString(numberOfEntries));
okButton = Localization.lang("Delete entries");
cancelButton = Localization.lang("Keep entries");
}

CheckBoxMessage cb = new CheckBoxMessage(msg, Localization.lang("Disable this confirmation dialog"), false);

int answer = JOptionPane.showConfirmDialog(null, cb, title, JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (cb.isSelected()) {
Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, false);
}
return answer == JOptionPane.YES_OPTION;
return dialogService.showConfirmationDialogWithOptOutAndWait(title, message,
okButton, cancelButton,
Localization.lang("Disable this confirmation dialog"),
optOut -> Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, !optOut));
} else {
return true;
}
Expand Down Expand Up @@ -1963,8 +1921,6 @@ private class RedoAction implements BaseAction {
@Override
public void action() {
try {

JComponent focused = Globals.getFocusListener().getFocused();
getUndoManager().redo();
markBaseChanged();
frame.output(Localization.lang("Redo"));
Expand Down
44 changes: 41 additions & 3 deletions src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
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;

import javafx.concurrent.Task;
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 @@ -21,6 +25,14 @@
*/
public interface DialogService {

/**
* This will create and display new {@link ChoiceDialog} of type T with a default choice (can be null) 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 @@ -92,7 +104,7 @@ default void showErrorDialogAndWait(Exception exception) {
* Create and display a new confirmation dialog.
* It will include a blue question icon on the left and
* a OK (with given label) and Cancel button. To create a confirmation dialog with custom
* buttons see also {@link #showCustomButtonDialogAndWait(Alert.AlertType, String, String, ButtonType...)}
* buttons see also {@link #showCustomButtonDialogAndWait(Alert.AlertType, String, String, ButtonType...)}.
*
* @return true if the use clicked "OK" otherwise false
*/
Expand All @@ -102,12 +114,37 @@ default void showErrorDialogAndWait(Exception exception) {
* Create and display a new confirmation dialog.
* It will include a blue question icon on the left and
* a OK (with given label) and Cancel (also with given label) button. To create a confirmation dialog with custom
* buttons see also {@link #showCustomButtonDialogAndWait(Alert.AlertType, String, String, ButtonType...)}
* buttons see also {@link #showCustomButtonDialogAndWait(Alert.AlertType, String, String, ButtonType...)}.
*
* @return true if the use clicked "OK" otherwise false
*/
boolean showConfirmationDialogAndWait(String title, String content, String okButtonLabel, String cancelButtonLabel);

/**
* Create and display a new confirmation dialog.
* It will include a blue question icon on the left and
* a YES (with given label) and Cancel (also with given label) button. To create a confirmation dialog with custom
* buttons see also {@link #showCustomButtonDialogAndWait(Alert.AlertType, String, String, ButtonType...)}.
* Moreover, the dialog contains a opt-out checkbox with the given text to support "Do not ask again"-behaviour.
*
* @return true if the use clicked "YES" otherwise false
*/
boolean showConfirmationDialogWithOptOutAndWait(String title, String content,
String optOutMessage, Consumer<Boolean> optOutAction);

/**
* Create and display a new confirmation dialog.
* It will include a blue question icon on the left and
* a YES (with given label) and Cancel (also with given label) button. To create a confirmation dialog with custom
* buttons see also {@link #showCustomButtonDialogAndWait(Alert.AlertType, String, String, ButtonType...)}.
* Moreover, the dialog contains a opt-out checkbox with the given text to support "Do not ask again"-behaviour.
*
* @return true if the use clicked "YES" otherwise false
*/
boolean showConfirmationDialogWithOptOutAndWait(String title, String content,
String okButtonLabel, String cancelButtonLabel,
String optOutMessage, Consumer<Boolean> optOutAction);

/**
* This will create and display a new dialog of the specified
* {@link Alert.AlertType} but with user defined buttons as optional
Expand All @@ -116,7 +153,7 @@ default void showErrorDialogAndWait(Exception exception) {
* @return Optional with the pressed Button as ButtonType
*/
Optional<ButtonType> showCustomButtonDialogAndWait(Alert.AlertType type, String title, String content,
ButtonType... buttonTypes);
ButtonType... buttonTypes);

/**
* This will create and display a new dialog showing a custom {@link DialogPane}
Expand Down Expand Up @@ -198,4 +235,5 @@ Optional<ButtonType> showCustomButtonDialogAndWait(Alert.AlertType type, String
* @return false if the user opts to cancel printing
*/
boolean showPrintDialog(PrinterJob job);

}
Loading

0 comments on commit 744726a

Please sign in to comment.