From 38e162df42fddc6b317ea550d538591030b945a9 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 5 Apr 2019 19:07:53 +0200 Subject: [PATCH] removed default constructor of FXDialogService (#4847) * removed default constructor of FXDialogService * Revert "removed default constructor of FXDialogService" This reverts commit 4c964ca602a9e4b9081e8273e03277c068da2c4c. * regained injection and splitted jabrefframe creation and init to hav dialogservice ready * replaced JabRegGUI.mainFrame with mainFrame --- src/main/java/org/jabref/JabRefGUI.java | 25 ++++++++----------- .../java/org/jabref/gui/DefaultInjector.java | 3 ++- .../java/org/jabref/gui/FXDialogService.java | 13 ---------- src/main/java/org/jabref/gui/JabRefFrame.java | 3 +-- .../gui/collab/EntryAddChangeViewModel.java | 4 +-- .../collab/EntryDeleteChangeViewModel.java | 4 +-- .../ExternalFileTypeEntryEditor.java | 4 +-- .../jabref/gui/entryeditor/SourceTabTest.java | 4 +-- 8 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index 203dcf03386..66fe3694ffa 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -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; @@ -43,14 +41,13 @@ public class JabRefGUI { private final boolean isBlank; private final List failed = new ArrayList<>(); private final List toOpenTab = new ArrayList<>(); - private final DialogService dialogService; private final String focusedFile; public JabRefGUI(Stage mainStage, List 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() @@ -60,7 +57,7 @@ public JabRefGUI(Stage mainStage, List 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); } @@ -75,7 +72,7 @@ private void openWindow(Stage mainStage) { GUIGlobals.init(); LOGGER.debug("Initializing frame"); - JabRefGUI.mainFrame = new JabRefFrame(mainStage); + mainFrame.init(); // Add all bibDatabases databases to the frame: boolean first = false; @@ -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); @@ -110,7 +107,7 @@ 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; } } @@ -118,7 +115,7 @@ private void openWindow(Stage mainStage) { // finally add things to the currently opened tab for (ParserResult pr : toOpenTab) { - JabRefGUI.getMainFrame().addParserResult(pr, first); + mainFrame.addParserResult(pr, first); first = false; } @@ -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 @@ -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); } @@ -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, diff --git a/src/main/java/org/jabref/gui/DefaultInjector.java b/src/main/java/org/jabref/gui/DefaultInjector.java index ee7c8c05839..ed9963b55c5 100644 --- a/src/main/java/org/jabref/gui/DefaultInjector.java +++ b/src/main/java/org/jabref/gui/DefaultInjector.java @@ -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; @@ -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) { diff --git a/src/main/java/org/jabref/gui/FXDialogService.java b/src/main/java/org/jabref/gui/FXDialogService.java index 2fe537a30a1..579b4de8bdd 100644 --- a/src/main/java/org/jabref/gui/FXDialogService.java +++ b/src/main/java/org/jabref/gui/FXDialogService.java @@ -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); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 71e75d1c54d..8ec31a46d11 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -178,7 +178,6 @@ public class JabRefFrame extends BorderPane { public JabRefFrame(Stage mainStage) { this.mainStage = mainStage; this.dialogService = new FXDialogService(mainStage, this); - init(); } /** @@ -204,7 +203,7 @@ private static void setEnabled(List list, boolean enabled) { } } - private void init() { + public void init() { sidePaneManager = new SidePaneManager(Globals.prefs, this); sidePane = sidePaneManager.getPane(); diff --git a/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java b/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java index c5849decfef..a84904534bb 100644 --- a/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java @@ -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; @@ -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; } diff --git a/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java b/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java index e4b658036a0..3efe55cb530 100644 --- a/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java @@ -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; @@ -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; } diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java index e620e69e84b..676868ac898 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java @@ -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; @@ -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 = DefaultTaskExecutor .runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration)); diff --git a/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java b/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java index 51a27e3b70a..c3f50e3c853 100644 --- a/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java +++ b/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java @@ -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; @@ -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")),