Google Web Toolkit Solutions: Implement Drag and Drop in Your Web Apps
The ultimate in user interactivity, drag and drop is taken for granted in desktop applications but is a litmus test of sorts for web applications: If you can easily implement drag and drop with your web application framework, then you know you've got something special.
Until now, drag and drop for web applications has, for the most part, been limited to specialized JavaScript frameworks such as Script.aculo.us and Rico.1 No more. With the advent of GWT, we have drag-and-drop capabilities in a Java-based web application framework. Although GWT does not explicitly support drag and drop (drag and drop is an anticipated feature in the future), it provides us with all the necessary ingredients to make our own drag-and-drop module.
In this solution, we explore drag-and-drop implementation with GWT. We implement drag and drop in a module of its own so that you can easily incorporate drag and drop into your applications.
Stuff You're Going to Learn
This solution explores the following aspects of GWT:
- Implementing composite widgets with the Composite class (page 174)
- Removing widgets from panels (page 169)
- Changing cursors for widgets with CSS styles (page 200)
- Implementing a GWT module (page 182)
- Adding multiple listeners to a widget (page 186)
- Using the AbsolutePanel class to place widgets by pixel location (page 211)
- Capturing and releasing events for a specific widget (page 191)
- Using an event preview to inhibit browser reactions to events (page 196)
See Solution 1 and Solution 2 for more in-depth discussions of implementing GWT modules and implementing composite widgets, respectively.