Search in sources :

Example 11 with DropTarget

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

the class DragDropManager method addDropSupport.

public void addDropSupport(final Control control, final IDragDropDelegate delegate) {
    // Create the drop target
    DropTarget dropTarget = new DropTarget(control, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
    dropTarget.setTransfer(types);
    dropTarget.addDropListener(new DropTargetAdapter() {

        @Override
        public void dragEnter(DropTargetEvent event) {
            if (event.detail == DND.DROP_COPY && !delegate.isDropAllowed(currentSelectionText)) {
                event.detail = DND.DROP_NONE;
                return;
            }
            if (event.detail == DND.DROP_DEFAULT) {
                event.detail = DND.DROP_MOVE;
            }
            // Allow dropping text only
            for (int i = 0, n = event.dataTypes.length; i < n; i++) {
                if (TextTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
                    event.currentDataType = event.dataTypes[i];
                }
            }
        }

        @Override
        public void dragLeave(DropTargetEvent event) {
            event.detail = DND.DROP_NONE;
        }

        @Override
        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (!delegate.isDropAllowed(currentSelectionText)) {
                event.detail = DND.DROP_NONE;
                return;
            }
            if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
                // Get the dropped data
                String data = (String) event.data;
                Point point = new Point(event.x, event.y);
                delegate.onDropItems(data, point);
                dropped = true;
            }
        }
    });
}
Also used : DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTarget(org.eclipse.swt.dnd.DropTarget) Point(org.eclipse.swt.graphics.Point)

Example 12 with DropTarget

use of org.eclipse.swt.dnd.DropTarget 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 13 with DropTarget

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

the class DragAndDropForWebService method createDropTarget.

/**
     * 
     * create DropTarget.
     */
private void createDropTarget(DropTargetListener targetListener) {
    if (dropTarget != null) {
        dropTarget.dispose();
    }
    dropTarget = new DropTarget(draggableControl, DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
    dropTarget.setTransfer(new Transfer[] { TableEntriesTransfer.getInstance() });
    dropTarget.addDropListener(targetListener);
}
Also used : DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 14 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project cubrid-manager by CUBRID.

the class RunSQLFileDialogDNDController method registerDropTarget.

/**
	 * register drag source and DB tree target
	 */
public void registerDropTarget() {
    synchronized (this) {
        DropTarget target = new DropTarget(dialog.getDatabaseTableComp(), DND.DROP_MOVE);
        target.setTransfer(new Transfer[] { TextTransfer.getInstance() });
        target.addDropListener(new DropTargetAdapter() {

            /**
				 * @see org.eclipse.swt.dnd.DropTargetAdapter#drop(org.eclipse.swt.dnd.DropTargetEvent)
				 * @param event the information associated with the drop event
				 */
            public void drop(DropTargetEvent event) {
                addDatabase();
            }
        });
    }
}
Also used : DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 15 with DropTarget

use of org.eclipse.swt.dnd.DropTarget in project cubrid-manager by CUBRID.

the class ERDNDController method registerDropTarget.

public void registerDropTarget() {
    synchronized (this) {
        DropTarget dropTt = new DropTarget(editor.getGraphicalControl(), DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
        dropTt.setTransfer(new Transfer[] { TextTransfer.getInstance() });
        dropTt.addDropListener(new DropTargetAdapter() {

            @Override
            public void drop(DropTargetEvent event) {
                int scrolledH = editor.getVerticalScrollHeight();
                int scrolledW = editor.getHorizontalScrollWidth();
                List<SchemaInfo> schemaInfoList = getSelectedSchemaInfos();
                // this event x, y is full screen's
                int erdXPoint = event.x - getAppXPoint() - getNavigatorPaneWidth() - 15;
                int erdYPoint = event.y - getAppYPoint() - 160;
                // 160 is the distance between ERD canvas top and the CM/CQB
                // app top
                addTables(schemaInfoList, erdXPoint + scrolledW, erdYPoint + scrolledH);
            }
        });
    }
}
Also used : DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) ArrayList(java.util.ArrayList) List(java.util.List) DropTarget(org.eclipse.swt.dnd.DropTarget)

Aggregations

DropTarget (org.eclipse.swt.dnd.DropTarget)28 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)12 DropTargetAdapter (org.eclipse.swt.dnd.DropTargetAdapter)8 DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)8 TransferDropTargetListener (org.eclipse.jface.util.TransferDropTargetListener)6 Point (org.eclipse.swt.graphics.Point)5 Transfer (org.eclipse.swt.dnd.Transfer)4 DragSource (org.eclipse.swt.dnd.DragSource)3 TextTransfer (org.eclipse.swt.dnd.TextTransfer)3 Control (org.eclipse.swt.widgets.Control)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 StyledText (org.eclipse.swt.custom.StyledText)2 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)2 DragSourceListener (org.eclipse.swt.dnd.DragSourceListener)2 TreeDragSourceEffect (org.eclipse.swt.dnd.TreeDragSourceEffect)2 TreeDropTargetEffect (org.eclipse.swt.dnd.TreeDropTargetEffect)2 CubridDnDNodeHandler (com.cubrid.common.ui.common.navigator.dnd.CubridDnDNodeHandler)1 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)1