i'm implementing the Drag&Drop on a generic TreeView. My purpose is to expand a folder during DragEntered event after a second of stationing, actual code:
setOnDragEntered(e -> {
TreeItem<TreeItemContent> enteredItem = getSourceItem(e);
if(model.isFolder(enteredItem)){
enteredItem.setGraphic(images.getFolderOpened());
enteredItem.setExpanded(true);
}
e.consume();
});
desired:
setOnDragEntered(e -> {
TreeItem<TreeItemContent> enteredItem = getSourceItem(e);
if(model.isFolder(enteredItem)){
if(dragDuration >= 1 sec){
enteredItem.setGraphic(images.getFolderOpened());
enteredItem.setExpanded(true);
}
}
e.consume();
});
There is a standard resolution for this scope ? or i must implement this function by myself ?
You can use a PauseTransition for adding the delay. On its
setOnFinished(), you can add an action to be performed after the supplied time has elapsed.On
setOnDragEntered(), you can start thePauseTransitionand onsetOnDragExited(), check thestatusofPauseTransitionand if it is still inRUNNINGstatus,stopit.Here is a simple code, which uses,
setOnMouseEntered()andsetOnMouseExited(), instead of the above two mentioned events, on aButton. But, this should be more than enough to give you an idea.Code :