Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2868 - keep source groups selected after drag and drop #5731

Merged
merged 1 commit into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where JabRef could not interact with [Oracle XE](https://www.oracle.com/de/database/technologies/appdev/xe.html) in the [shared SQL database setup](https://docs.jabref.org/collaborative-work/sqldatabase).
- We fixed an issue where the toolbar icons were hidden on smaller screens.
- We fixed an issue where renaming referenced files for bib entries with long titles was not possible. [#5603](https://github.com/JabRef/jabref/issues/5603)
- We fixed a bug where the selection of groups was lost after drag and drop.[#2868](https://github.com/JabRef/jabref/issues/2868)

### Removed

Expand Down
31 changes: 29 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.lang.reflect.Method;
import java.time.Duration;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -232,14 +233,18 @@ public void initialize() {

if (dragboard.hasContent(DragAndDropDataFormats.GROUP)) {
List<String> pathToSources = (List<String>) dragboard.getContent(DragAndDropDataFormats.GROUP);
List<GroupNodeViewModel> changedGroups = new LinkedList<>();
for (String pathToSource : pathToSources) {
Optional<GroupNodeViewModel> source = viewModel.rootGroupProperty().get()
.getChildByPath(pathToSource);
if (source.isPresent()) {
source.get().draggedOn(row.getItem(), ControlHelper.getDroppingMouseLocation(row, event));
changedGroups.add(source.get());
success = true;
}
}
groupTree.getSelectionModel().clearSelection();
changedGroups.forEach(value -> selectNode(value, true));
}

if (localDragboard.hasBibEntries()) {
Expand Down Expand Up @@ -268,8 +273,21 @@ private void updateSelection(List<TreeItem<GroupNodeViewModel>> newSelectedGroup
}

private void selectNode(GroupNodeViewModel value) {
selectNode(value, false);
}

private void selectNode(GroupNodeViewModel value, boolean expandParents) {
getTreeItemByValue(value)
.ifPresent(treeItem -> groupTree.getSelectionModel().select(treeItem));
.ifPresent(treeItem -> {
if (expandParents) {
TreeItem<GroupNodeViewModel> parent = treeItem.getParent();
while (parent != null) {
parent.setExpanded(true);
parent = parent.getParent();
}
}
groupTree.getSelectionModel().select(treeItem);
});
}

private Optional<TreeItem<GroupNodeViewModel>> getTreeItemByValue(GroupNodeViewModel value) {
Expand All @@ -281,7 +299,16 @@ private Optional<TreeItem<GroupNodeViewModel>> getTreeItemByValue(TreeItem<Group
if (root.getValue().equals(value)) {
return Optional.of(root);
}
return root.getChildren().stream().filter(child -> getTreeItemByValue(child, value).isPresent()).findFirst();

Optional<TreeItem<GroupNodeViewModel>> node = Optional.empty();
for (TreeItem<GroupNodeViewModel> child : root.getChildren()) {
node = getTreeItemByValue(child, value);
if (node.isPresent()) {
break;
}
}

return node;
}

private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
Expand Down