3
3
import java .nio .file .Files ;
4
4
import java .nio .file .Path ;
5
5
import java .sql .SQLException ;
6
+ import java .util .ArrayList ;
6
7
import java .util .Arrays ;
7
8
import java .util .Collections ;
8
9
import java .util .Iterator ;
@@ -42,11 +43,11 @@ public class OpenDatabaseAction extends SimpleCommand {
42
43
// List of actions that may need to be called after opening the file. Such as
43
44
// upgrade actions etc. that may depend on the JabRef version that wrote the file:
44
45
private static final List <GUIPostOpenAction > POST_OPEN_ACTIONS = Arrays .asList (
45
- // Migrations:
46
- // Warning for migrating the Review into the Comment field
47
- new MergeReviewIntoCommentAction (),
48
- // Check for new custom entry types loaded from the BIB file:
49
- new CheckForNewEntryTypesAction ());
46
+ // Migrations:
47
+ // Warning for migrating the Review into the Comment field
48
+ new MergeReviewIntoCommentAction (),
49
+ // Check for new custom entry types loaded from the BIB file:
50
+ new CheckForNewEntryTypesAction ());
50
51
51
52
private final JabRefFrame frame ;
52
53
private final DialogService dialogService ;
@@ -84,7 +85,6 @@ public void execute() {
84
85
}
85
86
86
87
/**
87
- *
88
88
* @return Path of current panel database directory or the working directory
89
89
*/
90
90
private Path getInitialDirectory () {
@@ -102,7 +102,7 @@ private Path getInitialDirectory() {
102
102
* @param file the file, may be null or not existing
103
103
*/
104
104
public void openFile (Path file , boolean raisePanel ) {
105
- openFiles (Arrays . asList (file ), raisePanel );
105
+ openFiles (new ArrayList <>( List . of (file ) ), raisePanel );
106
106
}
107
107
108
108
/**
@@ -116,12 +116,12 @@ public void openFiles(List<Path> filesToOpen, boolean raisePanel) {
116
116
int removed = 0 ;
117
117
118
118
// Check if any of the files are already open:
119
- for (Iterator <Path > iterator = filesToOpen .iterator (); iterator .hasNext ();) {
119
+ for (Iterator <Path > iterator = filesToOpen .iterator (); iterator .hasNext (); ) {
120
120
Path file = iterator .next ();
121
121
for (int i = 0 ; i < frame .getTabbedPane ().getTabs ().size (); i ++) {
122
122
BasePanel basePanel = frame .getBasePanelAt (i );
123
123
if ((basePanel .getBibDatabaseContext ().getDatabasePath ().isPresent ())
124
- && basePanel .getBibDatabaseContext ().getDatabasePath ().get ().equals (file )) {
124
+ && basePanel .getBibDatabaseContext ().getDatabasePath ().get ().equals (file )) {
125
125
iterator .remove ();
126
126
removed ++;
127
127
// See if we removed the final one. If so, we must perhaps
@@ -169,10 +169,9 @@ private void openTheFile(Path file, boolean raisePanel) {
169
169
OpenDatabaseAction .performPostOpenActions (panel , result );
170
170
})
171
171
.onFailure (ex -> dialogService .showErrorDialogAndWait (Localization .lang ("Connection error" ),
172
- ex .getMessage () + "\n \n " + Localization .lang ("A local copy will be opened." )))
172
+ ex .getMessage () + "\n \n " + Localization .lang ("A local copy will be opened." )))
173
173
.executeWith (Globals .TASK_EXECUTOR );
174
174
}
175
-
176
175
}
177
176
178
177
private ParserResult loadDatabase (Path file ) throws Exception {
@@ -187,23 +186,21 @@ private ParserResult loadDatabase(Path file) throws Exception {
187
186
}
188
187
189
188
ParserResult result = OpenDatabase .loadDatabase (fileToLoad .toString (),
190
- Globals .prefs .getImportFormatPreferences (), Globals .getFileUpdateMonitor ());
189
+ Globals .prefs .getImportFormatPreferences (), Globals .getFileUpdateMonitor ());
191
190
192
191
if (result .getDatabase ().isShared ()) {
193
192
try {
194
193
new SharedDatabaseUIManager (frame ).openSharedDatabaseFromParserResult (result );
195
194
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException |
196
- NotASharedDatabaseException e ) {
195
+ NotASharedDatabaseException e ) {
197
196
result .getDatabaseContext ().clearDatabaseFile (); // do not open the original file
198
197
result .getDatabase ().clearSharedDatabaseID ();
199
198
LOGGER .error ("Connection error" , e );
200
199
201
200
throw e ;
202
-
203
201
}
204
202
}
205
203
return result ;
206
-
207
204
}
208
205
209
206
private BasePanel addNewDatabase (ParserResult result , final Path file , boolean raisePanel ) {
@@ -214,6 +211,5 @@ private BasePanel addNewDatabase(ParserResult result, final Path file, boolean r
214
211
BasePanel basePanel = new BasePanel (frame , BasePanelPreferences .from (Globals .prefs ), result .getDatabaseContext (), ExternalFileTypes .getInstance ());
215
212
frame .addTab (basePanel , raisePanel );
216
213
return basePanel ;
217
-
218
214
}
219
215
}
0 commit comments