Search in sources :

Example 1 with DragSource

use of org.eclipse.swt.dnd.DragSource in project tdi-studio-se by Talend.

the class SchemasTreeDnD method addDragAndDrop.

public void addDragAndDrop() {
    // drag
    DragSource source = new DragSource(getTree(), operations);
    source.setTransfer(transferTypes);
    source.addDragListener(new TreeDragSourceEffect(getTree()));
    // drop
    DropTarget target = new DropTarget(getTree(), operations);
    target.setTransfer(transferTypes);
    target.addDropListener(new TreeDropTargetEffect(getTree()) {

        private SchemasKeyData source;

        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            Widget item = event.item;
            if (item != null) {
                TreeItem treeItem = (TreeItem) event.item;
                Object data = treeItem.getData();
                if (data != null && data instanceof SchemasKeyData) {
                    this.source = (SchemasKeyData) data;
                    event.feedback = DND.FEEDBACK_EXPAND;
                    return;
                }
            }
            event.detail = DND.DROP_NONE;
        }

        @Override
        public void drop(DropTargetEvent event) {
            super.drop(event);
            if (event.item != null && source != null) {
                TreeItem item = (TreeItem) event.item;
                Object data = item.getData();
                if (data != null && data instanceof SchemasKeyData) {
                    SchemasKeyData target = (SchemasKeyData) data;
                    target.addChild(source);
                    schemaTreeViewer.refresh();
                }
            }
            source = null;
        }
    });
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Widget(org.eclipse.swt.widgets.Widget) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSource(org.eclipse.swt.dnd.DragSource) DropTarget(org.eclipse.swt.dnd.DropTarget) TreeDragSourceEffect(org.eclipse.swt.dnd.TreeDragSourceEffect) TreeDropTargetEffect(org.eclipse.swt.dnd.TreeDropTargetEffect) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData)

Example 2 with DragSource

use of org.eclipse.swt.dnd.DragSource in project tdi-studio-se by Talend.

the class SchemaXMLDragAndDropHandler method createDragSource.

/**
     * 
     * amaumont Comment method "createDragSource".
     * 
     * @param sourceListener
     */
private void createDragSource() {
    if (dragSource != null) {
        dragSource.dispose();
    }
    dragSource = new DragSource(linker.getSource(), DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
    dragSource.setTransfer(new Transfer[] { LocalDataTransfer.getInstance() });
    DragSourceListener sourceListener = new TreeDragSourceListener();
    dragSource.addDragListener(sourceListener);
}
Also used : DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) TransferDragSourceListener(org.eclipse.jface.util.TransferDragSourceListener)

Example 3 with DragSource

use of org.eclipse.swt.dnd.DragSource in project tdi-studio-se by Talend.

the class Schema2XMLDragAndDropHandler method createDragSource.

/**
     * 
     * amaumont Comment method "createDragSource".
     * 
     * @param sourceListener
     */
private void createDragSource() {
    if (dragSource != null) {
        dragSource.dispose();
    }
    dragSource = new DragSource(linker.getSource(), DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
    dragSource.setTransfer(new Transfer[] { LocalDataTransfer.getInstance() });
    DragSourceListener sourceListener = new TreeDragSourceListener();
    dragSource.addDragListener(sourceListener);
}
Also used : DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) TransferDragSourceListener(org.eclipse.jface.util.TransferDragSourceListener)

Example 4 with DragSource

use of org.eclipse.swt.dnd.DragSource in project tdi-studio-se by Talend.

the class JSONTree2SchemaDragAndDropHandler method createDragSource.

private void createDragSource() {
    if (dragSource != null) {
        dragSource.dispose();
    }
    dragSource = new DragSource(tree, DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
    dragSource.setTransfer(new Transfer[] { XPathTransfer.getInstance() });
    DragSourceListener sourceListener = new TreeDragSourceListener();
    dragSource.addDragListener(sourceListener);
}
Also used : DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) TransferDragSourceListener(org.eclipse.jface.util.TransferDragSourceListener)

Example 5 with DragSource

use of org.eclipse.swt.dnd.DragSource in project tdi-studio-se by Talend.

the class DragDropManager method addDragSupport.

public void addDragSupport(final Control control, final IDragDropDelegate delegate) {
    DragSource dragSource = new DragSource(control, DND.DROP_MOVE | DND.DROP_COPY);
    dragSource.setTransfer(types);
    dragSource.addDragListener(new DragSourceAdapter() {

        @Override
        public void dragStart(DragSourceEvent event) {
            currentSelectionText = delegate.getDragItemsAsText();
            dropped = false;
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            // Get the selected items in the drag source
            event.data = currentSelectionText;
        }

        @Override
        public void dragFinished(DragSourceEvent event) {
            if (event.detail == DND.DROP_MOVE && dropped) {
                // remove selection
                delegate.removeDragItems(currentSelectionText);
            }
        }
    });
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) DragSource(org.eclipse.swt.dnd.DragSource)

Aggregations

DragSource (org.eclipse.swt.dnd.DragSource)42 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)26 DragSourceListener (org.eclipse.swt.dnd.DragSourceListener)23 Transfer (org.eclipse.swt.dnd.Transfer)12 DropTarget (org.eclipse.swt.dnd.DropTarget)11 DragSourceAdapter (org.eclipse.swt.dnd.DragSourceAdapter)10 Button (org.eclipse.swt.widgets.Button)10 TreeItem (org.eclipse.swt.widgets.TreeItem)10 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)9 TextTransfer (org.eclipse.swt.dnd.TextTransfer)9 Display (org.eclipse.swt.widgets.Display)9 Shell (org.eclipse.swt.widgets.Shell)9 Point (org.eclipse.swt.graphics.Point)8 Label (org.eclipse.swt.widgets.Label)8 DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 FormAttachment (org.eclipse.swt.layout.FormAttachment)7 FormData (org.eclipse.swt.layout.FormData)7 FormLayout (org.eclipse.swt.layout.FormLayout)7