|Is there a way to assign specific Transfer types to the nodes of a TreeViewer OR to get the dragged [message #537883]
||Fri, 04 June 2010 04:08
Registered: July 2009
My application needs to support the moving of 2 different types of nodes |
(each at a different depth in the tree) within a treeviewer by drag and drop
(multiple selections at one time). Each set of dragged selections must have
the same transfer type. Note that the moving of the nodes is done within
the same treeviewer (nothing is moved out of the viewer). Below is a quick
representation of the nodes in the tree:
The tree consists of 3 levels. Item nodes can be moved between Subgroups
and Subgroup nodes can be moved between Group nodes. Since I haven't
figured out how to control node selections in the tree (i.e. if the first
selection is an item then only allow item selections, or if the first
selection is a Subgroup then only allow Subgroup item selections) I am
attempting to force validation failure during the drag and drop operation.
If anyone knows how to control tree node selections as stated please reply.
I have tried forcing validation failure on both the drag and the drop side
of the operation but have run into issues with both approaches. Basically,
I want validation to fail if mixed nodes are selected and dragged (i.e.
Items and Subgroups).
I attempted to handle the validation (ensuring that all nodes are set to use
the same transfer type) of the multiple dragged nodes when the drag is
initiated within the DragSourceListener's dragSetData method by: 1) creating
2 custom transfer types (by extending ByteArrayTransfer), and 2) attempting
to use the DragSourceEvent's dataType attribute to compare against each of
the registered transfer types using the built in isSupportedType method. My
problem with this approach is that I cannot figure out how to associate each
of the transfer types with specific treeviewer nodes so that I can detect
them within the dragSetData method. This isn't the preferred approach
because a failed validation here causes a prompt to appear from the parent
Transfer class (with a user unfriendly message).
Alternatively, I considered validation of the multiple dragged nodes when
the drop is validated within the ViewerDropAdapter validateDrop method by:
1) creating only 1 custom transfer type (by extending ByteArrayTransfer)
that is associated with all nodes in the treeviewer, and 2) attempting to
get a handle to all of the dragged items within the validateDrop method to
use my own method to determine if the nodes are all the same for the drop.
My problem with this approach is that I cannot figure out how to get a
handle to the multiple dragged nodes within this method. There is a way to
get a single selected object but I need to check all of the dragged items to
successfully pass validation. This is the preferred implementation as this
will not prompt the user as a failed validation will on the drag side. Here
the drop is just not permitted and the drag icon conveys this.
If no method exists to handle this issue I can do one of the following: 1)
do further validation within the ViewerDropApdater performDrop method and
stop the drop there, 2) only move the items that are compatible with the
target node and ignore the rest, or 3) just use the treeviewer handle to get
the selections to determine if they are all the same (I was hoping to avoid
using this since this wouldn't be the proper method if the drag and drop was
done outside of the tree). Its a very small issue but I figured I'd ask in
case I'm missing some obvious way of achieving the same result (hopefully
this is the case).
Powered by FUDForum
. Page generated in 0.01567 seconds