org.cafesip.gwtcomp.client.ui
Class Draggable

java.lang.Object
  extended by org.cafesip.gwtcomp.client.ui.Draggable

public class Draggable
extends Object

An utility class for making a widget "draggable". A draggable widget can be dragged and dropped into a DroppableList object. Each draggable object must have a unique id and a "class" associated with it. The class (not to be confused with a class in object-oriented programming) is used to classify the object. For example, a draggable object with id="123" and class="country" can be dropped into a DroppableList that accepts objects of class="country". Therefore, it is possible to have more than one DroppableList in a screen that accepts objects of different class. Note that the id attribute is the same as the DOM id and must be unique for the underlying HTML document.

Important note: the makeDraggable() method must be invoked only after the object has been attached to the DOM document because of the limitation of the underlying implementation. If the application requires a label that is draggable, use the DraggableLabel instead. The makeDraggable() method does not have to be invoked for this class.

The draggable/droppable classes use the scriptaculous javascript library for providing the functionality. Therefore, you must add the following segment to your application HTML file (see the GWTCompExamples.html for an example).

       <script src="gwtcomp-scripts/scriptaculous/prototype.js" type="text/javascript"></script>
       <script src="gwtcomp-scripts/scriptaculous/scriptaculous.js" type="text/javascript"></script>
       <script src="gwtcomp-scripts/scriptaculous/dragdrop.js" type="text/javascript"></script>
 

Author:
Amit Chatterjee

Method Summary
 void dispose()
          This method must be called when the object is no longer attached with the DOM document.
 String getClazz()
          Returns the class.
 Element getDraggable()
          Returns the DOM element associated with the draggable object.
static HashMap<String,org.cafesip.gwtcomp.client.helpers.DraggableElement> getDraggables()
          Returns a list of draggable items.
 String getName()
          Returns the name of the draggable object.
 Widget getObject()
          Returns the draggable widget.
static Draggable makeDraggable(Widget object, String name, String id, String clazz)
          This static method is used to make a widget draggable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

dispose

public void dispose()
This method must be called when the object is no longer attached with the DOM document. Otherwise, the object will not be removed from the draggables list and will cause memory leak and potentially other issues.


getObject

public Widget getObject()
Returns the draggable widget.

Returns:
Returns the object.

getClazz

public String getClazz()
Returns the class.

Returns:
Returns the clazz.

getDraggable

public Element getDraggable()
Returns the DOM element associated with the draggable object.

Returns:
Returns the draggable.

getName

public String getName()
Returns the name of the draggable object.

Returns:
Returns the name.

getDraggables

public static HashMap<String,org.cafesip.gwtcomp.client.helpers.DraggableElement> getDraggables()
Returns a list of draggable items. The key for the HashMap is the id and the value is an object of the type DraggableElement.

Returns:
Returns the draggables.

makeDraggable

public static Draggable makeDraggable(Widget object,
                                      String name,
                                      String id,
                                      String clazz)
This static method is used to make a widget draggable. The dispose() method must be called to release the draggable nature of the object.

Parameters:
object - widget to make draggable.
name - the name of the object. The DroppableList object identifies the object with this name.
id - the DOM id of the object.
clazz - the class of the widget.
Returns:
a draggable object.


Copyright © 2010 Cafesip.org. All Rights Reserved.