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

removed default constructor of FXDialogService #4847

Merged
merged 4 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 11 additions & 14 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import javafx.stage.Stage;

import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.FXDialogService;
import org.jabref.gui.GUIGlobals;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.dialogs.BackupUIManager;
Expand Down Expand Up @@ -43,14 +41,13 @@ 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);
mainFrame = new JabRefFrame(mainStage);

// passed file (we take the first one) should be focused
focusedFile = argsDatabases.stream()
Expand All @@ -60,7 +57,7 @@ public JabRefGUI(Stage mainStage, List<ParserResult> argsDatabases, boolean isBl
.orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED));

openWindow(mainStage);
new VersionWorker(Globals.BUILD_INFO.getVersion(), Globals.prefs.getVersionPreferences().getIgnoredVersion(), JabRefGUI.getMainFrame().getDialogService(), Globals.TASK_EXECUTOR)
new VersionWorker(Globals.BUILD_INFO.getVersion(), Globals.prefs.getVersionPreferences().getIgnoredVersion(), mainFrame.getDialogService(), Globals.TASK_EXECUTOR)
.checkForNewVersionAsync(false);
}

Expand All @@ -75,7 +72,7 @@ private void openWindow(Stage mainStage) {
GUIGlobals.init();
Copy link
Member

Choose a reason for hiding this comment

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

Some lines earlier you have JabRefGui.getMainFrame() instead of mainFrame

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it was incosistent, i used only mainFrame now in the whole class.


LOGGER.debug("Initializing frame");
JabRefGUI.mainFrame = new JabRefFrame(mainStage);
mainFrame.init();

// Add all bibDatabases databases to the frame:
boolean first = false;
Expand All @@ -99,7 +96,7 @@ private void openWindow(Stage mainStage) {
pr.getDatabase().clearSharedDatabaseID();

LOGGER.error("Connection error", e);
dialogService.showErrorDialogAndWait(
mainFrame.getDialogService().showErrorDialogAndWait(
Localization.lang("Connection error"),
Localization.lang("A local copy will be opened."),
e);
Expand All @@ -110,15 +107,15 @@ private void openWindow(Stage mainStage) {
// add them to the list
toOpenTab.add(pr);
} else {
JabRefGUI.getMainFrame().addParserResult(pr, first);
mainFrame.addParserResult(pr, first);
first = false;
}
}
}

// finally add things to the currently opened tab
for (ParserResult pr : toOpenTab) {
JabRefGUI.getMainFrame().addParserResult(pr, first);
mainFrame.addParserResult(pr, first);
first = false;
}

Expand Down Expand Up @@ -158,14 +155,14 @@ private void openWindow(Stage mainStage) {
String message = Localization.lang("Error opening file '%0'.", pr.getFile().get().getName()) + "\n"
+ pr.getErrorMessage();

dialogService.showErrorDialogAndWait(Localization.lang("Error opening file"), message);
mainFrame.getDialogService().showErrorDialogAndWait(Localization.lang("Error opening file"), message);

}

// Display warnings, if any
int tabNumber = 0;
for (ParserResult pr : bibDatabases) {
ParserResultWarningDialog.showParserResultWarningDialog(pr, JabRefGUI.getMainFrame(), tabNumber++);
ParserResultWarningDialog.showParserResultWarningDialog(pr, mainFrame, tabNumber++);
}

// After adding the databases, go through each and see if
Expand All @@ -177,9 +174,9 @@ private void openWindow(Stage mainStage) {
// This is because importToOpen might have been used, which adds to
// loadedDatabases, but not to getBasePanelCount()

for (int i = 0; (i < bibDatabases.size()) && (i < JabRefGUI.getMainFrame().getBasePanelCount()); i++) {
for (int i = 0; (i < bibDatabases.size()) && (i < mainFrame.getBasePanelCount()); i++) {
ParserResult pr = bibDatabases.get(i);
BasePanel panel = JabRefGUI.getMainFrame().getBasePanelAt(i);
BasePanel panel = mainFrame.getBasePanelAt(i);
OpenDatabaseAction.performPostOpenActions(panel, pr);
}

Expand Down Expand Up @@ -209,7 +206,7 @@ private void openLastEditedDatabases() {
}

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

ParserResult parsedDatabase = OpenDatabase.loadDatabase(fileName,
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.swing.undo.UndoManager;

import org.jabref.Globals;
import org.jabref.JabRefGUI;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
Expand All @@ -28,7 +29,7 @@ public class DefaultInjector implements PresenterFactory {
*/
private static Object createDependency(Class<?> clazz) {
if (clazz == DialogService.class) {
return new FXDialogService();
return JabRefGUI.getMainFrame().getDialogService();
} else if (clazz == TaskExecutor.class) {
return Globals.TASK_EXECUTOR;
} else if (clazz == PreferencesService.class) {
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/org/jabref/gui/FXDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@ public class FXDialogService implements DialogService {
private final Window mainWindow;
private final JFXSnackbar statusLine;

/**
* @deprecated try not to initialize a new dialog service but reuse the one constructed in {@link org.jabref.gui.JabRefFrame}.
*/
@Deprecated
public FXDialogService() {
this(null);
}

public FXDialogService(Window mainWindow) {
this.mainWindow = mainWindow;
this.statusLine = new JFXSnackbar();
}

public FXDialogService(Window mainWindow, Pane mainPane) {
this.mainWindow = mainWindow;
this.statusLine = new JFXSnackbar(mainPane);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ public class JabRefFrame extends BorderPane {
public JabRefFrame(Stage mainStage) {
this.mainStage = mainStage;
this.dialogService = new FXDialogService(mainStage, this);
init();
}

/**
Expand All @@ -204,7 +203,7 @@ private static void setEnabled(List<Object> list, boolean enabled) {
}
}

private void init() {
public void init() {
sidePaneManager = new SidePaneManager(Globals.prefs, this);
sidePane = sidePaneManager.getPane();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javafx.scene.Node;

import org.jabref.Globals;
import org.jabref.gui.FXDialogService;
import org.jabref.JabRefGUI;
import org.jabref.gui.PreviewPanel;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.undo.NamedCompound;
Expand All @@ -29,7 +29,7 @@ public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {

@Override
public Node description() {
PreviewPanel previewPanel = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), new FXDialogService(), ExternalFileTypes.getInstance());
PreviewPanel previewPanel = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), JabRefGUI.getMainFrame().getDialogService(), ExternalFileTypes.getInstance());
previewPanel.setEntry(diskEntry);
return previewPanel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javafx.scene.Node;

import org.jabref.Globals;
import org.jabref.gui.FXDialogService;
import org.jabref.JabRefGUI;
import org.jabref.gui.PreviewPanel;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.undo.NamedCompound;
Expand Down Expand Up @@ -46,7 +46,7 @@ public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {

@Override
public Node description() {
PreviewPanel previewPanel = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), new FXDialogService(), ExternalFileTypes.getInstance());
PreviewPanel previewPanel = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), JabRefGUI.getMainFrame().getDialogService(), ExternalFileTypes.getInstance());
previewPanel.setEntry(memEntry);
return previewPanel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import javax.swing.event.DocumentListener;

import org.jabref.Globals;
import org.jabref.JabRefGUI;
import org.jabref.gui.DialogService;
import org.jabref.gui.FXDialogService;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.FileDialogConfiguration;
Expand Down Expand Up @@ -62,7 +62,7 @@ public class ExternalFileTypeEntryEditor {

FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.withInitialDirectory(Paths.get(appDir)).build();
DialogService ds = new FXDialogService();
DialogService ds = JabRefGUI.getMainFrame().getDialogService();

Optional<Path> path = DefaultTaskExecutor
.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import javafx.scene.control.TabPane;
import javafx.stage.Stage;

import org.jabref.gui.FXDialogService;
import org.jabref.gui.DialogService;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import org.jabref.logic.importer.ImportFormatPreferences;
Expand Down Expand Up @@ -38,7 +38,7 @@ public class SourceTabTest {
public void onStart(Stage stage) {
area = new CodeArea();
area.appendText("some example\n text to go here\n across a couple of \n lines....");
sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), mock(ImportFormatPreferences.class), new DummyFileUpdateMonitor(), new FXDialogService());
sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), mock(ImportFormatPreferences.class), new DummyFileUpdateMonitor(), mock(DialogService.class));
pane = new TabPane(
new Tab("main area", area),
new Tab("other tab", new Label("some text")),
Expand Down