GWT solution #6: Drag and drop

Use the Google Web Toolkit to roll your own drag-and-drop module

Cover image


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 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.

1 2 3 4 5 6 7 8 9 Page 1