Skip to content

Commit 7091cb3

Browse files
authored
Merge pull request #2845 from JabRef/fix2786
Implement #2786: Allow selection of multiple groups
2 parents cea2053 + 007690c commit 7091cb3

32 files changed

+309
-1120
lines changed

CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
1111
## [Unreleased]
1212

1313
### Changed
14-
- Continued to redesign the user interface: this time the editor got a fresh coat of paint:
14+
- We continued to improve the new groups interface:
15+
- You can now again select multiple groups (and a few related settings were added to the preferences) [#2786](https://github.com/JabRef/jabref/issues/2786).
16+
- The entry editor got a fresh coat of paint:
17+
- Homogenize the size of text fields.
1518
- The buttons were changed to icons.
19+
- Completely new interface to add or modify linked files.
1620
- Removed the hidden feature that a double click in the editor inserted the current date.
1721
- All authors and editors are separated using semicolons when exporting to csv. [#2762](https://github.com/JabRef/jabref/issues/2762)
18-
- Improved wording of "Show recommendationns: into "Show 'Related Articles' tab" in the preferences
22+
- Improved wording of "Show recommendations: into "Show 'Related Articles' tab" in the preferences
1923

2024
### Fixed
2125
- We fixed the IEEE Xplore web search functionality [#2789](https://github.com/JabRef/jabref/issues/2789)

src/main/java/org/jabref/gui/BasePanel.java

+2-53
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Objects;
2727
import java.util.Optional;
2828
import java.util.Set;
29-
import java.util.TimerTask;
3029
import java.util.stream.Collectors;
3130

3231
import javax.swing.AbstractAction;
@@ -68,7 +67,6 @@
6867
import org.jabref.gui.filelist.FileListEntry;
6968
import org.jabref.gui.filelist.FileListTableModel;
7069
import org.jabref.gui.groups.GroupAddRemoveDialog;
71-
import org.jabref.gui.groups.GroupSelector;
7270
import org.jabref.gui.importer.actions.AppendDatabaseAction;
7371
import org.jabref.gui.journals.AbbreviateAction;
7472
import org.jabref.gui.journals.UnabbreviateAction;
@@ -1900,10 +1898,6 @@ public BibDatabaseContext getBibDatabaseContext() {
19001898
return this.bibDatabaseContext;
19011899
}
19021900

1903-
public GroupSelector getGroupSelector() {
1904-
return frame.getGroupSelector();
1905-
}
1906-
19071901
public boolean isUpdatedExternally() {
19081902
return updatedExternally;
19091903
}
@@ -2116,63 +2110,18 @@ public void searchAndOpen() {
21162110
}
21172111

21182112
private class GroupTreeListener {
2119-
2120-
private final Runnable task = new Runnable() {
2121-
2122-
@Override
2123-
public void run() {
2124-
// Update group display (for example to reflect that the number of contained entries has changed)
2125-
frame.getGroupSelector().revalidateGroups();
2126-
}
2127-
};
2128-
2129-
/**
2130-
* Only access when you have the lock of the task instance
2131-
*
2132-
* Guarded by "task"
2133-
*/
2134-
private TimerTask timerTask = new TimerTask() {
2135-
2136-
@Override
2137-
public void run() {
2138-
task.run();
2139-
}
2140-
};
2141-
21422113
@Subscribe
21432114
public void listen(EntryAddedEvent addedEntryEvent) {
21442115
// if the added entry is an undo don't add it to the current group
21452116
if (addedEntryEvent.getEntryEventSource() == EntryEventSource.UNDO) {
2146-
scheduleUpdate();
21472117
return;
21482118
}
21492119

21502120
// Automatically add new entry to the selected group (or set of groups)
2151-
if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)
2152-
&& frame.getGroupSelector().getToggleAction().isSelected()) {
2121+
if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)) {
21532122
final List<BibEntry> entries = Collections.singletonList(addedEntryEvent.getBibEntry());
2154-
Globals.stateManager.getSelectedGroup(bibDatabaseContext).ifPresent(
2123+
Globals.stateManager.getSelectedGroup(bibDatabaseContext).forEach(
21552124
selectedGroup -> selectedGroup.addEntriesToGroup(entries));
2156-
SwingUtilities.invokeLater(() -> BasePanel.this.getGroupSelector().valueChanged(null));
2157-
}
2158-
2159-
scheduleUpdate();
2160-
}
2161-
2162-
private void scheduleUpdate() {
2163-
// This is a quickfix/dirty hack.
2164-
// a better solution would be using RxJava or something reactive instead
2165-
// nevertheless it works correctly
2166-
synchronized (task) {
2167-
timerTask.cancel();
2168-
timerTask = new TimerTask() {
2169-
2170-
@Override
2171-
public void run() {
2172-
task.run();
2173-
}
2174-
};
2175-
JabRefExecutorService.INSTANCE.submit(timerTask, 200);
21762125
}
21772126
}
21782127
}

src/main/java/org/jabref/gui/JabRefFrame.java

-4
Original file line numberDiff line numberDiff line change
@@ -1914,10 +1914,6 @@ public SidePaneManager getSidePaneManager() {
19141914
return sidePaneManager;
19151915
}
19161916

1917-
public GroupSelector getGroupSelector() {
1918-
return groupSelector;
1919-
}
1920-
19211917
public void setPreviewToggle(boolean enabled) {
19221918
previewToggle.setSelected(enabled);
19231919
}

src/main/java/org/jabref/gui/StateManager.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import javafx.beans.binding.Bindings;
99
import javafx.beans.property.ObjectProperty;
10-
import javafx.beans.property.ReadOnlyObjectProperty;
11-
import javafx.beans.property.ReadOnlyObjectWrapper;
10+
import javafx.beans.property.ReadOnlyListProperty;
11+
import javafx.beans.property.ReadOnlyListWrapper;
1212
import javafx.beans.property.SimpleObjectProperty;
1313
import javafx.collections.FXCollections;
1414
import javafx.collections.ObservableList;
@@ -33,21 +33,21 @@
3333
public class StateManager {
3434

3535
private final ObjectProperty<Optional<BibDatabaseContext>> activeDatabase = new SimpleObjectProperty<>(Optional.empty());
36-
private final ReadOnlyObjectWrapper<Optional<GroupTreeNode>> activeGroup = new ReadOnlyObjectWrapper<>(Optional.empty());
36+
private final ReadOnlyListWrapper<GroupTreeNode> activeGroups = new ReadOnlyListWrapper<>(FXCollections.observableArrayList());
3737
private final ObservableList<BibEntry> selectedEntries = FXCollections.observableArrayList();
38-
private final ObservableMap<BibDatabaseContext, GroupTreeNode> selectedGroups = FXCollections.observableHashMap();
38+
private final ObservableMap<BibDatabaseContext, ObservableList<GroupTreeNode>> selectedGroups = FXCollections.observableHashMap();
3939

4040
public StateManager() {
4141
MonadicBinding<BibDatabaseContext> currentDatabase = EasyBind.map(activeDatabase, database -> database.orElse(null));
42-
activeGroup.bind(EasyBind.map(Bindings.valueAt(selectedGroups, currentDatabase), Optional::ofNullable));
42+
activeGroups.bind(Bindings.valueAt(selectedGroups, currentDatabase));
4343
}
4444

4545
public ObjectProperty<Optional<BibDatabaseContext>> activeDatabaseProperty() {
4646
return activeDatabase;
4747
}
4848

49-
public ReadOnlyObjectProperty<Optional<GroupTreeNode>> activeGroupProperty() {
50-
return activeGroup.getReadOnlyProperty();
49+
public ReadOnlyListProperty<GroupTreeNode> activeGroupProperty() {
50+
return activeGroups.getReadOnlyProperty();
5151
}
5252

5353
public ObservableList<BibEntry> getSelectedEntries() {
@@ -58,16 +58,17 @@ public void setSelectedEntries(List<BibEntry> newSelectedEntries) {
5858
selectedEntries.setAll(newSelectedEntries);
5959
}
6060

61-
public void setSelectedGroup(BibDatabaseContext database, GroupTreeNode newSelectedGroup) {
62-
Objects.requireNonNull(newSelectedGroup);
63-
selectedGroups.put(database, newSelectedGroup);
61+
public void setSelectedGroups(BibDatabaseContext database, List<GroupTreeNode> newSelectedGroups) {
62+
Objects.requireNonNull(newSelectedGroups);
63+
selectedGroups.put(database, FXCollections.observableArrayList(newSelectedGroups));
6464
}
6565

66-
public Optional<GroupTreeNode> getSelectedGroup(BibDatabaseContext database) {
67-
return Optional.ofNullable(selectedGroups.get(database));
66+
public ObservableList<GroupTreeNode> getSelectedGroup(BibDatabaseContext database) {
67+
ObservableList<GroupTreeNode> selectedGroupsForDatabase = selectedGroups.get(database);
68+
return selectedGroupsForDatabase != null ? selectedGroupsForDatabase : FXCollections.observableArrayList();
6869
}
6970

70-
public void clearSelectedGroup(BibDatabaseContext database) {
71+
public void clearSelectedGroups(BibDatabaseContext database) {
7172
selectedGroups.remove(database);
7273
}
7374

0 commit comments

Comments
 (0)