Skip to content

Commit eea1b37

Browse files
committed
Remove SmartGroup and refactor groups factory
1 parent 3c05bce commit eea1b37

File tree

20 files changed

+71
-153
lines changed

20 files changed

+71
-153
lines changed

jabgui/src/main/java/org/jabref/gui/collab/groupchange/GroupChange.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.jabref.gui.groups.UndoableModifySubtree;
77
import org.jabref.gui.undo.NamedCompoundEdit;
88
import org.jabref.logic.bibtex.comparator.GroupDiff;
9-
import org.jabref.logic.groups.DefaultGroupsFactory;
9+
import org.jabref.logic.groups.GroupsFactory;
1010
import org.jabref.logic.l10n.Localization;
1111
import org.jabref.model.database.BibDatabaseContext;
1212
import org.jabref.model.groups.GroupTreeNode;
@@ -27,7 +27,7 @@ public void applyChange(NamedCompoundEdit undoEdit) {
2727
GroupTreeNode newRoot = groupDiff.getNewGroupRoot();
2828

2929
GroupTreeNode root = databaseContext.getMetaData().getGroups().orElseGet(() -> {
30-
GroupTreeNode groupTreeNode = new GroupTreeNode(DefaultGroupsFactory.getAllEntriesGroup());
30+
GroupTreeNode groupTreeNode = new GroupTreeNode(GroupsFactory.getAllEntriesGroup());
3131
databaseContext.getMetaData().setGroups(groupTreeNode);
3232
return groupTreeNode;
3333
});
@@ -38,7 +38,7 @@ public void applyChange(NamedCompoundEdit undoEdit) {
3838
root.removeAllChildren();
3939
if (newRoot == null) {
4040
// I think setting root to null is not possible
41-
root.setGroup(DefaultGroupsFactory.getAllEntriesGroup(), false, false, null);
41+
root.setGroup(GroupsFactory.getAllEntriesGroup(), false, false, null);
4242
} else {
4343
// change root group, even though it'll be AllEntries anyway
4444
root.setGroup(newRoot.getGroup(), false, false, null);

jabgui/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
import org.jabref.model.entry.BibtexString;
5555
import org.jabref.model.entry.LinkedFile;
5656
import org.jabref.model.entry.field.StandardField;
57+
import org.jabref.model.groups.ExplicitGroup;
5758
import org.jabref.model.groups.GroupEntryChanger;
5859
import org.jabref.model.groups.GroupTreeNode;
59-
import org.jabref.model.groups.SmartGroup;
6060
import org.jabref.model.util.FileUpdateMonitor;
6161
import org.jabref.model.util.OptionalUtil;
6262

@@ -516,14 +516,15 @@ private List<BibEntry> handlePdfUrl(String pdfUrl) throws IOException {
516516

517517
private void addToImportEntriesGroup(List<BibEntry> entriesToInsert) {
518518
if (preferences.getLibraryPreferences().isAddImportedEntriesEnabled()) {
519-
// Only one SmartGroup
519+
String groupName = preferences.getLibraryPreferences().getAddImportedEntriesGroupName();
520520
this.bibDatabaseContext.getMetaData()
521521
.getGroups()
522522
.flatMap(grp -> grp.getChildren()
523523
.stream()
524-
.filter(node -> node.getGroup() instanceof SmartGroup)
524+
.filter(node -> node.getGroup() instanceof ExplicitGroup
525+
&& node.getGroup().getName().equals(groupName))
525526
.findFirst())
526-
.ifPresent(smtGrp -> smtGrp.addEntriesToGroup(entriesToInsert));
527+
.ifPresent(importGroup -> importGroup.addEntriesToGroup(entriesToInsert));
527528
}
528529
}
529530
}

jabgui/src/main/java/org/jabref/gui/groups/GroupDescriptions.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.jabref.model.groups.ExplicitGroup;
66
import org.jabref.model.groups.KeywordGroup;
77
import org.jabref.model.groups.SearchGroup;
8-
import org.jabref.model.groups.SmartGroup;
98

109
public class GroupDescriptions {
1110

@@ -62,10 +61,6 @@ public static String getShortDescriptionAllEntriesGroup() {
6261
return Localization.lang("<b>All Entries</b> (this group cannot be edited or removed)");
6362
}
6463

65-
public static String getShortDescriptionSmartGroup(SmartGroup smartGroup) {
66-
return Localization.lang("<b>Smart Group</b> (Import Entries)");
67-
}
68-
6964
public static String getShortDescription(SearchGroup searchGroup, boolean showDynamic) {
7065
StringBuilder sb = new StringBuilder();
7166
sb.append("<b>");

jabgui/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.jabref.gui.preferences.GuiPreferences;
3131
import org.jabref.gui.util.FileDialogConfiguration;
3232
import org.jabref.logic.auxparser.DefaultAuxParser;
33-
import org.jabref.logic.groups.DefaultGroupsFactory;
33+
import org.jabref.logic.groups.GroupsFactory;
3434
import org.jabref.logic.l10n.Localization;
3535
import org.jabref.logic.search.IndexManager;
3636
import org.jabref.logic.util.StandardFileType;
@@ -416,14 +416,14 @@ public void setValues() {
416416

417417
if (editedGroup == null) {
418418
// creating new group -> defaults!
419-
// TODO: Create default group (via org.jabref.logic.groups.DefaultGroupsFactory) and use values
419+
// TODO: Create default group (via org.jabref.logic.groups.GroupsFactory) and use values
420420

421421
colorUseProperty.setValue(false);
422422
colorProperty.setValue(determineColor());
423423
if (parentNode != null) {
424424
parentNode.getGroup()
425425
.getIconName()
426-
.filter(iconName -> !DefaultGroupsFactory.ALL_ENTRIES_GROUP_DEFAULT_ICON.equals(iconName))
426+
.filter(iconName -> !GroupsFactory.ALL_ENTRIES_GROUP_DEFAULT_ICON.equals(iconName))
427427
.ifPresent(iconProperty::setValue);
428428
parentNode.getGroup().getColor().ifPresent(color -> colorUseProperty.setValue(true));
429429
}

jabgui/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.jabref.gui.util.CustomLocalDragboard;
2727
import org.jabref.gui.util.DroppingMouseLocation;
2828
import org.jabref.gui.util.UiTaskExecutor;
29-
import org.jabref.logic.groups.DefaultGroupsFactory;
29+
import org.jabref.logic.groups.GroupsFactory;
3030
import org.jabref.logic.layout.format.LatexToUnicodeFormatter;
3131
import org.jabref.logic.util.BackgroundTask;
3232
import org.jabref.logic.util.TaskExecutor;
@@ -48,7 +48,6 @@
4848
import org.jabref.model.groups.LastNameGroup;
4949
import org.jabref.model.groups.RegexKeywordGroup;
5050
import org.jabref.model.groups.SearchGroup;
51-
import org.jabref.model.groups.SmartGroup;
5251
import org.jabref.model.groups.TexGroup;
5352
import org.jabref.model.search.event.IndexAddedOrUpdatedEvent;
5453
import org.jabref.model.search.event.IndexClosedEvent;
@@ -141,7 +140,7 @@ public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager state
141140
}
142141

143142
static GroupNodeViewModel getAllEntriesGroup(BibDatabaseContext newDatabase, StateManager stateManager, TaskExecutor taskExecutor, CustomLocalDragboard localDragBoard, GuiPreferences preferences) {
144-
return new GroupNodeViewModel(newDatabase, stateManager, taskExecutor, DefaultGroupsFactory.getAllEntriesGroup(), localDragBoard, preferences);
143+
return new GroupNodeViewModel(newDatabase, stateManager, taskExecutor, GroupsFactory.getAllEntriesGroup(), localDragBoard, preferences);
145144
}
146145

147146
private GroupNodeViewModel toViewModel(GroupTreeNode child) {
@@ -437,16 +436,14 @@ public boolean hasSimilarSearchGroup(SearchGroup searchGroup) {
437436
}
438437

439438
public boolean hasAllSuggestedGroups() {
440-
return hasSimilarSearchGroup(JabRefSuggestedGroups.createWithoutFilesGroup())
441-
&& hasSimilarSearchGroup(JabRefSuggestedGroups.createWithoutGroupsGroup());
439+
return hasSimilarSearchGroup(GroupsFactory.createWithoutFilesGroup())
440+
&& hasSimilarSearchGroup(GroupsFactory.createWithoutGroupsGroup());
442441
}
443442

444443
public boolean canAddEntriesIn() {
445444
AbstractGroup group = groupNode.getGroup();
446445
if (group instanceof AllEntriesGroup) {
447446
return false;
448-
} else if (group instanceof SmartGroup) {
449-
return false;
450447
} else if (group instanceof ExplicitGroup) {
451448
return true;
452449
} else if (group instanceof LastNameGroup || group instanceof RegexKeywordGroup) {
@@ -477,8 +474,7 @@ public boolean canAddEntriesIn() {
477474
public boolean canBeDragged() {
478475
AbstractGroup group = groupNode.getGroup();
479476
return switch (group) {
480-
case AllEntriesGroup _,
481-
SmartGroup _ ->
477+
case AllEntriesGroup _ ->
482478
false;
483479
case ExplicitGroup _,
484480
SearchGroup _,
@@ -513,8 +509,7 @@ public boolean canAddGroupsIn() {
513509
case AutomaticKeywordGroup _,
514510
AutomaticPersonsGroup _,
515511
AutomaticDateGroup _,
516-
DateGroup _,
517-
SmartGroup _ ->
512+
DateGroup _ ->
518513
false;
519514
case KeywordGroup _ ->
520515
// KeywordGroup is parent of LastNameGroup, RegexKeywordGroup and WordKeywordGroup
@@ -532,8 +527,7 @@ public boolean canAddGroupsIn() {
532527
public boolean canRemove() {
533528
AbstractGroup group = groupNode.getGroup();
534529
return switch (group) {
535-
case AllEntriesGroup _,
536-
SmartGroup _ ->
530+
case AllEntriesGroup _ ->
537531
false;
538532
case ExplicitGroup _,
539533
SearchGroup _,
@@ -560,8 +554,7 @@ public boolean isEditable() {
560554
AbstractGroup group = groupNode.getGroup();
561555
return switch (group) {
562556
case AllEntriesGroup _,
563-
DateGroup _,
564-
SmartGroup _ ->
557+
DateGroup _ ->
565558
false;
566559
case ExplicitGroup _,
567560
SearchGroup _,

jabgui/src/main/java/org/jabref/gui/groups/GroupTreeNodeViewModel.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.jabref.model.groups.GroupTreeNode;
1818
import org.jabref.model.groups.KeywordGroup;
1919
import org.jabref.model.groups.SearchGroup;
20-
import org.jabref.model.groups.SmartGroup;
2120

2221
public class GroupTreeNodeViewModel {
2322
private final GroupTreeNode node;
@@ -52,8 +51,6 @@ public String getDescription() {
5251
String shortDescription = "";
5352
boolean showDynamic = true;
5453
shortDescription = switch (group) {
55-
case SmartGroup smartGroup ->
56-
GroupDescriptions.getShortDescriptionSmartGroup(smartGroup);
5754
case ExplicitGroup explicitGroup ->
5855
GroupDescriptions.getShortDescriptionExplicitGroup(explicitGroup);
5956
case KeywordGroup keywordGroup ->

jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.jabref.gui.preferences.GuiPreferences;
2929
import org.jabref.gui.util.CustomLocalDragboard;
3030
import org.jabref.logic.ai.AiService;
31+
import org.jabref.logic.groups.GroupsFactory;
3132
import org.jabref.logic.l10n.Localization;
3233
import org.jabref.logic.util.TaskExecutor;
3334
import org.jabref.model.database.BibDatabaseContext;
@@ -41,7 +42,6 @@
4142
import org.jabref.model.groups.GroupTreeNode;
4243
import org.jabref.model.groups.RegexKeywordGroup;
4344
import org.jabref.model.groups.SearchGroup;
44-
import org.jabref.model.groups.SmartGroup;
4545
import org.jabref.model.groups.TexGroup;
4646
import org.jabref.model.groups.WordKeywordGroup;
4747
import org.jabref.model.metadata.MetaData;
@@ -188,12 +188,12 @@ private void addGroupImportEntries(GroupNodeViewModel parent) {
188188
}
189189

190190
String grpName = preferences.getLibraryPreferences().getAddImportedEntriesGroupName();
191-
AbstractGroup importEntriesGroup = new SmartGroup(grpName, GroupHierarchyType.INDEPENDENT, ',');
191+
AbstractGroup importEntriesGroup = new ExplicitGroup(grpName, GroupHierarchyType.INDEPENDENT, ',');
192192
boolean isGrpExist = parent.getGroupNode()
193193
.getChildren()
194194
.stream()
195195
.map(GroupTreeNode::getGroup)
196-
.anyMatch(grp -> grp instanceof SmartGroup);
196+
.anyMatch(grp -> grp instanceof ExplicitGroup && grp.getName().equals(grpName));
197197
if (!isGrpExist) {
198198
currentDatabase.ifPresent(db -> {
199199
GroupTreeNode newSubgroup = parent.addSubgroup(importEntriesGroup);
@@ -251,14 +251,14 @@ public void addSuggestedGroups(GroupNodeViewModel parent) {
251251
List<GroupTreeNode> newSuggestedSubgroups = new ArrayList<>();
252252

253253
// 1. Create "Entries without linked files" group if it doesn't exist
254-
SearchGroup withoutFilesGroup = JabRefSuggestedGroups.createWithoutFilesGroup();
254+
SearchGroup withoutFilesGroup = GroupsFactory.createWithoutFilesGroup();
255255
if (!parent.hasSimilarSearchGroup(withoutFilesGroup)) {
256256
GroupTreeNode subGroup = rootNode.addSubgroup(withoutFilesGroup);
257257
newSuggestedSubgroups.add(subGroup);
258258
}
259259

260260
// 2. Create "Entries without groups" group if it doesn't exist
261-
SearchGroup withoutGroupsGroup = JabRefSuggestedGroups.createWithoutGroupsGroup();
261+
SearchGroup withoutGroupsGroup = GroupsFactory.createWithoutGroupsGroup();
262262
if (!parent.hasSimilarSearchGroup(withoutGroupsGroup)) {
263263
GroupTreeNode subGroup = rootNode.addSubgroup(withoutGroupsGroup);
264264
newSuggestedSubgroups.add(subGroup);

jabgui/src/main/java/org/jabref/migrations/ConvertMarkingToGroups.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import javafx.collections.ObservableList;
1111

12-
import org.jabref.logic.groups.DefaultGroupsFactory;
12+
import org.jabref.logic.groups.GroupsFactory;
1313
import org.jabref.logic.importer.ParserResult;
1414
import org.jabref.logic.l10n.Localization;
1515
import org.jabref.model.entry.BibEntry;
@@ -48,7 +48,7 @@ public void performMigration(@NonNull ParserResult parserResult) {
4848
}
4949

5050
if (parserResult.getMetaData().getGroups().isEmpty()) {
51-
parserResult.getMetaData().setGroups(GroupTreeNode.fromGroup(DefaultGroupsFactory.getAllEntriesGroup()));
51+
parserResult.getMetaData().setGroups(GroupTreeNode.fromGroup(GroupsFactory.getAllEntriesGroup()));
5252
}
5353
GroupTreeNode root = parserResult.getMetaData().getGroups().get();
5454
root.addChild(markingRoot, 0);

jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.jabref.gui.util.CustomLocalDragboard;
1313
import org.jabref.logic.LibraryPreferences;
1414
import org.jabref.logic.ai.AiService;
15+
import org.jabref.logic.groups.GroupsFactory;
1516
import org.jabref.logic.util.CurrentThreadTaskExecutor;
1617
import org.jabref.logic.util.TaskExecutor;
1718
import org.jabref.model.database.BibDatabaseContext;
@@ -173,7 +174,7 @@ void shouldAddsAllSuggestedGroupsWhenNoneExist() {
173174
void shouldAddOnlyMissingGroup() {
174175
GroupTreeViewModel model = new GroupTreeViewModel(stateManager, dialogService, mock(AiService.class), preferences, mock(AdaptVisibleTabs.class), taskExecutor, new CustomLocalDragboard());
175176
GroupNodeViewModel rootGroup = model.rootGroupProperty().getValue();
176-
rootGroup.getGroupNode().addSubgroup(JabRefSuggestedGroups.createWithoutFilesGroup());
177+
rootGroup.getGroupNode().addSubgroup(GroupsFactory.createWithoutFilesGroup());
177178
assertEquals(1, rootGroup.getChildren().size());
178179

179180
model.addSuggestedGroups(rootGroup);
@@ -186,8 +187,8 @@ void shouldAddOnlyMissingGroup() {
186187
void shouldNotAddSuggestedGroupsWhenAllExist() {
187188
GroupTreeViewModel model = new GroupTreeViewModel(stateManager, dialogService, mock(AiService.class), preferences, mock(AdaptVisibleTabs.class), taskExecutor, new CustomLocalDragboard());
188189
GroupNodeViewModel rootGroup = model.rootGroupProperty().getValue();
189-
rootGroup.getGroupNode().addSubgroup(JabRefSuggestedGroups.createWithoutFilesGroup());
190-
rootGroup.getGroupNode().addSubgroup(JabRefSuggestedGroups.createWithoutGroupsGroup());
190+
rootGroup.getGroupNode().addSubgroup(GroupsFactory.createWithoutFilesGroup());
191+
rootGroup.getGroupNode().addSubgroup(GroupsFactory.createWithoutGroupsGroup());
191192
assertEquals(2, rootGroup.getChildren().size());
192193

193194
model.addSuggestedGroups(rootGroup);

jabgui/src/test/java/org/jabref/migrations/ConvertMarkingToGroupsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.Optional;
44
import java.util.Set;
55

6-
import org.jabref.logic.groups.DefaultGroupsFactory;
6+
import org.jabref.logic.groups.GroupsFactory;
77
import org.jabref.logic.importer.ParserResult;
88
import org.jabref.model.entry.BibEntry;
99
import org.jabref.model.entry.field.InternalField;
@@ -24,7 +24,7 @@ void performMigrationForSingleEntry() {
2424

2525
new ConvertMarkingToGroups().performMigration(parserResult);
2626

27-
GroupTreeNode rootExpected = GroupTreeNode.fromGroup(DefaultGroupsFactory.getAllEntriesGroup());
27+
GroupTreeNode rootExpected = GroupTreeNode.fromGroup(GroupsFactory.getAllEntriesGroup());
2828
GroupTreeNode markings = rootExpected.addSubgroup(new ExplicitGroup("Markings", GroupHierarchyType.INCLUDING, ','));
2929
markings.addSubgroup(new ExplicitGroup("Nicolas:6", GroupHierarchyType.INCLUDING, ','));
3030

0 commit comments

Comments
 (0)