Skip to content

Commit 32a9a68

Browse files
authored
Add options to choose groups during import (#13977)
* Add options to choose groups during import * Remove unused import
1 parent 52cf0c3 commit 32a9a68

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
4141
- We added more supported formats of CAYW endpoint of HTTP server. [#13578](https://github.com/JabRef/jabref/issues/13578)
4242
- We added chronological navigation for entries in each library. [#6352](https://github.com/JabRef/jabref/issues/6352)
4343
- We added support for using Medline/Pubmed fetcher with an API key. [#11296](https://github.com/JabRef/jabref/issues/11296#issuecomment-3289005011)
44+
- We added an option to choose the group during import of the entry(s). [#9191](https://github.com/JabRef/jabref/issues/9191)
4445

4546
### Changed
4647

jabgui/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.jabref.gui.importer;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import java.util.Optional;
46

57
import javax.swing.undo.UndoManager;
@@ -49,6 +51,8 @@
4951
import org.jabref.model.database.BibDatabaseContext;
5052
import org.jabref.model.entry.BibEntry;
5153
import org.jabref.model.entry.BibEntryTypesManager;
54+
import org.jabref.model.groups.AllEntriesGroup;
55+
import org.jabref.model.groups.GroupTreeNode;
5256
import org.jabref.model.util.FileUpdateMonitor;
5357

5458
import com.airhacks.afterburner.views.ViewLoader;
@@ -62,6 +66,7 @@ public class ImportEntriesDialog extends BaseDialog<Boolean> {
6266
@FXML private Label pageNumberLabel;
6367
@FXML private CheckListView<BibEntry> entriesListView;
6468
@FXML private ComboBox<BibDatabaseContext> libraryListView;
69+
@FXML private ComboBox<GroupTreeNode> groupListView;
6570
@FXML private ButtonType importButton;
6671
@FXML private Label totalItems;
6772
@FXML private Label selectedItems;
@@ -146,6 +151,7 @@ private void initialize() {
146151
});
147152

148153
libraryListView.setEditable(false);
154+
groupListView.setEditable(false);
149155
libraryListView.getItems().addAll(stateManager.getOpenDatabases());
150156
new ViewModelListCellFactory<BibDatabaseContext>()
151157
.withText(database -> {
@@ -162,6 +168,7 @@ private void initialize() {
162168
.install(libraryListView);
163169
viewModel.selectedDbProperty().bind(libraryListView.getSelectionModel().selectedItemProperty());
164170
stateManager.getActiveDatabase().ifPresent(database1 -> libraryListView.getSelectionModel().select(database1));
171+
setupGroupListView();
165172

166173
PseudoClass entrySelected = PseudoClass.getPseudoClass("selected");
167174
new ViewModelListCellFactory<BibEntry>()
@@ -220,6 +227,48 @@ private void initialize() {
220227
}
221228
}
222229

230+
private void setupGroupListView() {
231+
groupListView.setVisibleRowCount(5);
232+
updateGroupList();
233+
libraryListView.getSelectionModel().selectedItemProperty()
234+
.addListener((_, _, _) -> {
235+
updateGroupList();
236+
});
237+
238+
new ViewModelListCellFactory<GroupTreeNode>()
239+
.withText(group -> group != null ? group.getName() : Localization.lang("No group"))
240+
.install(groupListView);
241+
}
242+
243+
private void updateGroupList() {
244+
groupListView.getItems().clear();
245+
246+
BibDatabaseContext selectedDb = libraryListView.getSelectionModel().getSelectedItem();
247+
if (selectedDb.getMetaData().getGroups().isPresent()) {
248+
GroupTreeNode rootGroup = selectedDb.getMetaData().getGroups().get();
249+
groupListView.getItems().add(rootGroup);
250+
251+
List<GroupTreeNode> allGroups = new ArrayList<>();
252+
collectGroupsFromTree(rootGroup, allGroups);
253+
allGroups.sort((g1, g2) -> g1.getName().compareToIgnoreCase(g2.getName()));
254+
255+
groupListView.getItems().addAll(allGroups);
256+
groupListView.getSelectionModel().select(stateManager.getSelectedGroups(selectedDb).getFirst());
257+
} else {
258+
// No groups defined -> only "All entries"
259+
GroupTreeNode noGroup = new GroupTreeNode(new AllEntriesGroup(Localization.lang("All entries")));
260+
groupListView.getItems().add(noGroup);
261+
groupListView.getSelectionModel().select(noGroup);
262+
}
263+
}
264+
265+
private void collectGroupsFromTree(GroupTreeNode parent, List<GroupTreeNode> groupList) {
266+
for (GroupTreeNode child : parent.getChildren()) {
267+
groupList.add(child);
268+
collectGroupsFromTree(child, groupList);
269+
}
270+
}
271+
223272
private void initializeDialog() {
224273
ViewLoader.view(this)
225274
.load()
@@ -236,7 +285,15 @@ private void initializeDialog() {
236285

237286
setResultConverter(button -> {
238287
if (button == importButton) {
239-
viewModel.importEntries(viewModel.getCheckedEntries().stream().toList(), downloadLinkedOnlineFiles.isSelected());
288+
if (groupListView.getItems().size() > 1) {
289+
// 1 is the "All entries" group, so if more than 1, we have groups defined
290+
GroupTreeNode prevSelectedGroup = stateManager.getSelectedGroups(stateManager.getActiveDatabase().orElse(null)).getFirst();
291+
stateManager.setSelectedGroups(libraryListView.getSelectionModel().getSelectedItem(), List.of(groupListView.getSelectionModel().getSelectedItem()));
292+
viewModel.importEntries(viewModel.getCheckedEntries().stream().toList(), downloadLinkedOnlineFiles.isSelected());
293+
stateManager.setSelectedGroups(stateManager.getActiveDatabase().orElse(null), List.of(prevSelectedGroup));
294+
} else {
295+
viewModel.importEntries(viewModel.getCheckedEntries().stream().toList(), downloadLinkedOnlineFiles.isSelected());
296+
}
240297
} else {
241298
dialogService.notify(Localization.lang("Import canceled"));
242299
}

jabgui/src/main/resources/org/jabref/gui/importer/ImportEntriesDialog.fxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<HBox spacing="4" alignment="CENTER_LEFT">
4545
<Label text="%Library to import into"/>
4646
<ComboBox fx:id="libraryListView" layoutX="16.0" layoutY="52.0"/>
47+
<ComboBox fx:id="groupListView" layoutX="16.0" layoutY="52.0"/>
4748
</HBox>
4849
</VBox>
4950
<HBox HBox.hgrow="ALWAYS"/>

jablib/src/main/resources/l10n/JabRef_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ Possible\ duplicate\ entries=Possible duplicate entries
682682
Possible\ duplicate\ of\ existing\ entry.\ Will\ be\ resolved\ on\ import.=Possible duplicate of existing entry. Will be resolved on import.
683683

684684
Import\ canceled=Import canceled
685+
No\ group=No group
685686
An\ error\ occurred\ while\ fetching\ entries\ from\ %0\:\ %1=An error occurred while fetching entries from %0: %1
686687
Error\ fetching\ entries=Error fetching entries
687688
%0\ of\ %1=%0 of %1

0 commit comments

Comments
 (0)