35
35
import org .jabref .model .groups .GroupEntryChanger ;
36
36
import org .jabref .model .groups .GroupTreeNode ;
37
37
import org .jabref .model .strings .StringUtil ;
38
+ import org .jabref .preferences .PreferencesService ;
38
39
39
40
import com .google .common .base .Enums ;
40
41
import com .tobiasdiez .easybind .EasyBind ;
@@ -57,13 +58,15 @@ public class GroupNodeViewModel {
57
58
private final TaskExecutor taskExecutor ;
58
59
private final CustomLocalDragboard localDragBoard ;
59
60
private final ObservableList <BibEntry > entriesList ;
61
+ private final PreferencesService preferencesService ;
60
62
61
- public GroupNodeViewModel (BibDatabaseContext databaseContext , StateManager stateManager , TaskExecutor taskExecutor , GroupTreeNode groupNode , CustomLocalDragboard localDragBoard ) {
63
+ public GroupNodeViewModel (BibDatabaseContext databaseContext , StateManager stateManager , TaskExecutor taskExecutor , GroupTreeNode groupNode , CustomLocalDragboard localDragBoard , PreferencesService preferencesService ) {
62
64
this .databaseContext = Objects .requireNonNull (databaseContext );
63
65
this .taskExecutor = Objects .requireNonNull (taskExecutor );
64
66
this .stateManager = Objects .requireNonNull (stateManager );
65
67
this .groupNode = Objects .requireNonNull (groupNode );
66
68
this .localDragBoard = Objects .requireNonNull (localDragBoard );
69
+ this .preferencesService = preferencesService ;
67
70
68
71
displayName = new LatexToUnicodeFormatter ().format (groupNode .getName ());
69
72
isRoot = groupNode .isRoot ();
@@ -95,16 +98,16 @@ public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager state
95
98
allSelectedEntriesMatched = selectedEntriesMatchStatus .isEmptyBinding ().not ().and (selectedEntriesMatchStatus .allMatch (matched -> matched ));
96
99
}
97
100
98
- public GroupNodeViewModel (BibDatabaseContext databaseContext , StateManager stateManager , TaskExecutor taskExecutor , AbstractGroup group , CustomLocalDragboard localDragboard ) {
99
- this (databaseContext , stateManager , taskExecutor , new GroupTreeNode (group ), localDragboard );
101
+ public GroupNodeViewModel (BibDatabaseContext databaseContext , StateManager stateManager , TaskExecutor taskExecutor , AbstractGroup group , CustomLocalDragboard localDragboard , PreferencesService preferencesService ) {
102
+ this (databaseContext , stateManager , taskExecutor , new GroupTreeNode (group ), localDragboard , preferencesService );
100
103
}
101
104
102
- static GroupNodeViewModel getAllEntriesGroup (BibDatabaseContext newDatabase , StateManager stateManager , TaskExecutor taskExecutor , CustomLocalDragboard localDragBoard ) {
103
- return new GroupNodeViewModel (newDatabase , stateManager , taskExecutor , DefaultGroupsFactory .getAllEntriesGroup (), localDragBoard );
105
+ static GroupNodeViewModel getAllEntriesGroup (BibDatabaseContext newDatabase , StateManager stateManager , TaskExecutor taskExecutor , CustomLocalDragboard localDragBoard , PreferencesService preferencesService ) {
106
+ return new GroupNodeViewModel (newDatabase , stateManager , taskExecutor , DefaultGroupsFactory .getAllEntriesGroup (), localDragBoard , preferencesService );
104
107
}
105
108
106
109
private GroupNodeViewModel toViewModel (GroupTreeNode child ) {
107
- return new GroupNodeViewModel (databaseContext , stateManager , taskExecutor , child , localDragBoard );
110
+ return new GroupNodeViewModel (databaseContext , stateManager , taskExecutor , child , localDragBoard , preferencesService );
108
111
}
109
112
110
113
public List <FieldChange > addEntriesToGroup (List <BibEntry > entries ) {
@@ -251,13 +254,15 @@ private void updateMatchedEntries() {
251
254
// We calculate the new hit value
252
255
// We could be more intelligent and try to figure out the new number of hits based on the entry change
253
256
// for example, a previously matched entry gets removed -> hits = hits - 1
254
- BackgroundTask
255
- .wrap (() -> groupNode .findMatches (databaseContext .getDatabase ()))
256
- .onSuccess (entries -> {
257
- matchedEntries .clear ();
258
- matchedEntries .addAll (entries );
259
- })
260
- .executeWith (taskExecutor );
257
+ if (preferencesService .getDisplayGroupCount ()) {
258
+ BackgroundTask
259
+ .wrap (() -> groupNode .findMatches (databaseContext .getDatabase ()))
260
+ .onSuccess (entries -> {
261
+ matchedEntries .clear ();
262
+ matchedEntries .addAll (entries );
263
+ })
264
+ .executeWith (taskExecutor );
265
+ }
261
266
}
262
267
263
268
public GroupTreeNode addSubgroup (AbstractGroup subgroup ) {
0 commit comments