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

Adds a delay to the group expansion #4838

Merged
merged 3 commits into from
Apr 2, 2019
Merged
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
29 changes: 28 additions & 1 deletion src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class GroupTreeView {
private GroupTreeViewModel viewModel;
private CustomLocalDragboard localDragboard;

private DragExpansionHandler dragExpansionHandler;

private static void removePseudoClasses(TreeTableRow<GroupNodeViewModel> row, PseudoClass... pseudoClasses) {
for (PseudoClass pseudoClass : pseudoClasses) {
row.pseudoClassStateChanged(pseudoClass, false);
Expand All @@ -84,6 +86,7 @@ public void initialize() {

// Set-up groups tree
groupTree.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
dragExpansionHandler = new DragExpansionHandler();

// Set-up bindings
Consumer<ObservableList<GroupNodeViewModel>> updateSelectedGroups =
Expand Down Expand Up @@ -220,7 +223,7 @@ public void initialize() {
event.acceptTransferModes(TransferMode.MOVE, TransferMode.LINK);

//expand node and all children on drag over
row.getTreeItem().setExpanded(true);
dragExpansionHandler.expandGroup(row.getTreeItem());

removePseudoClasses(row, dragOverBottom, dragOverCenter, dragOverTop);
switch (getDroppingMouseLocation(row, event)) {
Expand Down Expand Up @@ -399,4 +402,28 @@ private DroppingMouseLocation getDroppingMouseLocation(TreeTableRow<GroupNodeVie
return DroppingMouseLocation.CENTER;
}
}

private class DragExpansionHandler {
private static final long DRAG_TIME_BEFORE_EXPANDING_MS = 1000;
private TreeItem<GroupNodeViewModel> draggedItem;
private long dragStarted;

public void expandGroup(TreeItem<GroupNodeViewModel> treeItem) {
if (!treeItem.equals(draggedItem)) {
this.draggedItem = treeItem;
this.dragStarted = System.currentTimeMillis();
this.draggedItem.setExpanded(this.draggedItem.isExpanded());
return;
}

if (System.currentTimeMillis() - this.dragStarted > DRAG_TIME_BEFORE_EXPANDING_MS) {
// expand or collapse the tree item and reset the time
this.dragStarted = System.currentTimeMillis();
this.draggedItem.setExpanded(!this.draggedItem.isExpanded());
} else {
// leave the expansion state of the tree item as it is
this.draggedItem.setExpanded(this.draggedItem.isExpanded());
}
}
}
}