Skip to content

Commit 38e162d

Browse files
r0lighttobiasdiez
authored andcommitted
removed default constructor of FXDialogService (#4847)
* removed default constructor of FXDialogService * Revert "removed default constructor of FXDialogService" This reverts commit 4c964ca. * regained injection and splitted jabrefframe creation and init to hav dialogservice ready * replaced JabRegGUI.mainFrame with mainFrame
1 parent 17bfe91 commit 38e162d

File tree

8 files changed

+22
-38
lines changed

8 files changed

+22
-38
lines changed

src/main/java/org/jabref/JabRefGUI.java

+11-14
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import javafx.stage.Stage;
1111

1212
import org.jabref.gui.BasePanel;
13-
import org.jabref.gui.DialogService;
14-
import org.jabref.gui.FXDialogService;
1513
import org.jabref.gui.GUIGlobals;
1614
import org.jabref.gui.JabRefFrame;
1715
import org.jabref.gui.dialogs.BackupUIManager;
@@ -43,14 +41,13 @@ public class JabRefGUI {
4341
private final boolean isBlank;
4442
private final List<ParserResult> failed = new ArrayList<>();
4543
private final List<ParserResult> toOpenTab = new ArrayList<>();
46-
private final DialogService dialogService;
4744

4845
private final String focusedFile;
4946

5047
public JabRefGUI(Stage mainStage, List<ParserResult> argsDatabases, boolean isBlank) {
5148
this.bibDatabases = argsDatabases;
5249
this.isBlank = isBlank;
53-
this.dialogService = new FXDialogService(mainStage);
50+
mainFrame = new JabRefFrame(mainStage);
5451

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

6259
openWindow(mainStage);
63-
new VersionWorker(Globals.BUILD_INFO.getVersion(), Globals.prefs.getVersionPreferences().getIgnoredVersion(), JabRefGUI.getMainFrame().getDialogService(), Globals.TASK_EXECUTOR)
60+
new VersionWorker(Globals.BUILD_INFO.getVersion(), Globals.prefs.getVersionPreferences().getIgnoredVersion(), mainFrame.getDialogService(), Globals.TASK_EXECUTOR)
6461
.checkForNewVersionAsync(false);
6562
}
6663

@@ -75,7 +72,7 @@ private void openWindow(Stage mainStage) {
7572
GUIGlobals.init();
7673

7774
LOGGER.debug("Initializing frame");
78-
JabRefGUI.mainFrame = new JabRefFrame(mainStage);
75+
mainFrame.init();
7976

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

10198
LOGGER.error("Connection error", e);
102-
dialogService.showErrorDialogAndWait(
99+
mainFrame.getDialogService().showErrorDialogAndWait(
103100
Localization.lang("Connection error"),
104101
Localization.lang("A local copy will be opened."),
105102
e);
@@ -110,15 +107,15 @@ private void openWindow(Stage mainStage) {
110107
// add them to the list
111108
toOpenTab.add(pr);
112109
} else {
113-
JabRefGUI.getMainFrame().addParserResult(pr, first);
110+
mainFrame.addParserResult(pr, first);
114111
first = false;
115112
}
116113
}
117114
}
118115

119116
// finally add things to the currently opened tab
120117
for (ParserResult pr : toOpenTab) {
121-
JabRefGUI.getMainFrame().addParserResult(pr, first);
118+
mainFrame.addParserResult(pr, first);
122119
first = false;
123120
}
124121

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

161-
dialogService.showErrorDialogAndWait(Localization.lang("Error opening file"), message);
158+
mainFrame.getDialogService().showErrorDialogAndWait(Localization.lang("Error opening file"), message);
162159

163160
}
164161

165162
// Display warnings, if any
166163
int tabNumber = 0;
167164
for (ParserResult pr : bibDatabases) {
168-
ParserResultWarningDialog.showParserResultWarningDialog(pr, JabRefGUI.getMainFrame(), tabNumber++);
165+
ParserResultWarningDialog.showParserResultWarningDialog(pr, mainFrame, tabNumber++);
169166
}
170167

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

180-
for (int i = 0; (i < bibDatabases.size()) && (i < JabRefGUI.getMainFrame().getBasePanelCount()); i++) {
177+
for (int i = 0; (i < bibDatabases.size()) && (i < mainFrame.getBasePanelCount()); i++) {
181178
ParserResult pr = bibDatabases.get(i);
182-
BasePanel panel = JabRefGUI.getMainFrame().getBasePanelAt(i);
179+
BasePanel panel = mainFrame.getBasePanelAt(i);
183180
OpenDatabaseAction.performPostOpenActions(panel, pr);
184181
}
185182

@@ -209,7 +206,7 @@ private void openLastEditedDatabases() {
209206
}
210207

211208
if (BackupManager.checkForBackupFile(dbFile.toPath())) {
212-
BackupUIManager.showRestoreBackupDialog(dialogService, dbFile.toPath());
209+
BackupUIManager.showRestoreBackupDialog(mainFrame.getDialogService(), dbFile.toPath());
213210
}
214211

215212
ParserResult parsedDatabase = OpenDatabase.loadDatabase(fileName,

src/main/java/org/jabref/gui/DefaultInjector.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javax.swing.undo.UndoManager;
66

77
import org.jabref.Globals;
8+
import org.jabref.JabRefGUI;
89
import org.jabref.gui.keyboard.KeyBindingRepository;
910
import org.jabref.gui.util.TaskExecutor;
1011
import org.jabref.logic.journals.JournalAbbreviationLoader;
@@ -28,7 +29,7 @@ public class DefaultInjector implements PresenterFactory {
2829
*/
2930
private static Object createDependency(Class<?> clazz) {
3031
if (clazz == DialogService.class) {
31-
return new FXDialogService();
32+
return JabRefGUI.getMainFrame().getDialogService();
3233
} else if (clazz == TaskExecutor.class) {
3334
return Globals.TASK_EXECUTOR;
3435
} else if (clazz == PreferencesService.class) {

src/main/java/org/jabref/gui/FXDialogService.java

-13
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,6 @@ public class FXDialogService implements DialogService {
6363
private final Window mainWindow;
6464
private final JFXSnackbar statusLine;
6565

66-
/**
67-
* @deprecated try not to initialize a new dialog service but reuse the one constructed in {@link org.jabref.gui.JabRefFrame}.
68-
*/
69-
@Deprecated
70-
public FXDialogService() {
71-
this(null);
72-
}
73-
74-
public FXDialogService(Window mainWindow) {
75-
this.mainWindow = mainWindow;
76-
this.statusLine = new JFXSnackbar();
77-
}
78-
7966
public FXDialogService(Window mainWindow, Pane mainPane) {
8067
this.mainWindow = mainWindow;
8168
this.statusLine = new JFXSnackbar(mainPane);

src/main/java/org/jabref/gui/JabRefFrame.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ public class JabRefFrame extends BorderPane {
178178
public JabRefFrame(Stage mainStage) {
179179
this.mainStage = mainStage;
180180
this.dialogService = new FXDialogService(mainStage, this);
181-
init();
182181
}
183182

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

207-
private void init() {
206+
public void init() {
208207
sidePaneManager = new SidePaneManager(Globals.prefs, this);
209208
sidePane = sidePaneManager.getPane();
210209

src/main/java/org/jabref/gui/collab/EntryAddChangeViewModel.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import javafx.scene.Node;
44

55
import org.jabref.Globals;
6-
import org.jabref.gui.FXDialogService;
6+
import org.jabref.JabRefGUI;
77
import org.jabref.gui.PreviewPanel;
88
import org.jabref.gui.externalfiletype.ExternalFileTypes;
99
import org.jabref.gui.undo.NamedCompound;
@@ -29,7 +29,7 @@ public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {
2929

3030
@Override
3131
public Node description() {
32-
PreviewPanel previewPanel = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), new FXDialogService(), ExternalFileTypes.getInstance());
32+
PreviewPanel previewPanel = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), JabRefGUI.getMainFrame().getDialogService(), ExternalFileTypes.getInstance());
3333
previewPanel.setEntry(diskEntry);
3434
return previewPanel;
3535
}

src/main/java/org/jabref/gui/collab/EntryDeleteChangeViewModel.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import javafx.scene.Node;
44

55
import org.jabref.Globals;
6-
import org.jabref.gui.FXDialogService;
6+
import org.jabref.JabRefGUI;
77
import org.jabref.gui.PreviewPanel;
88
import org.jabref.gui.externalfiletype.ExternalFileTypes;
99
import org.jabref.gui.undo.NamedCompound;
@@ -46,7 +46,7 @@ public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {
4646

4747
@Override
4848
public Node description() {
49-
PreviewPanel previewPanel = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), new FXDialogService(), ExternalFileTypes.getInstance());
49+
PreviewPanel previewPanel = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), JabRefGUI.getMainFrame().getDialogService(), ExternalFileTypes.getInstance());
5050
previewPanel.setEntry(memEntry);
5151
return previewPanel;
5252
}

src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEntryEditor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import javax.swing.event.DocumentListener;
2121

2222
import org.jabref.Globals;
23+
import org.jabref.JabRefGUI;
2324
import org.jabref.gui.DialogService;
24-
import org.jabref.gui.FXDialogService;
2525
import org.jabref.gui.icon.IconTheme;
2626
import org.jabref.gui.util.DefaultTaskExecutor;
2727
import org.jabref.gui.util.FileDialogConfiguration;
@@ -62,7 +62,7 @@ public class ExternalFileTypeEntryEditor {
6262

6363
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
6464
.withInitialDirectory(Paths.get(appDir)).build();
65-
DialogService ds = new FXDialogService();
65+
DialogService ds = JabRefGUI.getMainFrame().getDialogService();
6666

6767
Optional<Path> path = DefaultTaskExecutor
6868
.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration));

src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import javafx.scene.control.TabPane;
77
import javafx.stage.Stage;
88

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

0 commit comments

Comments
 (0)