Dragging leaves only in a TreeTable

Hello. I am implementing Drag and Drop in a TreeTable and I need to allow dragging leaves only.

I tried:

public AcceptCriterion getAcceptCriterion() { return new Not(Tree.TargetItemAllowsChildren.get()); } but it doesn’t work for me.

Any help will be appreciated.

That should prevent you from dropping anything but leaves, not dragging them. I haven’t actually tried this, but glancing through the code it seems that there is no easy way to prevent the dragging for some items in TreeTable. At the very least you’d need to extend the client-side, very possibly even override it, because VTreeTable and its inner classes are not easily extendable as a rule, and they use VScrollTable’s drag handling in any case. Might be doable by overriding VTreeTableRow’s (or rather VScrollTableRow’s) startRowDrag(…), which is protected so it looks like this would be technically doable, but far from trivial. The drop-prevention should have the same end result, though, i.e. that only leaves end up changing their locations.

I have done something similar to Anna’s suggestion for Tree. I have a custom Tree component, and VTree and TreeConnector (under widgetsets/client package), just to customize a small piece in the VTree.TreeNode inner class:

[code]
if (mouseDownEvent != null) {
// start actual drag on slight move when mouse is down
VTransferable t = new VTransferable();
t.setDragSource(ConnectorMap.get(client).getConnector( VSelectiveDragTree.this));
t.setData(“itemId”, key);

// ---------------------------original-------------------
/VDragEvent drag = VDragAndDropManager.get().startDrag( t, mouseDownEvent, true);
drag.createDragImage(nodeCaptionDiv, true);
/

// ---------------------------customized-----------------
String sn = getStyleName();
if (sn.contains(“nodrag”)) {
VDragAndDropManager.get().interruptDrag();
} else {
VDragEvent drag = VDragAndDropManager.get().startDrag(t, mouseDownEvent, true);
drag.createDragImage(nodeCaptionDiv, true);
}

// ---------------------------end------------------------

event.stopPropagation(); mouseDownEvent = null;
}
[/code]Then in my Tree subclass, I set an ItemStyleGenerator:

@Override protected ItemStyleGenerator getItemStyleForDragAndDrop() { return new SelectiveDragTree.ItemStyleGenerator() { @Override public String getStyle(Tree source, Object itemId) { IcdCriteria i = (IcdCriteria) itemId; if (i.getRoot().equals("1")) { return "nodrag"; } return ""; } }; } In CSS, you can set the mouse pointer to default, so it looks “unselectable” for dragging: .nodrag, .v-tree-node-caption-nodrag span { cursor: default; } This produces a tree that drags any node that is not a “root”, as defined in my database. It does not make sense to me to allow a tree node to visually drag if the drop is not going to be accepted.

Has anyone found a more straightforward way to accomplish this?