Search in sources :

Example 16 with DropTargetEvent

use of org.eclipse.swt.dnd.DropTargetEvent in project cogtool by cogtool.

the class FrameEditorUI method setUpDropImageSupport.

protected void setUpDropImageSupport(final Canvas editorSubstrate) {
    ExternalImageDropTarget dropTarget = new ExternalImageDropTarget() {

        protected GraphicalWidget<?> dropTargetWidget = null;

        @Override
        protected void cancelHighlight(DropTargetEvent evt) {
            if (dropTargetWidget != null) {
                dropTargetWidget.dynamicHighlight(false);
            }
        }

        @Override
        protected void highlight(DropTargetEvent evt) {
            org.eclipse.swt.graphics.Point pt = editorSubstrate.toControl(evt.x, evt.y);
            GraphicalWidget<?> widgetFig = widgetLocatedAtXY(pt.x, pt.y);
            if (dropTargetWidget != widgetFig) {
                cancelHighlight(evt);
                if (widgetFig != null) {
                    widgetFig.dynamicHighlight(true);
                }
                dropTargetWidget = widgetFig;
            }
        }

        @Override
        protected Object buildParameters(DropTargetEvent evt, byte[] imgData) {
            org.eclipse.swt.graphics.Point pt = editorSubstrate.toControl(evt.x, evt.y);
            GraphicalWidget<?> widgetFig = widgetLocatedAtXY(pt.x, pt.y);
            IWidget selectedWidget = (widgetFig != null) ? widgetFig.getModel() : null;
            return new FrameEditorUI.CopyImageAsBackgroundParms(imgData, selectedWidget);
        }
    };
    setUpDropImage(editorSubstrate, dropTarget);
}
Also used : DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 17 with DropTargetEvent

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

the class QueryEditorDNDController method addTableDropTarget.

/**
	 * register result table target, connect drag target with drag source
	 *
	 * @param table Table
	 */
public void addTableDropTarget(Table table) {
    DropTarget resultTarget = new DropTarget(table, DND.DROP_MOVE);
    resultTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
    resultTarget.addDropListener(new DropTargetAdapter() {

        public void drop(DropTargetEvent event) {
            boolean isSuccess = replaceSql();
            if (isSuccess) {
                editor.getRunItem().notifyListeners(SWT.Selection, new Event());
            }
        }
    });
}
Also used : DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) Event(org.eclipse.swt.widgets.Event) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 18 with DropTargetEvent

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

the class CubridNavigatorView method addTreeDropTarget.

/**
	 * Add drop target
	 *
	 * @param tree Tree
	 */
