Search in sources :

Example 11 with DragSourceEvent

use of org.eclipse.swt.dnd.DragSourceEvent in project nebula.widgets.nattable by eclipse.

the class NatTable method addDragSupport.

// DND /////////////////////////////////////////////////////////////////
/**
 * Adds support for dragging items out of this control 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(final int operations, final Transfer[] transferTypes, final DragSourceListener listener) {
    final DragSource dragSource = new DragSource(this, operations);
    dragSource.setTransfer(transferTypes);
    DragSourceListener wrapper = new DragSourceListener() {

        @Override
        public void dragStart(DragSourceEvent event) {
            listener.dragStart(event);
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            listener.dragSetData(event);
        }

        @Override
        public void dragFinished(DragSourceEvent event) {
            listener.dragFinished(event);
            // ensure to stop any current active internal drag mode
            NatTable.this.modeSupport.switchMode(Mode.NORMAL_MODE);
        }
    };
    dragSource.addDragListener(wrapper);
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener)

Example 12 with DragSourceEvent

use of org.eclipse.swt.dnd.DragSourceEvent in project tdq-studio-se by Talend.

the class AnalysisColumnNominalIntervalTreeViewer method addSourceDND.

/**
 * DOC bZhou Comment method "addSourceDND".
 *
 * @param newTree
 */
private void addSourceDND(final Tree newTree) {
    final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
    Transfer[] types = new Transfer[] { transfer };
    int operations = DND.DROP_COPY | DND.DROP_MOVE;
    final DragSource source = new DragSource(newTree, operations);
    source.setTransfer(types);
    final TreeItem[] dragSourceItem = new TreeItem[1];
    source.addDragListener(new DragSourceListener() {

        public void dragStart(DragSourceEvent event) {
            TreeItem[] selection = newTree.getSelection();
            dragSourceItem[0] = selection[0];
            if (selection.length > 0) {
                event.doit = true;
                transfer.setSelection(new StructuredSelection(selection[0].getData(COLUMN_INDICATOR_KEY)));
                getColumnSetMultiValueList().remove(selection[0].getData(COLUMN_INDICATOR_KEY));
            } else {
                event.doit = false;
            }
        }

        public void dragSetData(DragSourceEvent event) {
            event.data = dragSourceItem[0];
        }

        public void dragFinished(DragSourceEvent event) {
            if (event.detail == DND.DROP_MOVE) {
                removeItemBranch(dragSourceItem[0]);
                tree.forceFocus();
            }
            dragSourceItem[0] = null;
        }
    });
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) TreeItem(org.eclipse.swt.widgets.TreeItem) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer)

Example 13 with DragSourceEvent

use of org.eclipse.swt.dnd.DragSourceEvent in project InformationSystem by ObeoNetwork.

the class TreeMapper method bindTreeForDND.

/**
 * @param sourceTreeViewer
 * @param targetTreeViewer
 * @param direction
 */
private void bindTreeForDND(final TreeViewer sourceTreeViewer, final TreeViewer targetTreeViewer, final int direction) {
    final LocalSelectionTransfer sourceTransfer = LocalSelectionTransfer.getTransfer();
    final LocalSelectionTransfer targetTransfer = LocalSelectionTransfer.getTransfer();
    sourceTreeViewer.addDragSupport(DND.DROP_LINK, new Transfer[] { sourceTransfer }, new TreeDragSourceEffect(sourceTreeViewer.getTree()) {

        @Override
        public void dragStart(DragSourceEvent event) {
            event.doit = !sourceTreeViewer.getSelection().isEmpty();
        }
    });
    targetTreeViewer.addDropSupport(DND.DROP_LINK, new Transfer[] { targetTransfer }, new TreeDropTargetEffect(targetTreeViewer.getTree()) {

        @Override
        public void dragEnter(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL | DND.FEEDBACK_SELECT;
            event.detail = DND.DROP_LINK;
            super.dragEnter(event);
        }

        @Override
        public void drop(DropTargetEvent event) {
            performMappingByDrop(sourceTreeViewer, sourceTreeViewer.getSelection(), targetTreeViewer, (TreeItem) getItem(event.x, event.y), direction);
        }
    });
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) TreeItem(org.eclipse.swt.widgets.TreeItem) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) TreeDragSourceEffect(org.eclipse.swt.dnd.TreeDragSourceEffect) TreeDropTargetEffect(org.eclipse.swt.dnd.TreeDropTargetEffect)

Example 14 with DragSourceEvent

use of org.eclipse.swt.dnd.DragSourceEvent in project netxms by netxms.

the class AgentFileManager method enableDragSupport.

/**
 * Enable drag support in object tree
 */
public void enableDragSupport() {
    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new DragSourceAdapter() {

        @Override
        public void dragStart(DragSourceEvent event) {
            LocalSelectionTransfer.getTransfer().setSelection(viewer.getSelection());
            event.doit = true;
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            event.data = LocalSelectionTransfer.getTransfer().getSelection();
        }
    });
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer)

Example 15 with DragSourceEvent

use of org.eclipse.swt.dnd.DragSourceEvent in project netxms by netxms.

the class ObjectTree method enableDragSupport.

/**
 * Enable drag support in object tree
 */
public void enableDragSupport() {
    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    objectTree.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new DragSourceAdapter() {

        @Override
        public void dragStart(DragSourceEvent event) {
            LocalSelectionTransfer.getTransfer().setSelection(objectTree.getSelection());
            event.doit = true;
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            event.data = LocalSelectionTransfer.getTransfer().getSelection();
        }
    });
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer)

Aggregations

DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)37 DragSource (org.eclipse.swt.dnd.DragSource)24 DragSourceListener (org.eclipse.swt.dnd.DragSourceListener)18 DragSourceAdapter (org.eclipse.swt.dnd.DragSourceAdapter)16 Transfer (org.eclipse.swt.dnd.Transfer)16 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)11 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 Composite (org.eclipse.swt.widgets.Composite)10 TreeItem (org.eclipse.swt.widgets.TreeItem)10 TextTransfer (org.eclipse.swt.dnd.TextTransfer)9 Display (org.eclipse.swt.widgets.Display)9 Point (org.eclipse.swt.graphics.Point)8 Button (org.eclipse.swt.widgets.Button)8 Shell (org.eclipse.swt.widgets.Shell)8 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)7 DropTarget (org.eclipse.swt.dnd.DropTarget)7 DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)6 KeyEvent (org.eclipse.swt.events.KeyEvent)6 FormAttachment (org.eclipse.swt.layout.FormAttachment)6