Disable Tree items

Hi I am trying to disable tree items. The issue is that I have drag/drop set for my tree, but I want disabled nodes to not be able to be dragged/dropped or dropped onto. I’ve been searching and couldn’t find a solution to this. I saw that you could change the style with:

tree.setItemStyleGenerator(new Tree.ItemStyleGenerator() {
            public String getStyle(Tree source, Object itemId) {
                    return "redTreeItem";
                    return "";

So is there a way maybe with the css that I could disable this item? I looked and found the following styles, and applied them but it didn’t have any affect on the drag/drop.

-moz-user-select: none;
-webkit-user-select: none;
/* this will work for QtWebKit in future */
 -webkit-user-drag: none;

I found a style that works somewhat. (doesnt work in IE though)

pointer-events: none; This does not let the user select the node in the tree at all, which works. I only wish that I could just disable the drag/drop…if anyone finds out let me know!


Interesting question.

Well, accepting/rejecting drops on a tree node can be done with an accept criterion. There are
a number of them
for trees. The TreeDropCriterion gives the most detailed control, as
demonstrated here

Regarding the drag source, I guess there isn’t a built-in way to restrict dragging some items, neither to disable items. It’s perhaps possible disable dragging items in some way in CSS, but I can’t help with that any better than you have done in your investigation.

Perhaps the most reliable way would be to extend VTree on the client-side and rewrite VTree.TreeNode.onBrowserEvent(), which handles drag initialization. Well, there’s some work with that. You might also be able to write a component extension that handles the browser events instead of the handler in TreeNode, but that might get even more complex than extending by inheritance.

Hey thanks Marko. For now I ended up checking in the drop listener, I check if the source/target object does not have the disable property I gave to it. If the object being dragged/dragged onto is disabled I just pop a warning and return so the item can’t be drag/dropped.

I will look into the VTree, I wish it was a bit more flexible easier, but hey it works!

edit: just looked at the drop crieterion demo you posted and it looks promising. If I know all of the ID’s of the nodes that are disabled I should be able to not let them be dropped into!