Using drag and drop with IBM Director

This topic describes the implementation of drag and drop within IBM Director. 

Note, the word "drag" is generally used to indicate the process of both dragging and dropping an object. The use of "drag and drop" is therefore normally considered unacceptable because of the inherent redundancy. In this topic, because the actions of icons at various stages of the drag and the drop processes are under consideration, both terms are used explicitly. "Drag" is specifically intended to mean the process of taking an icon and copying or moving it to a location without completing the action (i.e., "dropping" the icon).

Subtopics

Related information

Related sample code

Overview

In IBM Director Version 4.2 and beyond, drag and drop is implemented using the JDK java.awt.dnd package. Unlike the previous in-house implementation of drag and drop, when dragging from IBM Director a DragSource can now be dropped onto DropTargets in applications (such as WordPad) outside of IBM Director. Using this implementation of drag and drop, you must take care to select the appropriate drag and drop action, since the drag cursor associated with a drag and drop action conveys information to the user.

When a drag begins, the DragSource Component must provide a "Transferable" for the drag. The Transferable contains one or more "DataFlavors." Think of the Transferable as a suitcase and the DataFlavors as its contents. The DataFlavors contained in the Transferable typically provide multiple representations of specific information in the DragSource. DropTargets will query the Transferable to see if it contains something useful. IBM Director contains a set of Transferables which might be of interest to DropTargets in IBM Director Console Extensions. Similarly, IBM IBM Director framework DropTargets might recognize these Transferables if they are provided by Console Extensions.

Using this new drag and drop implementation, the ability to drag objects between windows becomes a matter of the DragSource advertising what it has to offer and the DropTarget accepting offers it is capable of handling. This is very flexible and has a great deal of potential. A useful overview can be found at:

http://www.javaworld.com/javaworld/jw-03-1999/jw-03-dragndrop_p.html

Common drag and drop actions

The most common actions used are DnDConstants.ACTION_MOVE and DnDConstants.ACTION_COPY.

 DnDConstants.ACTION_MOVE indicates that the DragSource from which the drag originated is modified when the drop is accepted by a DropTarget. A good place to use this cursor is on an Add/Remove panel such as those used in the IBM Director User Administration User Editor.

Move cursor icon for Windows, the component accepts the drop. Windows Move Cursor
 
Move cursor icon for Linux/Solaris, the component accepts the drop. Linux Move Cursor

The following cursors indicate to the user that there is no valid DropTarget beneath the cursor during an ACTION_MOVE drag:

Copy cursor icon for Windows, the component below won't accept. Windows "No Move" Cursor
 
Move cursor icon for Linux/Solaris, the component won't accept. Linux "No Move" Cursor

DnDConstants.ACTION_COPY indicates that the DragSource from which the drag originated will not be modified when the drop is accepted by a DropTarget. The main console uses this action.

Copy cursor icon for Windows, the component below accepts the drop. Windows Copy Cursor
 
Copy cursor icon for Linux/Solaris, the component below accepts the drop. Linux Copy Cursor

The following cursors indicate to the user that there is no valid DropTarget beneath the cursor during an ACTION_COPY drag:

Copy cursor icon for Windows, the component below won't accept. Windows "No Copy" Cursor
 
Copy cursor icon for Linux/Solaris, the component below won't accept. Linux "No Copy" Cursor

There is also a DnDConstants.ACTION_COPY_OR_MOVE action which can be used when either a copy or move operation is permitted. When a Component supports both Copy and Move, a normal drag from the component performs a move and a Control-drag performs a copy.

IBM Director transferables

IBM Director framework Transferables that might be of interest to Console Extensions are found in the com.tivoli.twg.guilibs package and are listed here. TOIDSetFlavor, MOIDSetFlavor and FOIDSetFlavor are also included in the com.tivoli.twg.guilibs package. StringValueSet is included in the com.tivoli.twg.libs package.

TWGFilterTransferable:
A Transferable used to transfer information about a set of filter objects. One DragSource providing this object is the Groups Pane of the Console.

  1. FilterPrettyNameSetFlavor is a StringValueSet containing filter names as displayed on the console.
  2.  FOIDSetFlavor is a LongValueSet containing filter object IDs.
  3. FilterPrettyNamesSringFlavor is a String containing the readable names of filter objects separated by spaces.
  4. FilterPrettyNamesPlainTextFlavor is plain text containing the readable names of filter objects separated by spaces.

TWGManagedObjectTransferable:
A Transferable used to transfer information about a set of managed objects. One DragSource providing this object is the Group Contents Pane of the Console.

TWGTaskTransferable:
A Transferable used to transfer information about a set of task objects. One DragSource providing this object is the Tasks Pane of the Console.

  1. TaskObjectPrettyNameSetFlavor is a StringValueSet containing task names as displayed on the console.
  2. TOIDSetFlavor is a LongValueSet containing task object IDs.
  3. TOPrettyNamesSringFlavor is a String containing the readable names of task objects separated by spaces.
  4. TOPrettyNamesPlainTextFlavor is plain text containing the readable names of task objects separated by spaces.

Known issues

In JDK1.4.1, on which IBM Director Version 5.1 is based, the UI classes of many Java widgets have been outfitted with default drag/drop mechanisms. An example is the JTextComponent family of widgets which will accept String DataFlavors. If one of these widgets uses a KeyListener to catch and analyze the incoming text for characters it considers valid (such as digits), drop will act like a paste and can cause a NumberFormatException. Even if your widget has been outfitted to handle Paste Actions, additional code might be required to handle these drop actions.