20
20
21
21
import javafx .collections .FXCollections ;
22
22
import javafx .collections .ObservableList ;
23
- import javafx .collections .ObservableSet ;
24
23
25
24
import org .jabref .logic .bibtex .FieldWriter ;
26
25
import org .jabref .model .database .event .EntriesAddedEvent ;
30
29
import org .jabref .model .entry .Month ;
31
30
import org .jabref .model .entry .event .EntriesEventSource ;
32
31
import org .jabref .model .entry .event .EntryChangedEvent ;
33
- import org .jabref .model .entry .event .FieldAddedOrRemovedEvent ;
34
32
import org .jabref .model .entry .event .FieldChangedEvent ;
35
33
import org .jabref .model .entry .field .Field ;
36
34
import org .jabref .model .entry .field .FieldFactory ;
@@ -54,8 +52,6 @@ public class BibDatabase {
54
52
* State attributes
55
53
*/
56
54
private final ObservableList <BibEntry > entries = FXCollections .synchronizedObservableList (FXCollections .observableArrayList (BibEntry ::getObservables ));
57
-
58
- private final ObservableSet <Field > visibleFields = FXCollections .observableSet ();
59
55
private Map <String , BibtexString > bibtexStrings = new ConcurrentHashMap <>();
60
56
61
57
private final EventBus eventBus = new EventBus ();
@@ -140,8 +136,13 @@ public ObservableList<BibEntry> getEntries() {
140
136
*
141
137
* @return set of fieldnames, that are visible
142
138
*/
143
- public ObservableSet <Field > getAllVisibleFields () {
144
- return visibleFields ;
139
+ public Set <Field > getAllVisibleFields () {
140
+ Set <Field > allFields = new TreeSet <>(Comparator .comparing (Field ::getName ));
141
+ for (BibEntry e : getEntries ()) {
142
+ allFields .addAll (e .getFields ());
143
+ }
144
+ return allFields .stream ().filter (field -> !FieldFactory .isInternalField (field ))
145
+ .collect (Collectors .toSet ());
145
146
}
146
147
147
148
/**
@@ -213,8 +214,6 @@ public synchronized void insertEntries(List<BibEntry> newEntries, EntriesEventSo
213
214
eventBus .post (new EntriesAddedEvent (newEntries , newEntries .get (0 ), eventSource ));
214
215
}
215
216
entries .addAll (newEntries );
216
-
217
- updateVisibleFields ();
218
217
}
219
218
220
219
public synchronized void removeEntry (BibEntry bibEntry ) {
@@ -252,7 +251,6 @@ public synchronized void removeEntries(List<BibEntry> toBeDeleted, EntriesEventS
252
251
boolean anyRemoved = entries .removeIf (entry -> ids .contains (entry .getId ()));
253
252
if (anyRemoved ) {
254
253
eventBus .post (new EntriesRemovedEvent (toBeDeleted , eventSource ));
255
- updateVisibleFields ();
256
254
}
257
255
}
258
256
@@ -586,30 +584,6 @@ private void relayEntryChangeEvent(FieldChangedEvent event) {
586
584
eventBus .post (event );
587
585
}
588
586
589
- @ Subscribe
590
- private void listen (FieldAddedOrRemovedEvent event ) {
591
- // When a field is removed from an entry we can't tell if it's
592
- // still present in other entries, and thus we can't remove it
593
- // from the set of visible fields. However, when a new field is added
594
- // to any entry, we can simply add it to the set because we're
595
- // going to add it whether other entries have it or not
596
- boolean isAdded = visibleFields .add (event .getField ());
597
- if (!isAdded ) {
598
- updateVisibleFields ();
599
- }
600
- }
601
-
602
- private void updateVisibleFields () {
603
- visibleFields .clear ();
604
- Set <Field > allFields = new TreeSet <>(Comparator .comparing (Field ::getName ));
605
- for (BibEntry e : getEntries ()) {
606
- allFields .addAll (e .getFields ());
607
- }
608
- visibleFields .addAll (allFields .stream ().filter (field -> !FieldFactory .isInternalField (field ))
609
- .filter (field -> StringUtil .isNotBlank (field .getName ()))
610
- .collect (Collectors .toSet ()));
611
- }
612
-
613
587
public Optional <BibEntry > getReferencedEntry (BibEntry entry ) {
614
588
return entry .getField (StandardField .CROSSREF ).flatMap (this ::getEntryByCitationKey );
615
589
}
0 commit comments