Skip to content

Commit

Permalink
NPE-fix for Preferences/Ext-Prog/Settings for X/Browse (#4983)
Browse files Browse the repository at this point in the history
* Added handover dialogservice

* Undone previous

* Refactor Constructors, handing over dialogService

* Reword Identifier

* Reformat for codestyle

* Refactor Constructors

* Delete superfluous import for checkstyle

* Reformat whitespace

* Refactor Constructors

* Refactor Cleanup
  • Loading branch information
calixtus authored and tobiasdiez committed May 21, 2019
1 parent df2a178 commit 9322cde
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/gui/preferences/ExternalTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.jabref.gui.push.PushToApplication;
import org.jabref.gui.push.PushToApplicationSettings;
import org.jabref.gui.push.PushToApplicationSettingsDialog;
import org.jabref.gui.push.PushToApplicationsManager;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
Expand All @@ -28,6 +27,7 @@

class ExternalTab implements PrefsTab {

private final JabRefFrame frame;
private final JabRefPreferences prefs;
private final TextField emailSubject;
private final TextField citeCommand;
Expand All @@ -54,6 +54,7 @@ class ExternalTab implements PrefsTab {

public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPreferences prefs) {
this.prefs = prefs;
this.frame = frame;
dialogService = frame.getDialogService();
builder.setVgap(7);

Expand Down Expand Up @@ -197,7 +198,7 @@ public Node getBuilder() {
}

private void addSettingsButton(final PushToApplication application, GridPane panel, int index) {
PushToApplicationSettings settings = PushToApplicationsManager.getSettings(application);
PushToApplicationSettings settings = frame.getPushApplications().getSettings(application);
Button button = new Button(Localization.lang("Settings for %0", application.getApplicationName()));
button.setPrefSize(150, 20);
button.setOnAction(e -> PushToApplicationSettingsDialog.showSettingsDialog(dialogService, settings, index));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public class PushToApplicationSettings {
protected AbstractPushToApplication application;
private DialogService dialogService;

public PushToApplicationSettings(DialogService dialogService) {
this.dialogService = dialogService;
}

public GridPane getJFXSettingPane(int n) {
switch (n) {
case 0:
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/jabref/gui/push/PushToApplicationsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public class PushToApplicationsManager {

private final List<PushToApplication> applications;

private final DialogService dialogService;

public PushToApplicationsManager(DialogService dialogService) {
this.dialogService = dialogService;
// Set up the current available choices:
applications = new ArrayList<>();
applications.add(new PushToEmacs(dialogService));
Expand All @@ -25,15 +28,15 @@ public List<PushToApplication> getApplications() {
return applications;
}

public static PushToApplicationSettings getSettings(PushToApplication application) {
public PushToApplicationSettings getSettings(PushToApplication application) {
if (application instanceof PushToEmacs) {
return new PushToEmacsSettings();
return new PushToEmacsSettings(dialogService);
} else if (application instanceof PushToLyx) {
return new PushToLyxSettings();
return new PushToLyxSettings(dialogService);
} else if (application instanceof PushToVim) {
return new PushToVimSettings();
return new PushToVimSettings(dialogService);
} else {
return new PushToApplicationSettings();
return new PushToApplicationSettings(dialogService);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToEmacsSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import javafx.scene.control.TextField;

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;

public class PushToEmacsSettings extends PushToApplicationSettings {

private final TextField additionalParams = new TextField();

public PushToEmacsSettings (DialogService dialogService) { super(dialogService); }

@Override
public void storeSettings() {
super.storeSettings();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToLyxSettings.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.jabref.gui.push;

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;

public class PushToLyxSettings extends PushToApplicationSettings {

public PushToLyxSettings (DialogService dialogService) { super(dialogService); }

@Override
protected void initJFXSettingsPanel() {
super.initJFXSettingsPanel();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToVimSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import javafx.scene.control.TextField;

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;

public class PushToVimSettings extends PushToApplicationSettings {

private final TextField vimServer = new TextField();

public PushToVimSettings (DialogService dialogService) { super(dialogService); }

@Override
public void storeSettings() {
super.storeSettings();
Expand Down

0 comments on commit 9322cde

Please sign in to comment.