org.csstudio.ui.util.dnd
Class ControlSystemDragSource

java.lang.Object
  extended by org.csstudio.ui.util.dnd.ControlSystemDragSource

public abstract class ControlSystemDragSource
extends java.lang.Object

General purpose utility to allowing Drag-and-Drop "Drag" of any adaptable or Serializable object.

As an example, assume a TableViewer or TreeViewer where the input contains Serializable objects like ProcessVariable. This would allow dragging the first of the currently selected elements:

 ...Viewer viewer = ...
 new ControlSystemDragSource(viewer.getControl())
 {
     public Object getSelection()
     {
         final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
         return selection.getFirstElement();
      }
 };
 

In principle this would allow dagging any number of selected PVs out of the viewer:

 new ControlSystemDragSource(viewer.getControl())
 {
     public Object getSelection()
     {
         final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
         final Object[] objs = selection.toArray();
         return objs;
      }
 };
 

.. but note that it will fail. The data needs to be serialized as the actual array type, not an Object array:

 new ControlSystemDragSource(viewer.getControl())
 {
     public Object getSelection()
     {
         final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
         final Object[] objs = selection.toArray();
         final ProcessVariable[] pvs = Arrays.copyOf(objs, objs.length, ProcessVariable[].class);
         return pvs;
      }
 };
 

Author:
Gabriele Carcassi, Kay Kasemir

Constructor Summary
ControlSystemDragSource(Control control)
          Initialize 'drag' source
 
Method Summary
abstract  java.lang.Object getSelection()
          To be implemented by derived class: Provide the control system items that should be 'dragged' from this drag source
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ControlSystemDragSource

public ControlSystemDragSource(Control control)
Initialize 'drag' source

Parameters:
control - Control from which the selection may be dragged
Method Detail

getSelection

public abstract java.lang.Object getSelection()
To be implemented by derived class: Provide the control system items that should be 'dragged' from this drag source

Returns:
the selection (can be single object or array)