In the example application, you can drag a user entry (a leaf in the tree view) to another group (a node in the tree view), thereby changing the data in the model (of course changes must be saved by pressing the 'Save' button or selecting the item 'Save' from the 'File' menu).
This feature is implemented in a command that is initialized in the MainForm.
As you would expect, that command is called
resides, along with all other commands, in the
For Drag & Drop, there is a special event listener which can be
added to trees. As usual with event listeners, it can be implemented as
anonymous class, and then be added to the
addDragDropListener( DragDropListener ) method. After
this is done, all nodes on the tree fire a
whenever the user attempts to drag some other element of the same tree
onto one of them.
(Remember that W4Toolkit is a library with active cross-browser
support. Drag & Drop works independently of the actual browser
case, an image is rendered to all items that triggers the
DragDropEvent. The user selects a leaf and clicks on one of the
dragdrop-placeholders for a node - and the
Here is the implementation of the actual Drag & Drop in the
For the Drag & Drop support it is necessary to get information
out of the tree items which are involved in the event. We must know which
Group object they represent, so we ask
TreeViewer for their data elements. This is the reason for
keeping a reference to the
TreeViewer instance in this command
Once we have the data objects, we ask the model to perform the changes to the data (that's the job of the business logic, not the ui):
Finally, we call another command that changes the state of
the ui to 'dirty': we remind the user to save by use of the
Copyright (c) 2003 by Innoopract Informationssysteme GmbH. All rights reserved.