Search in sources :

Example 1 with DragSourceEvent

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

Example 2 with DragSourceEvent

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

the class NodeTransferDragSourceListener method getNodeTransferDragSourceListener.

public TransferDragSourceListener getNodeTransferDragSourceListener() {
    if (dragDropListener == null)
        dragDropListener = new TransferDragSourceListener() {

            TextTransfer transfer;

            public Transfer getTransfer() {
                transfer = TextTransfer.getInstance();
                return transfer;
            }

            public void dragFinished(final DragSourceEvent event) {
            }

            public void dragSetData(final DragSourceEvent event) {
                if (currentEditPart != null && currentEditPart.getParent() != null) {
                    INode node = (INode) currentEditPart.getParent().getModel();
                    String value = ElementParameterParser.parse(node, ((INodeReturn) currentEditPart.getModel()).getVarName());
                    event.data = value;
                }
            }

            public void dragStart(final DragSourceEvent event) {
                if (currentEditPart != null && currentEditPart.getParent() != null) {
                    // Make sure the process node can not be dragged and dropped.
                    if (currentEditPart.getParent().getModel() instanceof org.talend.designer.core.ui.editor.nodes.Node) {
                        event.doit = true;
                        return;
                    }
                }
                event.doit = false;
            }
        };
    return dragDropListener;
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) INode(org.talend.core.model.process.INode) INode(org.talend.core.model.process.INode) TransferDragSourceListener(org.eclipse.jface.util.TransferDragSourceListener) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 3 with DragSourceEvent

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

the class CubridNavigatorView method addDragDropSupport.

/**
	 * Add the drag drop support of tree.
	 *
	 * @param tree the tree need to drag and drop.
	 */
protected void addDragDropSupport(final Tree tree) {
    // Define 'Transfer Type', 'Operation'
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    int operations = DND.DROP_MOVE | DND.DROP_COPY;
    // DragSource
    final DragSource source = new DragSource(tree, operations);
    source.setTransfer(types);
    source.addDragListener(new DragSourceListener() {

        public void dragStart(DragSourceEvent event) {
            event.doit = false;
            if (!dataSupportDND(tree.getSelection())) {
                return;
            }
            event.doit = true;
        }

        public void dragSetData(DragSourceEvent event) {
            event.data = ((ICubridNode) tree.getSelection()[0].getData()).getLabel();
        }

        public void dragFinished(DragSourceEvent event) {
        }
    });
    addTreeDropTarget(tree);
    String perspectiveId = PerspectiveManager.getInstance().getCurrentPerspectiveId();
    // DropTarget for query editor.
    QueryEditorDNDController.registerDragSource(perspectiveId, tv);
    // DropTarget for multiple query
    MultiDBQueryDNDController.registerDragSource(perspectiveId, tv);
    // DropTarget for Run SQL file
    RunSQLFileDialogDNDController.registerDragSource(perspectiveId, tv);
    //DropTarget for ERD
    ERDNDController.registerDragSource(perspectiveId, tv);
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) DragSource(org.eclipse.swt.dnd.DragSource) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) Point(org.eclipse.swt.graphics.Point)

Example 4 with DragSourceEvent

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

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

the class FileViewer method createTableDragSource.

/**
 * Creates the Drag & Drop DragSource for items being dragged from the table.
 *
 * @return the DragSource for the table
 */
private DragSource createTableDragSource(final Table table) {
    DragSource dragSource = new DragSource(table, DND.DROP_MOVE | DND.DROP_COPY);
    dragSource.setTransfer(FileTransfer.getInstance());
    dragSource.addDragListener(new DragSourceListener() {

        TableItem[] dndSelection = null;

        String[] sourceNames = null;

        @Override
        public void dragStart(DragSourceEvent event) {
            dndSelection = table.getSelection();
            sourceNames = null;
            event.doit = dndSelection.length > 0;
            isDragging = true;
        }

        @Override
        public void dragFinished(DragSourceEvent event) {
            dragSourceHandleDragFinished(event, sourceNames);
            dndSelection = null;
            sourceNames = null;
            isDragging = false;
            handleDeferredRefresh();
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (dndSelection == null || dndSelection.length == 0)
                return;
            if (!FileTransfer.getInstance().isSupportedType(event.dataType))
                return;
            sourceNames = new String[dndSelection.length];
            for (int i = 0; i < dndSelection.length; i++) {
                File file = (File) dndSelection[i].getData(TABLEITEMDATA_FILE);
                sourceNames[i] = file.getAbsolutePath();
            }
            event.data = sourceNames;
        }
    });
    return dragSource;
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) TableItem(org.eclipse.swt.widgets.TableItem) DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) File(java.io.File)

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