Search in sources :

Example 96 with Transfer

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

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

the class DNDExample method createDragTypes.

private void createDragTypes(Composite parent) {
    parent.setLayout(new GridLayout());
    Button textButton = new Button(parent, SWT.CHECK);
    textButton.setText("Text Transfer");
    textButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b = (Button) e.widget;
        if (b.getSelection()) {
            addDragTransfer(TextTransfer.getInstance());
        } else {
            removeDragTransfer(TextTransfer.getInstance());
        }
    }));
    Button b = new Button(parent, SWT.CHECK);
    b.setText("RTF Transfer");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b1 = (Button) e.widget;
        if (b1.getSelection()) {
            addDragTransfer(RTFTransfer.getInstance());
        } else {
            removeDragTransfer(RTFTransfer.getInstance());
        }
    }));
    b = new Button(parent, SWT.CHECK);
    b.setText("HTML Transfer");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b2 = (Button) e.widget;
        if (b2.getSelection()) {
            addDragTransfer(HTMLTransfer.getInstance());
        } else {
            removeDragTransfer(HTMLTransfer.getInstance());
        }
    }));
    b = new Button(parent, SWT.CHECK);
    b.setText("URL Transfer");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b3 = (Button) e.widget;
        if (b3.getSelection()) {
            addDragTransfer(URLTransfer.getInstance());
        } else {
            removeDragTransfer(URLTransfer.getInstance());
        }
    }));
    b = new Button(parent, SWT.CHECK);
    b.setText("File Transfer");
    b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b4 = (Button) e.widget;
        if (b4.getSelection()) {
            addDragTransfer(FileTransfer.getInstance());
        } else {
            removeDragTransfer(FileTransfer.getInstance());
        }
    }));
    b = new Button(parent, SWT.PUSH);
    b.setText("Select File(s)");
    b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        FileDialog dialog = new FileDialog(fileList.getShell(), SWT.OPEN | SWT.MULTI);
        String result = dialog.open();
        if (result != null && result.length() > 0) {
            fileList.removeAll();
            String path = dialog.getFilterPath();
            String[] names = dialog.getFileNames();
            for (String name : names) {
                fileList.add(path + File.separatorChar + name);
            }
        }
    }));
    fileList = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData();
    data.grabExcessHorizontalSpace = true;
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    fileList.setLayoutData(data);
    // initialize state
    textButton.setSelection(true);
    addDragTransfer(TextTransfer.getInstance());
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) URL(java.net.URL) DND(org.eclipse.swt.dnd.DND) TableColumn(org.eclipse.swt.widgets.TableColumn) FontMetrics(org.eclipse.swt.graphics.FontMetrics) Point(org.eclipse.swt.graphics.Point) SWTError(org.eclipse.swt.SWTError) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) URLTransfer(org.eclipse.swt.dnd.URLTransfer) Composite(org.eclipse.swt.widgets.Composite) TreeColumn(org.eclipse.swt.widgets.TreeColumn) DropTarget(org.eclipse.swt.dnd.DropTarget) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) Display(org.eclipse.swt.widgets.Display) Transfer(org.eclipse.swt.dnd.Transfer) MenuItem(org.eclipse.swt.widgets.MenuItem) Tree(org.eclipse.swt.widgets.Tree) SWT(org.eclipse.swt.SWT) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) List(org.eclipse.swt.widgets.List) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Label(org.eclipse.swt.widgets.Label) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Table(org.eclipse.swt.widgets.Table) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) FileTransfer(org.eclipse.swt.dnd.FileTransfer) DragSource(org.eclipse.swt.dnd.DragSource) TableItem(org.eclipse.swt.widgets.TableItem) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) MalformedURLException(java.net.MalformedURLException) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) FormLayout(org.eclipse.swt.layout.FormLayout) FileDialog(org.eclipse.swt.widgets.FileDialog) FormData(org.eclipse.swt.layout.FormData) FormAttachment(org.eclipse.swt.layout.FormAttachment) Group(org.eclipse.swt.widgets.Group) TreeItem(org.eclipse.swt.widgets.TreeItem) File(java.io.File) RowLayout(org.eclipse.swt.layout.RowLayout) Menu(org.eclipse.swt.widgets.Menu) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) List(org.eclipse.swt.widgets.List) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 98 with Transfer

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

the class DNDExample method open.

