1
1
package org .jabref .gui .importer ;
2
2
3
3
import java .util .Optional ;
4
+ import java .util .function .Supplier ;
4
5
5
6
import org .jabref .gui .DialogService ;
6
7
import org .jabref .gui .LibraryTab ;
@@ -16,39 +17,35 @@ public class NewEntryAction extends SimpleCommand {
16
17
/**
17
18
* The type of the entry to create.
18
19
*/
19
- private Optional <EntryType > type ;
20
-
20
+ private final Optional <EntryType > type ;
21
+ private final Supplier < LibraryTab > tabSupplier ;
21
22
private final DialogService dialogService ;
22
-
23
23
private final GuiPreferences preferences ;
24
- private final StateManager stateManager ;
25
24
26
- public NewEntryAction (DialogService dialogService , GuiPreferences preferences , StateManager stateManager ) {
25
+ public NewEntryAction (EntryType type , Supplier <LibraryTab > tabSupplier , DialogService dialogService , GuiPreferences preferences , StateManager stateManager ) {
26
+ this .type = Optional .ofNullable (type );
27
+ this .tabSupplier = tabSupplier ;
27
28
this .dialogService = dialogService ;
28
29
this .preferences = preferences ;
29
- this .stateManager = stateManager ;
30
-
31
- this .type = Optional .empty ();
32
30
33
31
this .executable .bind (ActionHelper .needsDatabase (stateManager ));
34
32
}
35
33
36
34
public NewEntryAction (EntryType type , DialogService dialogService , GuiPreferences preferences , StateManager stateManager ) {
37
- this (dialogService , preferences , stateManager );
38
- this .type = Optional .ofNullable (type );
35
+ this (type , () -> stateManager .activeTabProperty ().get ().get (), dialogService , preferences , stateManager );
36
+ }
37
+
38
+ public NewEntryAction (DialogService dialogService , GuiPreferences preferences , StateManager stateManager ) {
39
+ this (null , dialogService , preferences , stateManager );
39
40
}
40
41
41
42
@ Override
42
43
public void execute () {
43
- Optional < LibraryTab > activeTab = stateManager . activeTabProperty () .get ();
44
- if (activeTab . isEmpty () ) {
44
+ LibraryTab libraryTab = tabSupplier .get ();
45
+ if (libraryTab == null ) {
45
46
return ;
46
47
}
47
48
48
- execute (activeTab .get ());
49
- }
50
-
51
- public void execute (LibraryTab libraryTab ) {
52
49
if (type .isPresent ()) {
53
50
libraryTab .insertEntry (new BibEntry (type .get ()));
54
51
} else {
0 commit comments