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
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,6 @@ public void actionPerformed(ActionEvent event) {
// is indicated by the entry's group hit status:
if (entry.isGroupHit()) {

// return dialogService.showConfirmationDialogWithOptOutAndWait(title, message,
//okButton, cancelButton,
//Localization.lang("Disable this confirmation dialog"),
// optOut -> Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, !optOut));

boolean continuePressed = frame.getDialogService().showConfirmationDialogWithOptOutAndWait(Localization.lang("Duplicates found"),
Localization.lang("There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"),
Localization.lang("Continue"),
Expand Down Expand Up @@ -1206,10 +1201,8 @@ public void actionPerformed(ActionEvent event) {
}
BibEntry entry = selectionModel.getSelected().get(0);


Optional<String> result = frame.getDialogService().showInputDialogAndWait(Localization.lang("Enter URL"), Localization.lang("Enter URL"));


entries.getReadWriteLock().writeLock().lock();
try {
if (result.isPresent()) {
Expand Down Expand Up @@ -1243,7 +1236,6 @@ public void actionPerformed(ActionEvent actionEvent) {
entry = selectionModel.getSelected().get(0);
if (!entry.getCiteKeyOptional().isPresent()) {


boolean generateKeyPressed = frame.getDialogService().showConfirmationDialogAndWait(Localization.lang("Download file"),
Localization.lang("This entry has no BibTeX key. Generate key now?"),
Localization.lang("Generate key"),
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/jabref/gui/preftabs/AppearancePrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import org.jabref.gui.DialogService;
import org.jabref.gui.GUIGlobals;
import org.jabref.gui.JabRefFrame;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.preferences.JabRefPreferences;
Expand Down Expand Up @@ -56,7 +56,7 @@ class AppearancePrefsTab extends JPanel implements PrefsTab {
private final JCheckBox customLAF;
private final JCheckBox fxFontTweaksLAF;

private final JabRefFrame frame;
private final DialogService dialogService;

static class LookAndFeel {

Expand All @@ -70,8 +70,8 @@ public static Set<String> getAvailableLookAndFeels() {
*
* @param prefs a <code>JabRefPreferences</code> value
*/
public AppearancePrefsTab(JabRefFrame frame, JabRefPreferences prefs) {
this.frame = frame;
public AppearancePrefsTab(DialogService dialogService, JabRefPreferences prefs) {
this.dialogService = dialogService;
this.prefs = prefs;
setLayout(new BorderLayout());

Expand Down Expand Up @@ -286,7 +286,7 @@ public void storeSettings() {
}

if (isRestartRequired) {
frame.getDialogService().showWarningDialogAndWait(Localization.lang("Settings"),
dialogService.showWarningDialogAndWait(Localization.lang("Settings"),
Localization.lang("Some appearance settings you changed require to restart JabRef to come into effect."));
}

Expand All @@ -303,7 +303,7 @@ private boolean validateIntegerField(String fieldName, String fieldValue, String
Integer.parseInt(fieldValue);
} catch (NumberFormatException ex) {

frame.getDialogService().showErrorDialogAndWait(errorTitle, Localization.lang("You must enter an integer value in the text field for") + " '" + fieldName + "'");
dialogService.showErrorDialogAndWait(errorTitle, Localization.lang("You must enter an integer value in the text field for") + " '" + fieldName + "'");
return false;
}
return true;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/jabref/gui/preftabs/NetworkTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import org.jabref.gui.JabRefFrame;
import org.jabref.gui.DialogService;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.ProxyPreferences;
import org.jabref.logic.net.ProxyRegisterer;
Expand All @@ -30,10 +30,10 @@ public class NetworkTab extends JPanel implements PrefsTab {
private final JPasswordField passwordTextField;
private final JabRefPreferences preferences;
private ProxyPreferences oldProxyPreferences;
private final JabRefFrame frame;
private final DialogService dialogService;

public NetworkTab(JabRefFrame frame, JabRefPreferences preferences) {
this.frame = frame;
public NetworkTab(DialogService dialogService, JabRefPreferences preferences) {
this.dialogService = dialogService;
this.preferences = preferences;

setLayout(new BorderLayout());
Expand Down Expand Up @@ -161,10 +161,10 @@ public boolean validateSettings() {
if (!validSetting) {
if (validAuthenticationSetting) {

frame.getDialogService().showErrorDialogAndWait(Localization.lang("Invalid setting"),
dialogService.showErrorDialogAndWait(Localization.lang("Invalid setting"),
Localization.lang("Please specify both hostname and port"));
} else {
frame.getDialogService().showErrorDialogAndWait(Localization.lang("Invalid setting"),
dialogService.showErrorDialogAndWait(Localization.lang("Invalid setting"),
Localization.lang("Please specify both username and password"));

}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public PreferencesDialog(JabRefFrame parent) {
tabs.add(new ExportSortingPrefsTab(prefs));
tabs.add(new NameFormatterTab(prefs));
tabs.add(new XmpPrefsTab(prefs));
tabs.add(new NetworkTab(frame, prefs));
tabs.add(new NetworkTab(frame.getDialogService(), prefs));
tabs.add(new AdvancedTab(frame.getDialogService(), prefs));
tabs.add(new AppearancePrefsTab(frame, prefs));
tabs.add(new AppearancePrefsTab(frame.getDialogService(), prefs));

// add all tabs
tabs.forEach(tab -> main.add((Component) tab, tab.getTabName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String getTooltip() {
}

@Override
public void pushEntries(BibDatabase database, List<BibEntry> entries, String keyString, MetaData metaData) {
public void pushEntries(BibDatabase database, List<BibEntry> entries, String keyString, MetaData metaData, DialogService dialogServie) {

couldNotConnect = false;
couldNotCall = false;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/push/PushToApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.swing.JPanel;

import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.JabRefIcon;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -48,7 +49,7 @@ public interface PushToApplication {
* @param entries
* @param metaData
*/
void pushEntries(BibDatabase database, List<BibEntry> entries, String keyString, MetaData metaData);
void pushEntries(BibDatabase database, List<BibEntry> entries, String keyString, MetaData metaData, DialogService dialogService);

/**
* Reporting etc., this method is called on the event dispatch thread after pushEntries() returns.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void actionPerformed(ActionEvent e) {
@Override
public void run() {
// Do the operation:
operation.pushEntries(panel.getDatabase(), entries, getKeyString(entries), panel.getBibDatabaseContext().getMetaData());
operation.pushEntries(panel.getDatabase(), entries, getKeyString(entries), panel.getBibDatabaseContext().getMetaData(), frame.getDialogService());

// Call the operationCompleted() method on the event dispatch thread:
SwingUtilities.invokeLater(() -> operation.operationCompleted(panel));
Expand Down
34 changes: 19 additions & 15 deletions src/main/java/org/jabref/gui/push/PushToEmacs.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import java.io.InputStream;
import java.util.List;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.jabref.Globals;
import org.jabref.JabRefExecutorService;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.IconTheme;
import org.jabref.gui.JabRefIcon;
import org.jabref.logic.l10n.Localization;
Expand All @@ -29,6 +29,8 @@ public class PushToEmacs extends AbstractPushToApplication implements PushToAppl

private final JTextField additionalParams = new JTextField(30);

private DialogService dialogService;

@Override
public String getApplicationName() {
return "Emacs";
Expand Down Expand Up @@ -61,11 +63,12 @@ protected void initSettingsPanel() {
}

@Override
public void pushEntries(BibDatabase database, List<BibEntry> entries, String keys, MetaData metaData) {
public void pushEntries(BibDatabase database, List<BibEntry> entries, String keys, MetaData metaData, DialogService dialogService) {
Copy link
Member

Choose a reason for hiding this comment

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

The dialogService makes more sense as a constructor argument, I think. Probably push it even to AbstractPushToApplication

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 thought so, too, but the concrete subclass of PushToEntries (operation) is just passed as constructur argument as a dependency, so it is not possible

Copy link
Member

@tobiasdiez tobiasdiez Mar 4, 2018

Choose a reason for hiding this comment

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

Sorry, I don't understand what you mean. The push to application action of course only gets the PushToApplicaiton instance without knowing which concrete subclass it is. But this is not a problem as far as I can see since upon initialization each subclass would get a DialogService as a constructor argument.

Copy link
Member Author

@Siedlerchr Siedlerchr Mar 4, 2018

Choose a reason for hiding this comment

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

The problem is: PushToApplicationAction already gets an instance of the concrete push operation and only calls pushEntries.
And these push-Operations are defined and instantiated here. I can't just pass the DialogService as Constructor arg.
The only thing I could do is to create an additional setter for the Dialog Service

applications = new ArrayList<>();
applications.add(new PushToEmacs());
applications.add(new PushToLyx());
applications.add(new PushToTexmaker());

Copy link
Member

Choose a reason for hiding this comment

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

Why can't you pass the dialog service as a constructor argument to PushToApplications? It seems the only place where this class is initiated is

pushApplications = new PushToApplications();

where you have a dialog service at your disposal.

Copy link
Member Author

Choose a reason for hiding this comment

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

done


couldNotConnect = false;
couldNotCall = false;
notDefined = false;
this.dialogService = dialogService;

initParameters();
commandPath = Globals.prefs.get(commandPathPreferenceKey);
Expand All @@ -91,12 +94,12 @@ public void pushEntries(BibDatabase database, List<BibEntry> entries, String key
// java string: "(insert \\\"\\\\cite{Blah2001}\\\")";
// so cmd receives: (insert \"\\cite{Blah2001}\")
// so emacs receives: (insert "\cite{Blah2001}")
prefix.concat("\\\"\\" + getCiteCommand().replaceAll("\\\\", "\\\\\\\\") + "{" + keys + "}\\\"").concat(suffix) :
// Linux gnuclient/emacslient escaping:
// java string: "(insert \"\\\\cite{Blah2001}\")"
// so sh receives: (insert "\\cite{Blah2001}")
// so emacs receives: (insert "\cite{Blah2001}")
prefix.concat("\"" + getCiteCommand().replaceAll("\\\\", "\\\\\\\\") + "{" + keys + "}\"").concat(suffix);
prefix.concat("\\\"\\" + getCiteCommand().replaceAll("\\\\", "\\\\\\\\") + "{" + keys + "}\\\"").concat(suffix) :
// Linux gnuclient/emacslient escaping:
// java string: "(insert \"\\\\cite{Blah2001}\")"
// so sh receives: (insert "\\cite{Blah2001}")
// so emacs receives: (insert "\cite{Blah2001}")
prefix.concat("\"" + getCiteCommand().replaceAll("\\\\", "\\\\\\\\") + "{" + keys + "}\"").concat(suffix);

final Process p = Runtime.getRuntime().exec(com);

Expand Down Expand Up @@ -129,16 +132,17 @@ public void pushEntries(BibDatabase database, List<BibEntry> entries, String key
@Override
public void operationCompleted(BasePanel panel) {
if (couldNotConnect) {
JOptionPane.showMessageDialog(null, "<HTML>" +

dialogService.showErrorDialogAndWait(Localization.lang("Error pushing entries"),
Localization.lang("Could not connect to a running gnuserv process. Make sure that "
+ "Emacs or XEmacs is running,<BR>and that the server has been started "
+ "(by running the command 'server-start'/'gnuserv-start').") + "</HTML>",
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
+ "Emacs or XEmacs is running, and that the server has been started "
+ "(by running the command 'server-start'/'gnuserv-start')."));

} else if (couldNotCall) {
JOptionPane.showMessageDialog(null,
dialogService.showErrorDialogAndWait(Localization.lang("Error pushing entries"),
Localization.lang("Could not run the gnuclient/emacsclient program. Make sure you have "
+ "the emacsclient/gnuclient program installed and available in the PATH."),
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
+ "the emacsclient/gnuclient program installed and available in the PATH."));

} else {
super.operationCompleted(panel);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/push/PushToLyx.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jabref.Globals;
import org.jabref.JabRefExecutorService;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.IconTheme;
import org.jabref.gui.JabRefIcon;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected void initSettingsPanel() {

@Override
public void pushEntries(BibDatabase database, final List<BibEntry> entries, final String keyString,
MetaData metaData) {
MetaData metaData, DialogService dialogService) {

couldNotConnect = false;
couldNotCall = false;
Expand Down
30 changes: 14 additions & 16 deletions src/main/java/org/jabref/gui/push/PushToVim.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import java.io.InputStream;
import java.util.List;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.jabref.Globals;
import org.jabref.JabRefExecutorService;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.IconTheme;
import org.jabref.gui.JabRefIcon;
import org.jabref.logic.l10n.Localization;
Expand All @@ -27,6 +27,7 @@ public class PushToVim extends AbstractPushToApplication implements PushToApplic
private static final Logger LOGGER = LoggerFactory.getLogger(PushToVim.class);

private final JTextField vimServer = new JTextField(30);
private DialogService dialogService;

@Override
public String getApplicationName() {
Expand Down Expand Up @@ -60,11 +61,12 @@ protected void initSettingsPanel() {
}

@Override
public void pushEntries(BibDatabase database, List<BibEntry> entries, String keys, MetaData metaData) {
public void pushEntries(BibDatabase database, List<BibEntry> entries, String keys, MetaData metaData, DialogService dialogService) {

couldNotConnect = false;
couldNotCall = false;
notDefined = false;
dialogService = dialogService;

initParameters();
commandPath = Globals.prefs.get(commandPathPreferenceKey);
Expand All @@ -76,9 +78,9 @@ public void pushEntries(BibDatabase database, List<BibEntry> entries, String key

try {
String[] com = new String[] {commandPath, "--servername",
Globals.prefs.get(JabRefPreferences.VIM_SERVER), "--remote-send",
"<C-\\><C-N>a" + getCiteCommand() +
"{" + keys + "}"};
Globals.prefs.get(JabRefPreferences.VIM_SERVER), "--remote-send",
"<C-\\><C-N>a" + getCiteCommand() +
"{" + keys + "}"};

final Process p = Runtime.getRuntime().exec(com);

Expand Down Expand Up @@ -112,18 +114,14 @@ public void pushEntries(BibDatabase database, List<BibEntry> entries, String key
@Override
public void operationCompleted(BasePanel panel) {
if (couldNotConnect) {
JOptionPane.showMessageDialog(
null,
"<HTML>" +
Localization.lang("Could not connect to Vim server. Make sure that "
+ "Vim is running<BR>with correct server name.")
+ "</HTML>",
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);

dialogService.showErrorDialogAndWait(Localization.lang("Error pushing entries"),
Localization.lang("Could not connect to Vim server. Make sure that Vim is running with correct server name."));

} else if (couldNotCall) {
JOptionPane.showMessageDialog(
null,
Localization.lang("Could not run the 'vim' program."),
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
dialogService.showErrorDialogAndWait(Localization.lang("Error pushing entries"),
Localization.lang("Could not run the 'vim' program."));

} else {
super.operationCompleted(panel);
}
Expand Down