public void open(Display display) {
    Shell shell = new Shell(display);
    shell.setText("Drag and Drop Example");
    shell.setLayout(new FillLayout());
    itemImage = new Image(display, DNDExample.class.getResourceAsStream("openFolder.gif"));
    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);
    parent.setLayout(new FormLayout());
    Label dragLabel = new Label(parent, SWT.LEFT);
    dragLabel.setText("Drag Source:");
    Group dragWidgetGroup = new Group(parent, SWT.NONE);
    dragWidgetGroup.setText("Widget");
    createDragWidget(dragWidgetGroup);
    Composite cLeft = new Composite(parent, SWT.NONE);
    cLeft.setLayout(new GridLayout(2, false));
    Group dragOperationsGroup = new Group(cLeft, SWT.NONE);
    dragOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
    dragOperationsGroup.setText("Allowed Operation(s):");
    createDragOperations(dragOperationsGroup);
    Group dragTypesGroup = new Group(cLeft, SWT.NONE);
    dragTypesGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
    dragTypesGroup.setText("Transfer Type(s):");
    createDragTypes(dragTypesGroup);
    dragConsole = new Text(cLeft, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    dragConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    Menu menu = new Menu(shell, SWT.POP_UP);
    MenuItem item = new MenuItem(menu, SWT.PUSH);
    item.setText("Clear");
    item.addSelectionListener(widgetSelectedAdapter(e -> dragConsole.setText("")));
    item = new MenuItem(menu, SWT.CHECK);
    item.setText("Show Event detail");
    item.addSelectionListener(widgetSelectedAdapter(e -> {
        MenuItem eItem = (MenuItem) e.widget;
        dragEventDetail = eItem.getSelection();
    }));
    dragConsole.setMenu(menu);
    Label dropLabel = new Label(parent, SWT.LEFT);
    dropLabel.setText("Drop Target:");
    Group dropWidgetGroup = new Group(parent, SWT.NONE);
    dropWidgetGroup.setText("Widget");
    createDropWidget(dropWidgetGroup);
    Composite cRight = new Composite(parent, SWT.NONE);
    cRight.setLayout(new GridLayout(2, false));
    Group dropOperationsGroup = new Group(cRight, SWT.NONE);
    dropOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 2));
    dropOperationsGroup.setText("Allowed Operation(s):");
    createDropOperations(dropOperationsGroup);
    Group dropTypesGroup = new Group(cRight, SWT.NONE);
    dropTypesGroup.setText("Transfer Type(s):");
    createDropTypes(dropTypesGroup);
    Group feedbackTypesGroup = new Group(cRight, SWT.NONE);
    feedbackTypesGroup.setText("Feedback Type(s):");
    createFeedbackTypes(feedbackTypesGroup);
    dropConsole = new Text(cRight, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    dropConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    menu = new Menu(shell, SWT.POP_UP);
    item = new MenuItem(menu, SWT.PUSH);
    item.setText("Clear");
    item.addSelectionListener(widgetSelectedAdapter(e -> dropConsole.setText("")));
    item = new MenuItem(menu, SWT.CHECK);
    item.setText("Show Event detail");
    item.addSelectionListener(widgetSelectedAdapter(e -> {
        MenuItem eItem = (MenuItem) e.widget;
        dropEventDetail = eItem.getSelection();
    }));
    dropConsole.setMenu(menu);
    if (dragEnabled)
        createDragSource();
    if (dropEnabled)
        createDropTarget();
    int height = 200;
    FormData data = new FormData();
    data.top = new FormAttachment(0, 10);
    data.left = new FormAttachment(0, 10);
    dragLabel.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(dragLabel, 10);
    data.left = new FormAttachment(0, 10);
    data.right = new FormAttachment(50, -10);
    data.height = height;
    dragWidgetGroup.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(dragWidgetGroup, 10);
    data.left = new FormAttachment(0, 10);
    data.right = new FormAttachment(50, -10);
    data.bottom = new FormAttachment(100, -10);
    cLeft.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(0, 10);
    data.left = new FormAttachment(cLeft, 10);
    dropLabel.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(dropLabel, 10);
    data.left = new FormAttachment(cLeft, 10);
    data.right = new FormAttachment(100, -10);
    data.height = height;
    dropWidgetGroup.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(dropWidgetGroup, 10);
    data.left = new FormAttachment(cLeft, 10);
    data.right = new FormAttachment(100, -10);
    data.bottom = new FormAttachment(100, -10);
    cRight.setLayoutData(data);
    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    itemImage.dispose();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) StyledText(org.eclipse.swt.custom.StyledText) URL(java.net.URL) DND(org.eclipse.swt.dnd.DND) TableColumn(org.eclipse.swt.widgets.TableColumn) FontMetrics(org.eclipse.swt.graphics.FontMetrics) Point(org.eclipse.swt.graphics.Point) SWTError(org.eclipse.swt.SWTError) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) URLTransfer(org.eclipse.swt.dnd.URLTransfer) Composite(org.eclipse.swt.widgets.Composite) TreeColumn(org.eclipse.swt.widgets.TreeColumn) DropTarget(org.eclipse.swt.dnd.DropTarget) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) Display(org.eclipse.swt.widgets.Display) Transfer(org.eclipse.swt.dnd.Transfer) MenuItem(org.eclipse.swt.widgets.MenuItem) Tree(org.eclipse.swt.widgets.Tree) SWT(org.eclipse.swt.SWT) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) List(org.eclipse.swt.widgets.List) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Label(org.eclipse.swt.widgets.Label) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Table(org.eclipse.swt.widgets.Table) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) FileTransfer(org.eclipse.swt.dnd.FileTransfer) DragSource(org.eclipse.swt.dnd.DragSource) TableItem(org.eclipse.swt.widgets.TableItem) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) MalformedURLException(java.net.MalformedURLException) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) FormLayout(org.eclipse.swt.layout.FormLayout) FileDialog(org.eclipse.swt.widgets.FileDialog) FormData(org.eclipse.swt.layout.FormData) FormAttachment(org.eclipse.swt.layout.FormAttachment) Group(org.eclipse.swt.widgets.Group) TreeItem(org.eclipse.swt.widgets.TreeItem) File(java.io.File) RowLayout(org.eclipse.swt.layout.RowLayout) Menu(org.eclipse.swt.widgets.Menu) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) FormData(org.eclipse.swt.layout.FormData) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) MenuItem(org.eclipse.swt.widgets.MenuItem) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Menu(org.eclipse.swt.widgets.Menu) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 99 with Transfer

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

