From 2732800d3b44a0939eb727858711f7641db6b16f Mon Sep 17 00:00:00 2001
From: Ritij Paudel <43158841+paudelritij@users.noreply.github.com>
Date: Fri, 25 Apr 2025 00:23:31 +0930
Subject: [PATCH 1/7] Add field to configure imported entries group under web
search preference
---
.../preferences/websearch/WebSearchTab.fxml | 4 +++
.../preferences/websearch/WebSearchTab.java | 6 ++++
.../websearch/WebSearchTabViewModel.java | 27 ++++++++++++++++
.../org/jabref/logic/LibraryPreferences.java | 32 ++++++++++++++++++-
.../preferences/JabRefCliPreferences.java | 13 +++++++-
src/main/resources/l10n/JabRef_en.properties | 2 ++
6 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml b/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml
index 574112bc8ab..6675f474304 100644
--- a/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml
+++ b/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml
@@ -21,6 +21,10 @@
+
+
+
+
diff --git a/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.java b/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.java
index f842ba1233e..2a9073041d0 100644
--- a/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.java
+++ b/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.java
@@ -33,6 +33,8 @@ public class WebSearchTab extends AbstractPreferenceTabView defaultPlainCitationParser;
@FXML private CheckBox useCustomDOI;
@@ -76,6 +78,10 @@ public void initialize() {
downloadLinkedOnlineFiles.selectedProperty().bindBidirectional(viewModel.shouldDownloadLinkedOnlineFiles());
keepDownloadUrl.selectedProperty().bindBidirectional(viewModel.shouldKeepDownloadUrl());
+ addImportedEntries.selectedProperty().bindBidirectional(viewModel.getAddImportedEntries());
+ addImportedEntriesGroupName.textProperty().bindBidirectional(viewModel.getAddImportedEntriesGroupName());
+ addImportedEntriesGroupName.disableProperty().bind(addImportedEntries.selectedProperty().not());
+
new ViewModelListCellFactory()
.withText(PlainCitationParserChoice::getLocalizedName)
.install(defaultPlainCitationParser);
diff --git a/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTabViewModel.java b/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTabViewModel.java
index ced3fc6a146..800303a513b 100644
--- a/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTabViewModel.java
+++ b/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTabViewModel.java
@@ -21,6 +21,7 @@
import org.jabref.gui.preferences.PreferenceTabViewModel;
import org.jabref.gui.slr.StudyCatalogItem;
import org.jabref.logic.FilePreferences;
+import org.jabref.logic.LibraryPreferences;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.SearchBasedFetcher;
@@ -48,6 +49,9 @@ public class WebSearchTabViewModel implements PreferenceTabViewModel {
new SimpleListProperty<>(FXCollections.observableArrayList(PlainCitationParserChoice.values()));
private final ObjectProperty defaultPlainCitationParser = new SimpleObjectProperty<>();
+ private final BooleanProperty addImportedEntries = new SimpleBooleanProperty();
+ private final StringProperty addImportedEntriesGroupName = new SimpleStringProperty("");
+
private final BooleanProperty useCustomDOIProperty = new SimpleBooleanProperty();
private final StringProperty useCustomDOINameProperty = new SimpleStringProperty("");
@@ -67,6 +71,7 @@ public class WebSearchTabViewModel implements PreferenceTabViewModel {
private final ImporterPreferences importerPreferences;
private final FilePreferences filePreferences;
private final ImportFormatPreferences importFormatPreferences;
+ private final LibraryPreferences libraryPreferences;
private final ReadOnlyBooleanProperty refAiEnabled;
@@ -78,6 +83,7 @@ public WebSearchTabViewModel(CliPreferences preferences, DialogService dialogSer
this.doiPreferences = preferences.getDOIPreferences();
this.filePreferences = preferences.getFilePreferences();
this.importFormatPreferences = preferences.getImportFormatPreferences();
+ this.libraryPreferences = preferences.getLibraryPreferences();
this.refAiEnabled = refAiEnabled;
@@ -128,6 +134,12 @@ public void setValues() {
warnAboutDuplicatesOnImportProperty.setValue(importerPreferences.shouldWarnAboutDuplicatesOnImport());
shouldDownloadLinkedOnlineFiles.setValue(filePreferences.shouldDownloadLinkedFiles());
shouldkeepDownloadUrl.setValue(filePreferences.shouldKeepDownloadUrl());
+ addImportedEntries.setValue(libraryPreferences.isAddImportedEntriesEnabled());
+ if (libraryPreferences.getAddImportedEntriesGroupName().isEmpty()) {
+ addImportedEntriesGroupName.setValue(Localization.lang("Imported entries"));
+ } else {
+ addImportedEntriesGroupName.setValue(libraryPreferences.getAddImportedEntriesGroupName());
+ }
defaultPlainCitationParser.setValue(importerPreferences.getDefaultPlainCitationParser());
useCustomDOIProperty.setValue(doiPreferences.isUseCustom());
@@ -159,7 +171,14 @@ public void storeSettings() {
importerPreferences.setWarnAboutDuplicatesOnImport(warnAboutDuplicatesOnImportProperty.getValue());
filePreferences.setDownloadLinkedFiles(shouldDownloadLinkedOnlineFiles.getValue());
filePreferences.setKeepDownloadUrl(shouldkeepDownloadUrl.getValue());
+ libraryPreferences.setAddImportedEntries(addImportedEntries.getValue());
+ if (addImportedEntriesGroupName.getValue().isEmpty() || addImportedEntriesGroupName.getValue().startsWith(" ")) {
+ libraryPreferences.setAddImportedEntriesGroupName("");
+ } else {
+ libraryPreferences.setAddImportedEntriesGroupName(addImportedEntriesGroupName.getValue());
+ }
importerPreferences.setDefaultPlainCitationParser(defaultPlainCitationParser.getValue());
+
grobidPreferences.setGrobidEnabled(grobidEnabledProperty.getValue());
grobidPreferences.setGrobidUseAsked(grobidPreferences.isGrobidUseAsked());
grobidPreferences.setGrobidURL(grobidURLProperty.getValue());
@@ -189,6 +208,14 @@ public ObjectProperty defaultPlainCitationParserPrope
return defaultPlainCitationParser;
}
+ public BooleanProperty getAddImportedEntries() {
+ return addImportedEntries;
+ }
+
+ public StringProperty getAddImportedEntriesGroupName() {
+ return addImportedEntriesGroupName;
+ }
+
public BooleanProperty useCustomDOIProperty() {
return this.useCustomDOIProperty;
}
diff --git a/src/main/java/org/jabref/logic/LibraryPreferences.java b/src/main/java/org/jabref/logic/LibraryPreferences.java
index 64ca8501de0..31ae85d78a2 100644
--- a/src/main/java/org/jabref/logic/LibraryPreferences.java
+++ b/src/main/java/org/jabref/logic/LibraryPreferences.java
@@ -4,6 +4,8 @@
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.property.SimpleStringProperty;
+import javafx.beans.property.StringProperty;
import org.jabref.model.database.BibDatabaseMode;
@@ -12,13 +14,17 @@ public class LibraryPreferences {
private final ObjectProperty defaultBibDatabaseMode;
private final BooleanProperty alwaysReformatOnSave;
private final BooleanProperty autoSave;
+ private final BooleanProperty addImportedEntries;
+ private final StringProperty addImportedEntriesGroupName;
public LibraryPreferences(BibDatabaseMode defaultBibDatabaseMode,
boolean alwaysReformatOnSave,
- boolean autoSave) {
+ boolean autoSave, boolean addImportedEntries, String addImportedEntriesGroupName) {
this.defaultBibDatabaseMode = new SimpleObjectProperty<>(defaultBibDatabaseMode);
this.alwaysReformatOnSave = new SimpleBooleanProperty(alwaysReformatOnSave);
this.autoSave = new SimpleBooleanProperty(autoSave);
+ this.addImportedEntries = new SimpleBooleanProperty(addImportedEntries);
+ this.addImportedEntriesGroupName = new SimpleStringProperty(addImportedEntriesGroupName);
}
public BibDatabaseMode getDefaultBibDatabaseMode() {
@@ -56,4 +62,28 @@ public BooleanProperty autoSaveProperty() {
public void setAutoSave(boolean shouldAutoSave) {
this.autoSave.set(shouldAutoSave);
}
+
+ public boolean isAddImportedEntriesEnabled() {
+ return addImportedEntries.get();
+ }
+
+ public BooleanProperty addImportedEntriesProperty() {
+ return addImportedEntries;
+ }
+
+ public void setAddImportedEntries(boolean addImportedEntries) {
+ this.addImportedEntries.set(addImportedEntries);
+ }
+
+ public String getAddImportedEntriesGroupName() {
+ return addImportedEntriesGroupName.get();
+ }
+
+ public StringProperty addImportedEntriesGroupNameProperty() {
+ return addImportedEntriesGroupName;
+ }
+
+ public void setAddImportedEntriesGroupName(String addImportedEntriesGroupName) {
+ this.addImportedEntriesGroupName.set(addImportedEntriesGroupName);
+ }
}
diff --git a/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java b/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java
index 7df1c943415..eeb948fe2c6 100644
--- a/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java
+++ b/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java
@@ -171,6 +171,9 @@ public class JabRefCliPreferences implements CliPreferences {
public static final String MEMORY_STICK_MODE = "memoryStickMode";
public static final String DEFAULT_ENCODING = "defaultEncoding";
+ private static final String ADD_IMPORTED_ENTRIES = "addImportedEntries";
+ private static final String ADD_IMPORTED_ENTRIES_GROUP_NAME = "addImportedEntriesGroupName";
+
public static final String BASE_DOI_URI = "baseDOIURI";
public static final String USE_CUSTOM_DOI_URI = "useCustomDOIURI";
@@ -470,6 +473,9 @@ protected JabRefCliPreferences() {
defaults.put(IMPORTERS_ENABLED, Boolean.TRUE);
defaults.put(GENERATE_KEY_ON_IMPORT, Boolean.TRUE);
+ defaults.put(ADD_IMPORTED_ENTRIES, Boolean.FALSE);
+ defaults.put(ADD_IMPORTED_ENTRIES_GROUP_NAME, Localization.lang("Imported entries"));
+
// region: Grobid
defaults.put(GROBID_ENABLED, Boolean.FALSE);
defaults.put(GROBID_PREFERENCE, Boolean.FALSE);
@@ -1175,12 +1181,17 @@ public LibraryPreferences getLibraryPreferences() {
libraryPreferences = new LibraryPreferences(
getBoolean(BIBLATEX_DEFAULT_MODE) ? BibDatabaseMode.BIBLATEX : BibDatabaseMode.BIBTEX,
getBoolean(REFORMAT_FILE_ON_SAVE_AND_EXPORT),
- getBoolean(LOCAL_AUTO_SAVE));
+ getBoolean(LOCAL_AUTO_SAVE),
+ getBoolean(ADD_IMPORTED_ENTRIES),
+ get(ADD_IMPORTED_ENTRIES_GROUP_NAME));
EasyBind.listen(libraryPreferences.defaultBibDatabaseModeProperty(), (obs, oldValue, newValue) -> putBoolean(BIBLATEX_DEFAULT_MODE, (newValue == BibDatabaseMode.BIBLATEX)));
EasyBind.listen(libraryPreferences.alwaysReformatOnSaveProperty(), (obs, oldValue, newValue) -> putBoolean(REFORMAT_FILE_ON_SAVE_AND_EXPORT, newValue));
EasyBind.listen(libraryPreferences.autoSaveProperty(), (obs, oldValue, newValue) -> putBoolean(LOCAL_AUTO_SAVE, newValue));
+ EasyBind.listen(libraryPreferences.addImportedEntriesProperty(), (obs, oldValue, newValue) -> putBoolean(ADD_IMPORTED_ENTRIES, newValue));
+ EasyBind.listen(libraryPreferences.addImportedEntriesGroupNameProperty(), (obs, oldValue, newValue) -> put(ADD_IMPORTED_ENTRIES_GROUP_NAME, newValue));
+
return libraryPreferences;
}
diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties
index 0b4b2bc6b97..030d3af2e00 100644
--- a/src/main/resources/l10n/JabRef_en.properties
+++ b/src/main/resources/l10n/JabRef_en.properties
@@ -2459,6 +2459,8 @@ Unprotect\ terms=Unprotect terms
Generate\ a\ new\ key\ for\ imported\ entries\ (overwriting\ their\ default)=Generate a new key for imported entries (overwriting their default)
Warn\ about\ duplicates\ on\ import=Warn about duplicates on import
+Add\ imported\ entries\ to\ group=Add imported entries to group
+
Custom\ DOI\ URI=Custom DOI URI
Use\ custom\ DOI\ base\ URI\ for\ article\ access=Use custom DOI base URI for article access
From 91575ba0e3c3542921ae86c3dd17b19715d0535c Mon Sep 17 00:00:00 2001
From: Ritij Paudel <43158841+paudelritij@users.noreply.github.com>
Date: Sun, 4 May 2025 22:00:32 +0930
Subject: [PATCH 2/7] Add 'Import entries' group feature for web import entries
---
.../gui/externalfiles/ImportHandler.java | 16 +++++++
.../jabref/gui/groups/GroupDescriptions.java | 5 ++
.../jabref/gui/groups/GroupNodeViewModel.java | 11 +++--
.../gui/groups/GroupTreeNodeViewModel.java | 3 ++
.../jabref/gui/groups/GroupTreeViewModel.java | 25 ++++++++++
.../gui/groups/GroupTreeViewModelTest.java | 8 ++++
.../org/jabref/logic/LibraryPreferences.java | 4 +-
.../logic/exporter/GroupSerializer.java | 15 ++++++
.../logic/importer/util/GroupsParser.java | 22 +++++++++
.../preferences/JabRefCliPreferences.java | 1 -
.../MetadataSerializationConfiguration.java | 6 +++
.../org/jabref/model/groups/SmartGroup.java | 47 +++++++++++++++++++
.../main/resources/l10n/JabRef_en.properties | 1 -
.../logic/exporter/GroupSerializerTest.java | 9 ++++
14 files changed, 166 insertions(+), 7 deletions(-)
create mode 100644 jablib/src/main/java/org/jabref/model/groups/SmartGroup.java
diff --git a/jabgui/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/jabgui/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
index 9e0ad415be5..67ba9c2ad40 100644
--- a/jabgui/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
+++ b/jabgui/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
@@ -56,6 +56,7 @@
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.groups.GroupEntryChanger;
import org.jabref.model.groups.GroupTreeNode;
+import org.jabref.model.groups.SmartGroup;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.model.util.OptionalUtil;
@@ -164,6 +165,7 @@ public List call() {
// Modifiers do not work on macOS: https://bugs.openjdk.org/browse/JDK-8264172
// Similar code as org.jabref.gui.preview.PreviewPanel.PreviewPanel
DragDrop.handleDropOfFiles(List.of(file), transferMode, fileLinker, entry);
+ addToImportEntriesGroup(pdfEntriesInFile);
entriesToAdd.addAll(pdfEntriesInFile);
addResultToList(file, true, Localization.lang("File was successfully imported as a new entry"));
});
@@ -263,6 +265,7 @@ private void importEntryWithDuplicateCheck(BibDatabaseContext bibDatabaseContext
finalEntry = duplicateHandledEntry.get();
}
importCleanedEntries(bibDatabaseContext, List.of(finalEntry));
+ addToImportEntriesGroup(List.of(finalEntry));
downloadLinkedFiles(finalEntry);
BibEntry entryToFocus = finalEntry;
stateManager.activeTabProperty().get().ifPresent(tab -> tab.clearAndSelect(entryToFocus));
@@ -501,4 +504,17 @@ private List handlePdfUrl(String pdfUrl) throws IOException {
return List.of();
}
}
+
+ private void addToImportEntriesGroup(List entryToInsert) {
+ if (preferences.getLibraryPreferences().isAddImportedEntriesEnabled()) {
+ // Only one SmartGroup
+ this.bibDatabaseContext.getMetaData()
+ .getGroups()
+ .flatMap(grp -> grp.getChildren()
+ .stream()
+ .filter(node -> node.getGroup() instanceof SmartGroup)
+ .findFirst())
+ .ifPresent(smtGrp -> smtGrp.addEntriesToGroup(entryToInsert));
+ }
+ }
}
diff --git a/jabgui/src/main/java/org/jabref/gui/groups/GroupDescriptions.java b/jabgui/src/main/java/org/jabref/gui/groups/GroupDescriptions.java
index 5023f77e5f0..606f7a586a9 100644
--- a/jabgui/src/main/java/org/jabref/gui/groups/GroupDescriptions.java
+++ b/jabgui/src/main/java/org/jabref/gui/groups/GroupDescriptions.java
@@ -4,6 +4,7 @@
import org.jabref.model.groups.ExplicitGroup;
import org.jabref.model.groups.KeywordGroup;
import org.jabref.model.groups.SearchGroup;
+import org.jabref.model.groups.SmartGroup;
import org.jabref.model.strings.StringUtil;
public class GroupDescriptions {
@@ -61,6 +62,10 @@ public static String getShortDescriptionAllEntriesGroup() {
return Localization.lang("All Entries (this group cannot be edited or removed)");
}
+ public static String getShortDescriptionSmartGroup(SmartGroup smartGroup) {
+ return Localization.lang("Smart Group (Import Entries)");
+ }
+
public static String getShortDescription(SearchGroup searchGroup, boolean showDynamic) {
StringBuilder sb = new StringBuilder();
sb.append("");
diff --git a/jabgui/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java b/jabgui/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java
index 718fc45229d..f2782ff656c 100644
--- a/jabgui/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java
+++ b/jabgui/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java
@@ -46,6 +46,7 @@
import org.jabref.model.groups.LastNameGroup;
import org.jabref.model.groups.RegexKeywordGroup;
import org.jabref.model.groups.SearchGroup;
+import org.jabref.model.groups.SmartGroup;
import org.jabref.model.groups.TexGroup;
import org.jabref.model.search.event.IndexAddedOrUpdatedEvent;
import org.jabref.model.search.event.IndexClosedEvent;
@@ -416,6 +417,8 @@ public boolean canAddEntriesIn() {
AbstractGroup group = groupNode.getGroup();
if (group instanceof AllEntriesGroup) {
return false;
+ } else if (group instanceof SmartGroup) {
+ return false;
} else if (group instanceof ExplicitGroup) {
return true;
} else if (group instanceof LastNameGroup || group instanceof RegexKeywordGroup) {
@@ -442,7 +445,7 @@ public boolean canAddEntriesIn() {
public boolean canBeDragged() {
AbstractGroup group = groupNode.getGroup();
return switch (group) {
- case AllEntriesGroup _ -> false;
+ case AllEntriesGroup _, SmartGroup _ -> false;
case ExplicitGroup _, SearchGroup _, AutomaticKeywordGroup _, AutomaticPersonsGroup _, TexGroup _ -> true;
case KeywordGroup _ ->
// KeywordGroup is parent of LastNameGroup, RegexKeywordGroup and WordKeywordGroup
@@ -461,13 +464,13 @@ public boolean canAddGroupsIn() {
AbstractGroup group = groupNode.getGroup();
return switch (group) {
case AllEntriesGroup _, ExplicitGroup _, SearchGroup _, TexGroup _ -> true;
+ case AutomaticKeywordGroup _, AutomaticPersonsGroup _, SmartGroup _ -> false;
case KeywordGroup _ ->
// KeywordGroup is parent of LastNameGroup, RegexKeywordGroup and WordKeywordGroup
groupNode.getParent()
.map(GroupTreeNode::getGroup)
.map(groupParent -> !(groupParent instanceof AutomaticKeywordGroup || groupParent instanceof AutomaticPersonsGroup))
.orElse(false);
- case AutomaticKeywordGroup _, AutomaticPersonsGroup _ -> false;
case null -> throw new IllegalArgumentException("Group cannot be null");
default -> throw new UnsupportedOperationException("canAddGroupsIn method not yet implemented in group: " + group.getClass().getName());
};
@@ -476,7 +479,7 @@ public boolean canAddGroupsIn() {
public boolean canRemove() {
AbstractGroup group = groupNode.getGroup();
return switch (group) {
- case AllEntriesGroup _ -> false;
+ case AllEntriesGroup _, SmartGroup _ -> false;
case ExplicitGroup _, SearchGroup _, AutomaticKeywordGroup _, AutomaticPersonsGroup _, TexGroup _ -> true;
case KeywordGroup _ ->
// KeywordGroup is parent of LastNameGroup, RegexKeywordGroup and WordKeywordGroup
@@ -492,7 +495,7 @@ public boolean canRemove() {
public boolean isEditable() {
AbstractGroup group = groupNode.getGroup();
return switch (group) {
- case AllEntriesGroup _ -> false;
+ case AllEntriesGroup _, SmartGroup _ -> false;
case ExplicitGroup _, SearchGroup _, AutomaticKeywordGroup _, AutomaticPersonsGroup _, TexGroup _ -> true;
case KeywordGroup _ ->
// KeywordGroup is parent of LastNameGroup, RegexKeywordGroup and WordKeywordGroup
diff --git a/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeNodeViewModel.java b/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeNodeViewModel.java
index 38f9c532988..d8f454931da 100644
--- a/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeNodeViewModel.java
+++ b/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeNodeViewModel.java
@@ -17,6 +17,7 @@
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.groups.KeywordGroup;
import org.jabref.model.groups.SearchGroup;
+import org.jabref.model.groups.SmartGroup;
public class GroupTreeNodeViewModel {
private final GroupTreeNode node;
@@ -51,6 +52,8 @@ public String getDescription() {
String shortDescription = "";
boolean showDynamic = true;
shortDescription = switch (group) {
+ case SmartGroup smartGroup ->
+ GroupDescriptions.getShortDescriptionSmartGroup(smartGroup);
case ExplicitGroup explicitGroup ->
GroupDescriptions.getShortDescriptionExplicitGroup(explicitGroup);
case KeywordGroup keywordGroup ->
diff --git a/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
index c744909d56e..bceeaa220bc 100644
--- a/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
+++ b/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
@@ -36,9 +36,11 @@
import org.jabref.model.groups.AutomaticKeywordGroup;
import org.jabref.model.groups.AutomaticPersonsGroup;
import org.jabref.model.groups.ExplicitGroup;
+import org.jabref.model.groups.GroupHierarchyType;
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.groups.RegexKeywordGroup;
import org.jabref.model.groups.SearchGroup;
+import org.jabref.model.groups.SmartGroup;
import org.jabref.model.groups.TexGroup;
import org.jabref.model.groups.WordKeywordGroup;
import org.jabref.model.metadata.MetaData;
@@ -172,6 +174,29 @@ private void onActiveDatabaseChanged(Optional newDatabase) {
rootGroup.setValue(null);
}
currentDatabase = newDatabase;
+ newDatabase.ifPresent(db -> addGroupImportEntries(rootGroup.get()));
+ }
+
+ private void addGroupImportEntries(GroupNodeViewModel parent) {
+ if (!preferences.getLibraryPreferences().isAddImportedEntriesEnabled()) {
+ return;
+ }
+
+ String grpName = preferences.getLibraryPreferences().getAddImportedEntriesGroupName();
+ AbstractGroup importEntriesGroup = new SmartGroup(grpName, GroupHierarchyType.INDEPENDENT, ',');
+ boolean isGrpExist = parent.getGroupNode()
+ .getChildren()
+ .stream()
+ .map(GroupTreeNode::getGroup)
+ .anyMatch(grp -> grp instanceof SmartGroup);
+ if (!isGrpExist) {
+ currentDatabase.ifPresent(db -> {
+ GroupTreeNode newSubgroup = parent.addSubgroup(importEntriesGroup);
+ newSubgroup.moveTo(parent.getGroupNode(), 0);
+ selectedGroups.setAll(new GroupNodeViewModel(db, stateManager, taskExecutor, newSubgroup, localDragboard, preferences));
+ writeGroupChangesToMetaData();
+ });
+ }
}
/**
diff --git a/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java b/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java
index fd3b781a4b6..c4fca8ea0ea 100644
--- a/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java
+++ b/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java
@@ -7,6 +7,7 @@
import org.jabref.gui.StateManager;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.util.CustomLocalDragboard;
+import org.jabref.logic.LibraryPreferences;
import org.jabref.logic.ai.AiService;
import org.jabref.logic.util.CurrentThreadTaskExecutor;
import org.jabref.logic.util.TaskExecutor;
@@ -47,6 +48,13 @@ void setUp() {
preferences = mock(GuiPreferences.class);
dialogService = mock(DialogService.class, Answers.RETURNS_DEEP_STUBS);
+ when(preferences.getLibraryPreferences()).thenReturn(new LibraryPreferences(
+ databaseContext.getMode(),
+ false,
+ false,
+ false,
+ "Imported entries"
+ ));
when(preferences.getGroupsPreferences()).thenReturn(new GroupsPreferences(
EnumSet.noneOf(GroupViewMode.class),
true,
diff --git a/jablib/src/main/java/org/jabref/logic/LibraryPreferences.java b/jablib/src/main/java/org/jabref/logic/LibraryPreferences.java
index 31ae85d78a2..05d67e04d85 100644
--- a/jablib/src/main/java/org/jabref/logic/LibraryPreferences.java
+++ b/jablib/src/main/java/org/jabref/logic/LibraryPreferences.java
@@ -19,7 +19,9 @@ public class LibraryPreferences {
public LibraryPreferences(BibDatabaseMode defaultBibDatabaseMode,
boolean alwaysReformatOnSave,
- boolean autoSave, boolean addImportedEntries, String addImportedEntriesGroupName) {
+ boolean autoSave,
+ boolean addImportedEntries,
+ String addImportedEntriesGroupName) {
this.defaultBibDatabaseMode = new SimpleObjectProperty<>(defaultBibDatabaseMode);
this.alwaysReformatOnSave = new SimpleBooleanProperty(alwaysReformatOnSave);
this.autoSave = new SimpleBooleanProperty(autoSave);
diff --git a/jablib/src/main/java/org/jabref/logic/exporter/GroupSerializer.java b/jablib/src/main/java/org/jabref/logic/exporter/GroupSerializer.java
index 32de0e8aedc..f74a6195157 100644
--- a/jablib/src/main/java/org/jabref/logic/exporter/GroupSerializer.java
+++ b/jablib/src/main/java/org/jabref/logic/exporter/GroupSerializer.java
@@ -17,6 +17,7 @@
import org.jabref.model.groups.KeywordGroup;
import org.jabref.model.groups.RegexKeywordGroup;
import org.jabref.model.groups.SearchGroup;
+import org.jabref.model.groups.SmartGroup;
import org.jabref.model.groups.TexGroup;
import org.jabref.model.search.SearchFlags;
import org.jabref.model.strings.StringUtil;
@@ -26,6 +27,19 @@ private static String serializeAllEntriesGroup() {
return MetadataSerializationConfiguration.ALL_ENTRIES_GROUP_ID;
}
+ private String serializeSmartGroup(SmartGroup group) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(MetadataSerializationConfiguration.SMART_GROUP_ID);
+ sb.append(StringUtil.quote(group.getName(), MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR));
+ sb.append(MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR);
+ sb.append(group.getHierarchicalContext().ordinal());
+ sb.append(MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR);
+
+ appendGroupDetails(sb, group);
+
+ return sb.toString();
+ }
+
private String serializeExplicitGroup(ExplicitGroup group) {
StringBuilder sb = new StringBuilder();
sb.append(MetadataSerializationConfiguration.EXPLICIT_GROUP_ID);
@@ -116,6 +130,7 @@ public List serializeTree(GroupTreeNode node) {
private String serializeGroup(AbstractGroup group) {
return switch (group) {
case AllEntriesGroup _ -> serializeAllEntriesGroup();
+ case SmartGroup smartGroup -> serializeSmartGroup(smartGroup);
case ExplicitGroup explicitGroup -> serializeExplicitGroup(explicitGroup);
case KeywordGroup keywordGroup -> serializeKeywordGroup(keywordGroup);
case SearchGroup searchGroup -> serializeSearchGroup(searchGroup);
diff --git a/jablib/src/main/java/org/jabref/logic/importer/util/GroupsParser.java b/jablib/src/main/java/org/jabref/logic/importer/util/GroupsParser.java
index 35ed1908479..f7e77cd11ce 100644
--- a/jablib/src/main/java/org/jabref/logic/importer/util/GroupsParser.java
+++ b/jablib/src/main/java/org/jabref/logic/importer/util/GroupsParser.java
@@ -24,6 +24,7 @@
import org.jabref.model.groups.KeywordGroup;
import org.jabref.model.groups.RegexKeywordGroup;
import org.jabref.model.groups.SearchGroup;
+import org.jabref.model.groups.SmartGroup;
import org.jabref.model.groups.TexGroup;
import org.jabref.model.groups.WordKeywordGroup;
import org.jabref.model.metadata.MetaData;
@@ -99,6 +100,9 @@ public static AbstractGroup fromString(String s, Character keywordSeparator, Fil
if (s.startsWith(MetadataSerializationConfiguration.ALL_ENTRIES_GROUP_ID)) {
return allEntriesGroupFromString(s);
}
+ if (s.startsWith(MetadataSerializationConfiguration.SMART_GROUP_ID)) {
+ return smartGroupFromString(s, keywordSeparator);
+ }
if (s.startsWith(MetadataSerializationConfiguration.SEARCH_GROUP_ID)) {
return searchGroupFromString(s);
}
@@ -206,6 +210,24 @@ private static KeywordGroup keywordGroupFromString(String s, Character keywordSe
return newGroup;
}
+ private static SmartGroup smartGroupFromString(String input, Character keywordSeparator) throws ParseException {
+ if (!input.startsWith(MetadataSerializationConfiguration.SMART_GROUP_ID)) {
+ throw new IllegalArgumentException("SmartGroup cannot be created from \"" + input + "\".");
+ }
+ QuotedStringTokenizer tok = new QuotedStringTokenizer(input.substring(MetadataSerializationConfiguration.SMART_GROUP_ID.length()),
+ MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
+
+ String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
+ try {
+ int context = Integer.parseInt(tok.nextToken());
+ SmartGroup newGroup = new SmartGroup(name, GroupHierarchyType.getByNumberOrDefault(context), keywordSeparator);
+ addGroupDetails(tok, newGroup);
+ return newGroup;
+ } catch (NumberFormatException exception) {
+ throw new ParseException("Could not parse context in " + input);
+ }
+ }
+
private static ExplicitGroup explicitGroupFromString(String input, Character keywordSeparator) throws ParseException {
if (!input.startsWith(MetadataSerializationConfiguration.EXPLICIT_GROUP_ID)) {
throw new IllegalArgumentException("ExplicitGroup cannot be created from \"" + input + "\".");
diff --git a/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java b/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java
index 2be24686434..e0cec03e934 100644
--- a/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java
+++ b/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java
@@ -1131,7 +1131,6 @@ public LibraryPreferences getLibraryPreferences() {
EasyBind.listen(libraryPreferences.defaultBibDatabaseModeProperty(), (obs, oldValue, newValue) -> putBoolean(BIBLATEX_DEFAULT_MODE, newValue == BibDatabaseMode.BIBLATEX));
EasyBind.listen(libraryPreferences.alwaysReformatOnSaveProperty(), (obs, oldValue, newValue) -> putBoolean(REFORMAT_FILE_ON_SAVE_AND_EXPORT, newValue));
EasyBind.listen(libraryPreferences.autoSaveProperty(), (obs, oldValue, newValue) -> putBoolean(LOCAL_AUTO_SAVE, newValue));
-
EasyBind.listen(libraryPreferences.addImportedEntriesProperty(), (obs, oldValue, newValue) -> putBoolean(ADD_IMPORTED_ENTRIES, newValue));
EasyBind.listen(libraryPreferences.addImportedEntriesGroupNameProperty(), (obs, oldValue, newValue) -> put(ADD_IMPORTED_ENTRIES_GROUP_NAME, newValue));
diff --git a/jablib/src/main/java/org/jabref/logic/util/MetadataSerializationConfiguration.java b/jablib/src/main/java/org/jabref/logic/util/MetadataSerializationConfiguration.java
index db99eb45882..81505b53649 100644
--- a/jablib/src/main/java/org/jabref/logic/util/MetadataSerializationConfiguration.java
+++ b/jablib/src/main/java/org/jabref/logic/util/MetadataSerializationConfiguration.java
@@ -6,6 +6,7 @@
import org.jabref.model.groups.ExplicitGroup;
import org.jabref.model.groups.RegexKeywordGroup;
import org.jabref.model.groups.SearchGroup;
+import org.jabref.model.groups.SmartGroup;
import org.jabref.model.groups.TexGroup;
import org.jabref.model.groups.WordKeywordGroup;
@@ -48,6 +49,11 @@ public class MetadataSerializationConfiguration {
*/
public static final String EXPLICIT_GROUP_ID = "StaticGroup:";
+ /**
+ * Identifier for {@link SmartGroup}.
+ */
+ public static final String SMART_GROUP_ID = "SmartGroup:";
+
/**
* Identifier for {@link SearchGroup}.
*/
diff --git a/jablib/src/main/java/org/jabref/model/groups/SmartGroup.java b/jablib/src/main/java/org/jabref/model/groups/SmartGroup.java
new file mode 100644
index 00000000000..1bde951a096
--- /dev/null
+++ b/jablib/src/main/java/org/jabref/model/groups/SmartGroup.java
@@ -0,0 +1,47 @@
+package org.jabref.model.groups;
+
+import java.util.Objects;
+
+import org.jabref.model.entry.field.StandardField;
+
+/**
+ * This group contains entries, which were automatically assigned to it.
+ * Assignments are stored in the {@link StandardField#GROUPS} field.
+ */
+public class SmartGroup extends WordKeywordGroup {
+
+ public SmartGroup(String name, GroupHierarchyType context, Character keywordSeparator) {
+ super(name, context, StandardField.GROUPS, name, true, keywordSeparator, true);
+ }
+
+ @Override
+ public AbstractGroup deepCopy() {
+ return new SmartGroup(getName(), getHierarchicalContext(), keywordSeparator);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof ExplicitGroup other)) {
+ return false;
+ }
+ return Objects.equals(getName(), other.getName())
+ && Objects.equals(getHierarchicalContext(), other.getHierarchicalContext())
+ && Objects.equals(getIconName(), other.getIconName())
+ && Objects.equals(getDescription(), other.getDescription())
+ && Objects.equals(getColor(), other.getColor())
+ && Objects.equals(isExpanded(), other.isExpanded());
+ }
+
+ @Override
+ public boolean isDynamic() {
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name.getValue(), context, iconName, color, description, isExpanded);
+ }
+}
diff --git a/jablib/src/main/resources/l10n/JabRef_en.properties b/jablib/src/main/resources/l10n/JabRef_en.properties
index 1260ce7d5e8..42f07f04124 100644
--- a/jablib/src/main/resources/l10n/JabRef_en.properties
+++ b/jablib/src/main/resources/l10n/JabRef_en.properties
@@ -2431,7 +2431,6 @@ Unprotect\ terms=Unprotect terms
Generate\ a\ new\ key\ for\ imported\ entries\ (overwriting\ their\ default)=Generate a new key for imported entries (overwriting their default)
Warn\ about\ duplicates\ on\ import=Warn about duplicates on import
-
Add\ imported\ entries\ to\ group=Add imported entries to group
Custom\ DOI\ URI=Custom DOI URI
diff --git a/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java b/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java
index 88d7eca19f8..84091a779b6 100644
--- a/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java
+++ b/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
@@ -22,6 +23,7 @@
import org.jabref.model.groups.KeywordGroup;
import org.jabref.model.groups.RegexKeywordGroup;
import org.jabref.model.groups.SearchGroup;
+import org.jabref.model.groups.SmartGroup;
import org.jabref.model.groups.TexGroup;
import org.jabref.model.groups.WordKeywordGroup;
import org.jabref.model.metadata.MetaData;
@@ -51,6 +53,13 @@ void serializeSingleAllEntriesGroup() {
assertEquals(List.of("0 AllEntriesGroup:"), serialization);
}
+ @Test
+ void serializeSmartGroup() {
+ SmartGroup group = new SmartGroup("mySmartGroup", GroupHierarchyType.INDEPENDENT, ',');
+ List serialization = groupSerializer.serializeTree(GroupTreeNode.fromGroup(group));
+ assertEquals(Collections.singletonList("0 SmartGroup:mySmartGroup;0;1;;;;"), serialization);
+ }
+
@Test
void serializeSingleExplicitGroup() {
ExplicitGroup group = new ExplicitGroup("myExplicitGroup", GroupHierarchyType.INDEPENDENT, ',');
From 152cfed3b56e8a59a9a043a202da0c0b4627b90d Mon Sep 17 00:00:00 2001
From: Ritij Paudel <43158841+paudelritij@users.noreply.github.com>
Date: Thu, 8 May 2025 01:16:39 +0930
Subject: [PATCH 3/7] Add few test case
---
.../gui/externalfiles/ImportHandler.java | 4 ++--
.../gui/groups/GroupTreeViewModelTest.java | 24 +++++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/jabgui/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/jabgui/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
index 67ba9c2ad40..966d30a162f 100644
--- a/jabgui/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
+++ b/jabgui/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
@@ -505,7 +505,7 @@ private List handlePdfUrl(String pdfUrl) throws IOException {
}
}
- private void addToImportEntriesGroup(List entryToInsert) {
+ private void addToImportEntriesGroup(List entriesToInsert) {
if (preferences.getLibraryPreferences().isAddImportedEntriesEnabled()) {
// Only one SmartGroup
this.bibDatabaseContext.getMetaData()
@@ -514,7 +514,7 @@ private void addToImportEntriesGroup(List entryToInsert) {
.stream()
.filter(node -> node.getGroup() instanceof SmartGroup)
.findFirst())
- .ifPresent(smtGrp -> smtGrp.addEntriesToGroup(entryToInsert));
+ .ifPresent(smtGrp -> smtGrp.addEntriesToGroup(entriesToInsert));
}
}
}
diff --git a/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java b/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java
index 2b4143aec54..646bfcaa087 100644
--- a/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java
+++ b/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java
@@ -1,6 +1,7 @@
package org.jabref.gui.groups;
import java.util.EnumSet;
+import java.util.List;
import java.util.Optional;
import org.jabref.gui.DialogService;
@@ -192,4 +193,27 @@ void shouldNotAddSuggestedGroupsWhenAllExist() {
assertEquals(2, rootGroup.getChildren().size());
assertTrue(rootGroup.hasAllSuggestedGroups());
}
+
+ @Test
+ void shouldCreateImportedEntriesGroupWhenEnabled() {
+ preferences.getLibraryPreferences().setAddImportedEntries(true);
+
+ List prevModel = groupTree.rootGroupProperty().getValue().getChildren();
+ GroupTreeViewModel model = new GroupTreeViewModel(stateManager, dialogService, mock(AiService.class), preferences, taskExecutor, new CustomLocalDragboard());
+ String actualGrpName = model.rootGroupProperty().getValue().getChildren().getFirst().getDisplayName();
+
+ assertTrue(prevModel.isEmpty());
+ assertEquals("Imported entries", actualGrpName);
+ }
+
+ @Test
+ void shouldReflectUpdatedNameForImportedEntriesGroup() {
+ preferences.getLibraryPreferences().setAddImportedEntries(true);
+ preferences.getLibraryPreferences().setAddImportedEntriesGroupName("Review list");
+
+ GroupTreeViewModel model = new GroupTreeViewModel(stateManager, dialogService, mock(AiService.class), preferences, taskExecutor, new CustomLocalDragboard());
+ String actualGrpName = model.rootGroupProperty().getValue().getChildren().getFirst().getDisplayName();
+
+ assertEquals("Review list", actualGrpName);
+ }
}
From 46dec7a19eeb33d97740c62afff83dd4c4ab1364 Mon Sep 17 00:00:00 2001
From: Ritij Paudel <43158841+paudelritij@users.noreply.github.com>
Date: Thu, 8 May 2025 01:35:05 +0930
Subject: [PATCH 4/7] Add JabRef_en.properties entry and revert access modifier
---
.../org/jabref/logic/preferences/JabRefCliPreferences.java | 4 ++--
jablib/src/main/resources/l10n/JabRef_en.properties | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java b/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java
index e0cec03e934..dc1e724ef59 100644
--- a/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java
+++ b/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java
@@ -168,8 +168,8 @@ public class JabRefCliPreferences implements CliPreferences {
public static final String MEMORY_STICK_MODE = "memoryStickMode";
public static final String DEFAULT_ENCODING = "defaultEncoding";
- private static final String ADD_IMPORTED_ENTRIES = "addImportedEntries";
- private static final String ADD_IMPORTED_ENTRIES_GROUP_NAME = "addImportedEntriesGroupName";
+ public static final String ADD_IMPORTED_ENTRIES = "addImportedEntries";
+ public static final String ADD_IMPORTED_ENTRIES_GROUP_NAME = "addImportedEntriesGroupName";
public static final String BASE_DOI_URI = "baseDOIURI";
public static final String USE_CUSTOM_DOI_URI = "useCustomDOIURI";
diff --git a/jablib/src/main/resources/l10n/JabRef_en.properties b/jablib/src/main/resources/l10n/JabRef_en.properties
index d528adda074..d5be108df69 100644
--- a/jablib/src/main/resources/l10n/JabRef_en.properties
+++ b/jablib/src/main/resources/l10n/JabRef_en.properties
@@ -2438,6 +2438,8 @@ Unprotect\ terms=Unprotect terms
Generate\ a\ new\ key\ for\ imported\ entries\ (overwriting\ their\ default)=Generate a new key for imported entries (overwriting their default)
Warn\ about\ duplicates\ on\ import=Warn about duplicates on import
Add\ imported\ entries\ to\ group=Add imported entries to group
+Smart\ Group\ (Import\ Entries)=Smart Group (Import Entries)
+Imported\ entries=Imported entries
Custom\ DOI\ URI=Custom DOI URI
Use\ custom\ DOI\ base\ URI\ for\ article\ access=Use custom DOI base URI for article access
From 1067b993bbb3567e0e744cf4aa2bd72da3cedf71 Mon Sep 17 00:00:00 2001
From: Ritij Paudel <43158841+paudelritij@users.noreply.github.com>
Date: Sat, 10 May 2025 16:36:20 +0930
Subject: [PATCH 5/7] Fix methods in test
---
.../java/org/jabref/gui/groups/GroupTreeViewModelTest.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java b/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java
index 11af8fbebcc..c7b7e8521e5 100644
--- a/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java
+++ b/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java
@@ -200,10 +200,10 @@ void shouldCreateImportedEntriesGroupWhenEnabled() {
preferences.getLibraryPreferences().setAddImportedEntries(true);
List prevModel = groupTree.rootGroupProperty().getValue().getChildren();
- GroupTreeViewModel model = new GroupTreeViewModel(stateManager, dialogService, mock(AiService.class), preferences, taskExecutor, new CustomLocalDragboard());
+ GroupTreeViewModel model = new GroupTreeViewModel(stateManager, dialogService, mock(AiService.class), preferences, mock(AdaptVisibleTabs.class), taskExecutor, new CustomLocalDragboard());
String actualGrpName = model.rootGroupProperty().getValue().getChildren().getFirst().getDisplayName();
- assertTrue(prevModel.isEmpty());
+ assertEquals(0, prevModel.size());
assertEquals("Imported entries", actualGrpName);
}
@@ -212,7 +212,7 @@ void shouldReflectUpdatedNameForImportedEntriesGroup() {
preferences.getLibraryPreferences().setAddImportedEntries(true);
preferences.getLibraryPreferences().setAddImportedEntriesGroupName("Review list");
- GroupTreeViewModel model = new GroupTreeViewModel(stateManager, dialogService, mock(AiService.class), preferences, taskExecutor, new CustomLocalDragboard());
+ GroupTreeViewModel model = new GroupTreeViewModel(stateManager, dialogService, mock(AiService.class), preferences, mock(AdaptVisibleTabs.class), taskExecutor, new CustomLocalDragboard());
String actualGrpName = model.rootGroupProperty().getValue().getChildren().getFirst().getDisplayName();
assertEquals("Review list", actualGrpName);
From 3ac2590a379c32f41cdae691e8f88a172d8cbda0 Mon Sep 17 00:00:00 2001
From: Ritij Paudel <43158841+paudelritij@users.noreply.github.com>
Date: Sat, 10 May 2025 17:29:00 +0930
Subject: [PATCH 6/7] Add CHANGELOG.md entry
---
CHANGELOG.md | 1 +
.../java/org/jabref/logic/exporter/GroupSerializerTest.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 005c6c1d826..45ba013173a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added the provision to choose different CSL bibliography body formats (e.g. First Line Indent, Hanging Indent, Bibliography 1, etc.) in the LibreOffice integration. [#13049](https://github.com/JabRef/jabref/issues/13049)
- We added "Bibliography Heading" to the available CSL bibliography header formats in the LibreOffice integration. [#13049](https://github.com/JabRef/jabref/issues/13049)
- We added a new button to toggle the file path between an absolute and relative formats in context of library properties. [#13031](https://github.com/JabRef/jabref/issues/13031)
+- We introduced user-configurable group 'Imported entries' for automatic import of entries from web search, PDF import and web fetchers. [#12548](https://github.com/JabRef/jabref/issues/12548)
### Changed
diff --git a/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java b/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java
index 84091a779b6..2eb9557d93e 100644
--- a/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java
+++ b/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java
@@ -57,7 +57,7 @@ void serializeSingleAllEntriesGroup() {
void serializeSmartGroup() {
SmartGroup group = new SmartGroup("mySmartGroup", GroupHierarchyType.INDEPENDENT, ',');
List serialization = groupSerializer.serializeTree(GroupTreeNode.fromGroup(group));
- assertEquals(Collections.singletonList("0 SmartGroup:mySmartGroup;0;1;;;;"), serialization);
+ assertEquals(List.of("0 SmartGroup:mySmartGroup;0;1;;;;"), serialization);
}
@Test
From e5a9dfffc1012a70c9f6f07163b11c159a6ac1ce Mon Sep 17 00:00:00 2001
From: Ritij Paudel <43158841+paudelritij@users.noreply.github.com>
Date: Sat, 10 May 2025 18:31:32 +0930
Subject: [PATCH 7/7] Refactor method for storing and setting group name
---
.../gui/preferences/websearch/WebSearchTabViewModel.java | 8 ++------
.../org/jabref/logic/exporter/GroupSerializerTest.java | 1 -
2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTabViewModel.java b/jabgui/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTabViewModel.java
index 800303a513b..e22198286b4 100644
--- a/jabgui/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTabViewModel.java
+++ b/jabgui/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTabViewModel.java
@@ -135,11 +135,7 @@ public void setValues() {
shouldDownloadLinkedOnlineFiles.setValue(filePreferences.shouldDownloadLinkedFiles());
shouldkeepDownloadUrl.setValue(filePreferences.shouldKeepDownloadUrl());
addImportedEntries.setValue(libraryPreferences.isAddImportedEntriesEnabled());
- if (libraryPreferences.getAddImportedEntriesGroupName().isEmpty()) {
- addImportedEntriesGroupName.setValue(Localization.lang("Imported entries"));
- } else {
- addImportedEntriesGroupName.setValue(libraryPreferences.getAddImportedEntriesGroupName());
- }
+ addImportedEntriesGroupName.setValue(libraryPreferences.getAddImportedEntriesGroupName());
defaultPlainCitationParser.setValue(importerPreferences.getDefaultPlainCitationParser());
useCustomDOIProperty.setValue(doiPreferences.isUseCustom());
@@ -173,7 +169,7 @@ public void storeSettings() {
filePreferences.setKeepDownloadUrl(shouldkeepDownloadUrl.getValue());
libraryPreferences.setAddImportedEntries(addImportedEntries.getValue());
if (addImportedEntriesGroupName.getValue().isEmpty() || addImportedEntriesGroupName.getValue().startsWith(" ")) {
- libraryPreferences.setAddImportedEntriesGroupName("");
+ libraryPreferences.setAddImportedEntriesGroupName(Localization.lang("Imported entries"));
} else {
libraryPreferences.setAddImportedEntriesGroupName(addImportedEntriesGroupName.getValue());
}
diff --git a/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java b/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java
index 2eb9557d93e..035dab28012 100644
--- a/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java
+++ b/jablib/src/test/java/org/jabref/logic/exporter/GroupSerializerTest.java
@@ -3,7 +3,6 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
-import java.util.Collections;
import java.util.EnumSet;
import java.util.List;