下面列出了怎么用javafx.scene.control.TreeItem.TreeModificationEvent的API类实例代码及写法,或者点击链接到github查看源代码。
/** Trigger a redraw of a tree item
*
* <p>Call when the model item's representation changed,
* so tree item with existing value object needs to be
* redrawn.
*
* @param item {@link TreeItem}
*/
public static <TV> void triggerTreeItemRefresh(final TreeItem<TV> item)
{
// TreeView has a refresh() for triggering a complete update.
// TreeItem has no 'refresh()', update or redraw method to trigger a single-node update.
// 'setValue' can trigger a refresh if value is different, for example by briefly
// changing to null and back:
// final TV value = item.getValue();
// item.setValue(null);
// item.setValue(value);
// The API does expose the valueChangedEvent(), so send that.
// Checking in the debugger, the effect seems to be a redraw
// of all visible tree nodes, not just the modified one.
// Still, we use this as a best effort to limit updates.
Event.fireEvent(item, new TreeModificationEvent<>(TreeItem.<TV>valueChangedEvent(), item, item.getValue()));
}
/**
* Handle changed count of expanded elements.
*/
@FxThread
private void processChangedExpands(@NotNull TreeModificationEvent<?> event) {
if (!(event.wasExpanded() || event.wasCollapsed())) {
return;
}
if (isLazyMode()) {
EXECUTOR_MANAGER.addFxTask(this::lazyLoadChildren);
}
getExpandHandler().ifPresent(handler ->
handler.accept(getExpandedItemCount(), this));
repaint();
}
@Override public void handle(final TreeModificationEvent<Object> ev) {
if (!root.isExpanded() && controller.isOpened()) {
// Closing controller
controller.close();
} else if (root.isExpanded() && !controller.isOpened()) {
// Opening controller
scenicView.openStage(controller);
}
}