GWT solution #6: Drag and drop
Use the Google Web Toolkit to roll your own drag-and-drop module
By David Geary and Rob Gordon , JavaWorld.com, 11/06/07
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
 |
Excerpt from Google Web Toolkit Solutions: More Cool & Useful Stuff.
|
By David Geary, Rob Gordon Published by Prentice Hall ISBN-10: 0-13-234481-5 ISBN-13: 978-0-13-234481-4
|
|
You're not alone if you think drag and drop in Java Web applications is a drag. Fortunately, we found a solution in Google Web Toolkit Solutions: More Cool & Useful Stuff, forthcoming from Prentice Hall. In this excerpt, authors David Geary and Rob Gordon show you how to implement a drag-and-drop
module that you can easily incorporate into your Java Web applications. Along the way you'll also learn about GWT modules,
composite widgets, and widget event handling.
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. 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
- Removing widgets from panels
- Changing cursors for widgets with CSS styles
- Implementing a GWT module
- Adding multiple listeners to a widget
- Using the
AbsolutePanel class to place widgets by pixel location
- Capturing and releasing events for a specific widget
- Using an event preview to inhibit browser reactions to events
See Google Web Toolkit Solutions: More Cool & Useful Stuff Solution 1 and Solution 2 for more in-depth discussions of implementing GWT modules and implementing composite widgets, respectively.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- Pre-order Google Web Toolkit Solutions: More Cool & Useful Stuff (David Geary and Rob Gordon, Prentice Hall, November 2007.
- Learn more about Scriptaculous and Rico, two JavaScript frameworks that handle drag and drop for Web applications.
- GWT's handling of listeners is a big improvement over the Abstract Window Toolkit (AWT), which does not guarantee the order in which listeners are invoked.
- "Ease Ajax development with the Google Web Toolkit" (Jeff Friesen, JavaWorld, December 2006) is a good starting point for learning about Ajax development using GWT.
- Also see "Recipes to improve your Google Web Toolkit development" (Klaus P. Berg, JavaWorld, April 2007) for programming tips from a developer experienced with creating Java Web applications
using GWT.
- For a peek into the history of drag and drop on the Java platform, see "How to drag and drop with Java, Part 1" (Gene De Lisa, JavaWorld, March 1999).
- The Voices That Matter: Google Web Toolkit Conference runs from December 3 to 6 in San Francisco. JavaWorld readers are entitled to a $100 discount on the conference pass -- just
enter "GW-SPK6" in the Priority Code field when registering.
- See the JavaWorld Development Tools research center for more articles about Java Web development tools and frameworks.