Implement Drag and Drop in Your Web Apps - Part 2
Implement Drag and Drop in Your Web Apps: Part 2
Drag and Drop Implementation in a GWT Module
Now that we have a good grasp of how to use the dnd module, let's look at how it's implemented.
The drag-and-drop module is implemented inside, our Components module. See Figure 6.5 shows the drag and drop's pertinent files and directories.
Like all GWT modules, our drag-and-drop module has an XML configuration file. Like most modules, our drag-and-drop module also has some Java classes and interfaces.
The Module Configuration File
Every GWT module must provide a configuration file. The dnd module's configuration file is listed in Listing 6.10.
It doesn't get any simpler than that. All we need for our dnd module is the core GWT classes, so that's what we inherit.
Now let's look at the Java classes in the dnd module.
The Abstract Drag Source and Drop Target Classes
The DragSource class is listed in Listing 6.11.
This simple extension of the
MousePanel we discussed in "The Viewport's Use of a Focus Panel: Revisited" (page 115) defines three properties and implements four methods that subclasses are likely to use:
The properties keep track of whether the mouse panel is currently being dragged, its position before the drag began, and the enclosing drop target, if any. The methods are typically overridden by subclasses, as is the case for the
MusicPlayerPanelDropTarget, listed in Listing 6.6 on page 178.