protected void configureDragAndDrop(DragAndDropConfiguration dragAndDropConfiguration, TreeViewer treeViewer) { // drop Transfer[] transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() }; int operations = dragAndDropConfiguration.getSupportedDropOperations(this); DropTarget target = new DropTarget(treeViewer.getControl(), operations); target.setTransfer(transferTypes); // Drop listeners pour le drop des elements sur l'arbre SchemaViewerDropPolicy dropPolicy = dragAndDropConfiguration.getDropPolicy(this); DnDTargetListener targetListener = new DnDTargetListener(this, nodeConverter, dropPolicy); target.addDropListener(targetListener); // Drag listener pour le drag des elements de l'arbre DragSourceListener sourceListener = new DnDSourceListener(this); operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT; transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() }; treeViewer.addDragSupport(operations, transferTypes, sourceListener); }
protected DragSourceListener getDragSourceAdapter( final TableViewer inViewer) { return new DragSourceAdapter() { @Override public void dragSetData(final DragSourceEvent inEvent) { final IStructuredSelection lSelected = (IStructuredSelection) inViewer .getSelection(); if (!lSelected.isEmpty()) { final Object[] lItems = lSelected.toArray(); final UniqueID[] lIDs = new UniqueID[lItems.length]; for (int i = 0; i < lItems.length; i++) { final ILightWeightItem lItem = (ILightWeightItem) lItems[i]; lIDs[i] = new UniqueID(lItem.getItemType(), lItem.getID()); } inEvent.data = lIDs; } } }; }
@Override public void addDragSupport(int operations, Transfer[] transferTypes, DragSourceListener listener) { fViewer.addDragSupport(operations, transferTypes, listener); }
/** * Adds support for dragging items out of this viewer via a user * drag-and-drop operation. * * @param operations * a bitwise OR of the supported drag and drop operation types ( * <code>DROP_COPY</code>,<code>DROP_LINK</code>, and * <code>DROP_MOVE</code>) * @param transferTypes * the transfer types that are supported by the drag operation * @param listener * the callback that will be invoked to set the drag data and to * cleanup after the drag and drop operation finishes * @see org.eclipse.swt.dnd.DND */ public void addDragSupport(int operations, Transfer[] transferTypes, DragSourceListener listener) { Control myControl = getControl(); final DragSource dragSource = new DragSource(myControl, operations); dragSource.setTransfer(transferTypes); dragSource.addDragListener(listener); }