Search in sources :

Example 1 with DropTargetEvent

use of org.eclipse.swt.dnd.DropTargetEvent in project translationstudio8 by heartsome.

the class TableHierarchicalExample method initDND.

/**
     * Init a simple drag and drop operation for moving rows in the table.
     * 
     * @param table
     * @param parent
     */
private void initDND(final JaretTable table, Composite parent) {
    // support move only
    int operations = DND.DROP_MOVE;
    final DragSource source = new DragSource(table, operations);
    // Provide data in Text format
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    source.setTransfer(types);
    source.addDragListener(new DragSourceListener() {

        public void dragStart(DragSourceEvent event) {
            // check whether drag occured on the hierarchy column
            IColumn column = table.colForX(event.x);
            if (column != null && table.isHierarchyColumn(column)) {
                // TODO check whether a resize may have
                // higher priority
                // possible row drag
                IRow row = table.rowForY(event.y);
                if (row != null) {
                    // row hit, start row drag
                    _draggedRow = row;
                    // capture the data for internal use
                    // row drag: use row at starting position
                    _parentTableNode = getParent(table.getHierarchicalModel().getRootNode(), (ITableNode) row);
                } else {
                    event.doit = false;
                }
            }
        }

        public void dragSetData(DragSourceEvent event) {
            // Provide the data of the requested type.
            if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
                if (_draggedRow != null) {
                    event.data = "row: " + _draggedRow.getId();
                }
            }
        }

        public void dragFinished(DragSourceEvent event) {
            // for this simple case we do all the manipulations in the drop
            // target
            // this is more of a hack ...
            _draggedRow = null;
        }
    });
    // ////////////////////
    // Drop target
    // moved to the drop target
    operations = DND.DROP_MOVE;
    final DropTarget target = new DropTarget(table, operations);
    // Receive data in Text
    final TextTransfer textTransfer = TextTransfer.getInstance();
    types = new Transfer[] { textTransfer };
    target.setTransfer(types);
    target.addDropListener(new DropTargetListener() {

        public void dragEnter(DropTargetEvent event) {
        }

        public void dragOver(DropTargetEvent event) {
            if (_draggedRow != null) {
            // no drag over effect right now
            }
        }

        public void dragOperationChanged(DropTargetEvent event) {
        }

        public void dragLeave(DropTargetEvent event) {
        }

        public void dropAccept(DropTargetEvent event) {
        }

        public void drop(DropTargetEvent event) {
            // this is kind of a hack ...
            if (textTransfer.isSupportedType(event.currentDataType)) {
                String text = (String) event.data;
                System.out.println("DROP: " + text);
                if (_draggedRow != null) {
                    int destY = Display.getCurrent().map(null, table, event.x, event.y).y;
                    int destX = Display.getCurrent().map(null, table, event.x, event.y).x;
                    IRow overRow = table.rowForY(destY);
                    if (overRow != null) {
                        System.out.println("over row " + overRow.getId());
                        // this is an action from the drag source listener
                        // ...
                        // this has to be done right here because otherwise
                        // the node would be at two places
                        // at the same time causing some redraw trouble ...
                        _parentTableNode.remNode((ITableNode) _draggedRow);
                        ITableNode node = (ITableNode) overRow;
                        node.addNode((ITableNode) _draggedRow);
                    }
                }
            }
        }
    });
    // Dispose listener on parent of timebar viewer to dispose the
    // dragsource and dragtarget BEFORE the timebar
    // viewer
    // this prevents an exception beeing thrown by SWT
    parent.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            source.dispose();
            target.dispose();
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) IRow(de.jaret.util.ui.table.model.IRow) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) IColumn(de.jaret.util.ui.table.model.IColumn) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) DropTarget(org.eclipse.swt.dnd.DropTarget) ITableNode(de.jaret.util.ui.table.model.ITableNode) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 2 with DropTargetEvent

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

the class MapperDropTargetListener 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;
    }
    showTargetFeedback();
}
Also used : ISash(org.talend.designer.gefabstractmap.figures.sash.ISash) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent)

Example 3 with DropTargetEvent

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

the class AbstractElementPropertySectionController method addDragAndDropTarget.

/**
     * Accept Text and StyledText control.
     *
     * @param labelText
     */
public void addDragAndDropTarget(final Control textControl) {
    DropTargetListener dropTargetListener = new DropTargetListener() {

        String propertyName = null;

        @Override
        public void dragEnter(final DropTargetEvent event) {
        }

        @Override
        public void dragLeave(final DropTargetEvent event) {
        }

        @Override
        public void dragOperationChanged(final DropTargetEvent event) {
        }

        @Override
        public void dragOver(final DropTargetEvent event) {
            if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
                propertyName = getParameterName(textControl);
                for (int i = 0; i < elem.getElementParameters().size(); i++) {
                    IElementParameter param = elem.getElementParameters().get(i);
                    if (param.getName().equals(propertyName)) {
                        if (param.isReadOnly()) {
                            event.detail = DND.ERROR_INVALID_DATA;
                        }
                    }
                }
            }
        }

        @Override
        public void drop(final DropTargetEvent event) {
            if (propertyName != null) {
                String text;
                if (textControl instanceof StyledText) {
                    text = ((StyledText) textControl).getText() + (String) event.data;
                    ((StyledText) textControl).setText(text);
                } else {
                    text = ((Text) textControl).getText() + (String) event.data;
                    ((Text) textControl).setText(text);
                }
                Command cmd = new PropertyChangeCommand(elem, propertyName, text);
                // getCommandStack().execute(cmd);
                executeCommand(cmd);
            }
        }

        @Override
        public void dropAccept(final DropTargetEvent event) {
        }
    };
    DropTarget target = new DropTarget(textControl, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
    Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
    target.setTransfer(transfers);
    target.addDropListener(dropTargetListener);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ReconcilerStyledText(org.talend.designer.core.ui.viewer.ReconcilerStyledText) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Command(org.eclipse.gef.commands.Command) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) IElementParameter(org.talend.core.model.process.IElementParameter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) ReconcilerStyledText(org.talend.designer.core.ui.viewer.ReconcilerStyledText) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 4 with DropTargetEvent

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

use of org.eclipse.swt.dnd.DropTargetEvent 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)

Aggregations

DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)18 DropTarget (org.eclipse.swt.dnd.DropTarget)12 DropTargetAdapter (org.eclipse.swt.dnd.DropTargetAdapter)8 ArrayList (java.util.ArrayList)4 Transfer (org.eclipse.swt.dnd.Transfer)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 ViewerDropAdapter (org.eclipse.jface.viewers.ViewerDropAdapter)3 DragSource (org.eclipse.swt.dnd.DragSource)3 TextTransfer (org.eclipse.swt.dnd.TextTransfer)3 TransferData (org.eclipse.swt.dnd.TransferData)3 RepositoryBundle (bndtools.model.repo.RepositoryBundle)2 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)2 File (java.io.File)2 URI (java.net.URI)2 List (java.util.List)2 IResource (org.eclipse.core.resources.IResource)2 ISelection (org.eclipse.jface.viewers.ISelection)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2