Search in sources :

Example 16 with DragSourceListener

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

the class JSONToSchemaDragAndDropHandler method createDragSource.

/**
     * 
     * DOC amaumont Comment method "createDragSource".
     * 
     * @param sourceListener
     */
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 17 with DragSourceListener

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

the class JSONFileDragAndDropHandler method createDragSource.

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 18 with DragSourceListener

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

the class Bug497705_BrowserDragDetect method setDrag.

public static void setDrag(final Browser browser) {
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
    final DragSource source = new DragSource(browser, operations);
    source.setTransfer(types);
    source.addDragListener(new DragSourceListener() {

        @Override
        public void dragStart(DragSourceEvent event) {
            event.doit = (browser.getText().length() != 0);
            // not ran.
            System.out.println("Drag started");
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            event.data = browser.getText();
        }

        @Override
        public void dragFinished(DragSourceEvent event) {
            if (event.detail == DND.DROP_MOVE)
                browser.setText("");
        }
    });
}
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) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener)

Example 19 with DragSourceListener

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

the class FileViewer method createTreeDragSource.

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

        TreeItem[] dndSelection = null;

        String[] sourceNames = null;

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

        @Override
        public void dragFinished(DragSourceEvent event) {
            dragSourceHandleDragFinished(event, sourceNames);
            dndSelection = null;
            sourceNames = null;
            isDragging = false;
            processedDropFiles = null;
            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(TREEITEMDATA_FILE);
                sourceNames[i] = file.getAbsolutePath();
            }
            event.data = sourceNames;
        }
    });
    return dragSource;
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) TreeItem(org.eclipse.swt.widgets.TreeItem) DragSource(org.eclipse.swt.dnd.DragSource) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) File(java.io.File)

Example 20 with DragSourceListener

use of org.eclipse.swt.dnd.DragSourceListener in project tdq-studio-se by Talend.

the class ComparisonTableViewerDNDDecorate method installDragListener.

private void installDragListener(final TableViewer targetViewer, int operations) {
    final Table table = targetViewer.getTable();
    final DragSource source = new DragSource(table, operations);
    source.setTransfer(transferTypes);
    final TableItem[] dragSourceItem = new TableItem[1];
    source.addDragListener(new DragSourceListener() {

        public void dragStart(DragSourceEvent event) {
            TableItem[] selection = table.getSelection();
            if (selection.length > 0) {
                event.doit = true;
                dragSourceItem[0] = selection[0];
                dragSelectedElement = ((IStructuredSelection) targetViewer.getSelection()).getFirstElement();
            } else {
                event.doit = false;
            }
        }

        public void dragSetData(DragSourceEvent event) {
            dragSelectedElement = ((IStructuredSelection) targetViewer.getSelection()).getFirstElement();
            event.data = dragSourceItem[0].getText();
        }

        public void dragFinished(DragSourceEvent event) {
        }
    });
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Table(org.eclipse.swt.widgets.Table) TableItem(org.eclipse.swt.widgets.TableItem) DragSource(org.eclipse.swt.dnd.DragSource) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener)

Aggregations

DragSourceListener (org.eclipse.swt.dnd.DragSourceListener)25 DragSource (org.eclipse.swt.dnd.DragSource)22 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)19 Transfer (org.eclipse.swt.dnd.Transfer)13 TextTransfer (org.eclipse.swt.dnd.TextTransfer)8 TransferDragSourceListener (org.eclipse.jface.util.TransferDragSourceListener)6 DropTarget (org.eclipse.swt.dnd.DropTarget)6 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)6 DropTargetListener (org.eclipse.swt.dnd.DropTargetListener)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Point (org.eclipse.swt.graphics.Point)5 Button (org.eclipse.swt.widgets.Button)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 Composite (org.eclipse.swt.widgets.Composite)4 Display (org.eclipse.swt.widgets.Display)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 KeyAdapter (org.eclipse.swt.events.KeyAdapter)3 KeyEvent (org.eclipse.swt.events.KeyEvent)3 File (java.io.File)2