private void addTreeDropTarget(final Tree tree) {
    // DropTarget for tree
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    int operations = DND.DROP_MOVE | DND.DROP_COPY;
    DropTarget target = new DropTarget(tree, operations);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {

        /**
			 * Drag item enter the tree items
			 */
        public void dragEnter(DropTargetEvent event) {
            TreeItem[] selectedItems = tree.getSelection();
            //do not support multi DROP_COPY
            if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
                event.detail = DND.DROP_NONE;
                event.feedback = DND.FEEDBACK_NONE;
            }
        }

        /**
			 * When drag operation change, check whether to support this operation
			 */
        public void dragOperationChanged(DropTargetEvent event) {
            dragEnter(event);
        }

        /**
			 * Drag item over the tree items.
			 */
        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
            if (event.item == null) {
                event.feedback = DND.FEEDBACK_NONE;
                return;
            }
            //do not support multi DROP_COPY
            TreeItem[] selectedItems = tree.getSelection();
            if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
                event.feedback = DND.FEEDBACK_NONE;
                return;
            }
            //Target TreeItem
            TreeItem targetTreeItem = (TreeItem) event.item;
            ICubridNode data = (ICubridNode) targetTreeItem.getData();
            if (dataSupportDragOver(data)) {
                if (data instanceof CubridGroupNode) {
                    event.feedback |= DND.FEEDBACK_SELECT;
                    return;
                }
                //Convert drop coordinate from Display to Tree
                Point pt = Display.getCurrent().map(null, tree, event.x, event.y);
                Rectangle bounds = targetTreeItem.getBounds();
                if (pt.y < (bounds.y + bounds.height / 2)) {
                    event.feedback |= DND.FEEDBACK_INSERT_BEFORE;
                } else {
                    //if (pt.y > bounds.y + 2 * bounds.height / 3)
                    event.feedback |= DND.FEEDBACK_INSERT_AFTER;
                }
            } else {
                event.feedback = DND.FEEDBACK_NONE;
            }
        }

        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            TreeItem[] selectedItems = tree.getSelection();
            if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
                event.detail = DND.DROP_NONE;
                return;
            }
            final int dropOperation = event.detail;
            ICubridNode dropNode = null;
            boolean insertBefore = false;
            if (event.item == null) {
                List<CubridGroupNode> allGroup = getGroupNodeManager().getAllGroupNodes();
                dropNode = allGroup.get(allGroup.size() - 1);
            } else {
                //Move under a TreeItem node
                TreeItem dropItem = (TreeItem) event.item;
                dropNode = (ICubridNode) dropItem.getData();
                Point pt = Display.getCurrent().map(null, tree, event.x, event.y);
                Rectangle bounds = dropItem.getBounds();
                if (pt.y < bounds.y + bounds.height / 2) {
                    insertBefore = true;
                }
            }
            CubridDnDNodeHandler handler = getCubridDnDNodeHandler();
            boolean isSuccess = false;
            if (insertBefore) {
                for (TreeItem si : selectedItems) {
                    ICubridNode dragNode = (ICubridNode) si.getData();
                    isSuccess = handler.handle(dragNode, dropNode, insertBefore, dropOperation) || isSuccess;
                }
            } else {
                for (int i = selectedItems.length - 1; i >= 0; i--) {
                    TreeItem si = selectedItems[i];
                    ICubridNode dragNode = (ICubridNode) si.getData();
                    isSuccess = handler.handle(dragNode, dropNode, insertBefore, dropOperation) || isSuccess;
                }
            }
            if (isSuccess) {
                Object[] objs = tv.getExpandedElements();
                setTreeInput();
                tv.setExpandedElements(objs);
            }
        }
    });
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Rectangle(org.eclipse.swt.graphics.Rectangle) CubridDnDNodeHandler(com.cubrid.common.ui.common.navigator.dnd.CubridDnDNodeHandler) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) List(java.util.List) ArrayList(java.util.ArrayList) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 19 with DropTargetEvent

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

the class UnifyHostConfigDialogDNDController method registerDropTarget.

/**
	 * register drag source and DB tree target
	 */
public void registerDropTarget() {
    synchronized (this) {
        DropTarget target = new DropTarget(dialog.getTableComposite(), 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) {
                addHost();
            }
        });
    }
}
Also used : DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 20 with DropTargetEvent

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

the class XmlDropTargetListener method handleDragOver.

@Override
public void handleDragOver() {
    getCurrentEvent().detail = DND.DROP_NONE;
    getCurrentEvent().feedback = DND.FEEDBACK_NONE;
    updateTargetRequest();
    updateTargetEditPart();
    DropTargetEvent event = getCurrentEvent();
    Object object = TemplateTransfer.getInstance().getObject();
    if (object == null) {
        event.detail = DND.DROP_NONE;
        return;
    }
    // dnd the sash
    if (object instanceof ISash) {
        handleSashDrag(event, (ISash) object);
        return;
    }
    // dnd the tree node
    if (!(object instanceof TransferedObject)) {
        event.detail = DND.DROP_NONE;
        return;
    }
    DropContextAnalyzer analyzer = new DropContextAnalyzer((TransferedObject) object, (AbstractGraphicalEditPart) getTargetEditPart(), getDropLocation());
    if (analyzer.isDropValid()) {
        event.detail = analyzer.getDetail();
        NewNodeCreationFactory factory = new NewNodeCreationFactory(analyzer.getDropType(), null);
        getCreateRequest().setFactory(factory);
    }
    showTargetFeedback();
}
Also used : ISash(org.talend.designer.gefabstractmap.figures.sash.ISash) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject)

Aggregations

DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)28 DropTarget (org.eclipse.swt.dnd.DropTarget)20 DropTargetAdapter (org.eclipse.swt.dnd.DropTargetAdapter)13 Point (org.eclipse.swt.graphics.Point)9 DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)8 Transfer (org.eclipse.swt.dnd.Transfer)7 TextTransfer (org.eclipse.swt.dnd.TextTransfer)6 DragSource (org.eclipse.swt.dnd.DragSource)5 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)3 RepositoryBundle (bndtools.model.repo.RepositoryBundle)2 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)2 URI (java.net.URI)2 List (java.util.List)2