the class DNDExample method removeDragTransfer.

private void removeDragTransfer(Transfer transfer) {
    if (dragTypes.length == 1) {
        dragTypes = new Transfer[0];
    } else {
        int index = -1;
        for (int i = 0; i < dragTypes.length; i++) {
            if (dragTypes[i] == transfer) {
                index = i;
                break;
            }
        }
        if (index == -1)
            return;
        Transfer[] newTypes = new Transfer[dragTypes.length - 1];
        System.arraycopy(dragTypes, 0, newTypes, 0, index);
        System.arraycopy(dragTypes, index + 1, newTypes, index, dragTypes.length - index - 1);
        dragTypes = newTypes;
    }
    if (dragSource != null) {
        dragSource.setTransfer(dragTypes);
    }
}
Also used : URLTransfer(org.eclipse.swt.dnd.URLTransfer) Transfer(org.eclipse.swt.dnd.Transfer) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) Point(org.eclipse.swt.graphics.Point)

Example 100 with Transfer

use of org.eclipse.swt.dnd.Transfer in project vorto by eclipse.

the class DatatypeTreeViewer method init.

@Override
protected void init() {
    super.init();
    int operations = DND.DROP_COPY | DND.DROP_MOVE;
    Transfer[] transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    treeViewer.addDragSupport(operations, transferTypes, new ModelDragListener(treeViewer));
    treeViewer.addDropSupport(operations, transferTypes, ModelDropListenerFactory.datatypeViewPartDropListener(treeViewer, localModelWorkspace));
}
Also used : LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) ModelDragListener(org.eclipse.vorto.perspective.dnd.ModelDragListener)

Aggregations

Transfer (org.eclipse.swt.dnd.Transfer)151 TextTransfer (org.eclipse.swt.dnd.TextTransfer)71 Point (org.eclipse.swt.graphics.Point)63 Clipboard (org.eclipse.swt.dnd.Clipboard)51 Menu (org.eclipse.swt.widgets.Menu)37 IMenuManager (org.eclipse.jface.action.IMenuManager)32 MenuManager (org.eclipse.jface.action.MenuManager)32 Separator (org.eclipse.jface.action.Separator)32 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)32 EditingDomainViewerDropAdapter (org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter)30 LocalTransfer (org.eclipse.emf.edit.ui.dnd.LocalTransfer)30 ViewerDragAdapter (org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter)30 UnwrappingSelectionProvider (org.eclipse.emf.edit.ui.provider.UnwrappingSelectionProvider)30 FileTransfer (org.eclipse.swt.dnd.FileTransfer)30 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)27 DropTarget (org.eclipse.swt.dnd.DropTarget)23 GridData (org.eclipse.swt.layout.GridData)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 Composite (org.eclipse.swt.widgets.Composite)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)20