Skip to content

Commit

Permalink
Adds a delay to the group expansion (#4838)
Browse files Browse the repository at this point in the history
* Adds a delay to the group expansion

* Also collapses the item after 1 second

* Renamed handler class and method signature
  • Loading branch information
johannes-manner authored and tobiasdiez committed Apr 2, 2019
1 parent 1c1a6a4 commit 3ed41ef
Showing 1 changed file with 28 additions and 1 deletion.
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());
}
}
}
}

0 comments on commit 3ed41ef

Please sign in to comment.