Class ControlSystemDragSource

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

public abstract class ControlSystemDragSource extends 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()
     {
         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() {
         IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
         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() {
         IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
         Object[] objs = selection.toArray();
         ProcessVariable[] pvs = Arrays.copyOf(objs, objs.length, ProcessVariable[].class);
         return pvs;
     }
 };
 
  • Constructor Details

    • ControlSystemDragSource

      public ControlSystemDragSource(Control control)
      Initialize 'drag' source
      Parameters:
      control - Control from which the selection may be dragged
  • Method Details

    • getSelection

      public abstract 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)