Search in sources :

Example 1 with URLTransfer

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

the class DNDExample method createDragSource.

private void createDragSource() {
    if (dragSource != null)
        dragSource.dispose();
    dragSource = new DragSource(dragControl, dragOperation);
    dragSource.setTransfer(dragTypes);
    dragSource.addDragListener(new DragSourceListener() {

        @Override
        public void dragFinished(org.eclipse.swt.dnd.DragSourceEvent event) {
            dragConsole.append(">>dragFinished\n");
            printEvent(event);
            dragDataText = dragDataRTF = dragDataHTML = dragDataURL = null;
            dragDataFiles = null;
            if (event.detail == DND.DROP_MOVE) {
                switch(dragControlType) {
                    case BUTTON_CHECK:
                    case BUTTON_TOGGLE:
                    case BUTTON_RADIO:
                        {
                            Button b = (Button) dragControl;
                            b.setText("");
                            break;
                        }
                    case STYLED_TEXT:
                        {
                            StyledText text = (StyledText) dragControl;
                            text.insert("");
                            break;
                        }
                    case TABLE:
                        {
                            Table table = (Table) dragControl;
                            TableItem[] items = table.getSelection();
                            for (TableItem item : items) {
                                item.dispose();
                            }
                            break;
                        }
                    case TEXT:
                        {
                            Text text = (Text) dragControl;
                            text.insert("");
                            break;
                        }
                    case TREE:
                        {
                            Tree tree = (Tree) dragControl;
                            TreeItem[] items = tree.getSelection();
                            for (TreeItem item : items) {
                                item.dispose();
                            }
                            break;
                        }
                    case CANVAS:
                        {
                            dragControl.setData("STRINGS", null);
                            dragControl.redraw();
                            break;
                        }
                    case LABEL:
                        {
                            Label label = (Label) dragControl;
                            label.setText("");
                            break;
                        }
                    case LIST:
                        {
                            List list = (List) dragControl;
                            int[] indices = list.getSelectionIndices();
                            list.remove(indices);
                            break;
                        }
                    case COMBO:
                        {
                            Combo combo = (Combo) dragControl;
                            combo.setText("");
                            break;
                        }
                }
            }
        }

        @Override
        public void dragSetData(org.eclipse.swt.dnd.DragSourceEvent event) {
            dragConsole.append(">>dragSetData\n");
            printEvent(event);
            if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = dragDataText;
            }
            if (RTFTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = dragDataRTF;
            }
            if (HTMLTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = dragDataHTML;
            }
            if (URLTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = dragDataURL;
            }
            if (FileTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = dragDataFiles;
            }
        }

        @Override
        public void dragStart(org.eclipse.swt.dnd.DragSourceEvent event) {
            dragConsole.append(">>dragStart\n");
            printEvent(event);
            dragDataFiles = fileList.getItems();
            switch(dragControlType) {
                case BUTTON_CHECK:
                case BUTTON_TOGGLE:
                case BUTTON_RADIO:
                    {
                        Button b = (Button) dragControl;
                        dragDataText = b.getSelection() ? "true" : "false";
                        break;
                    }
                case STYLED_TEXT:
                    {
                        StyledText text = (StyledText) dragControl;
                        String s = text.getSelectionText();
                        if (s.length() == 0) {
                            event.doit = false;
                        } else {
                            dragDataText = s;
                        }
                        break;
                    }
                case TABLE:
                    {
                        Table table = (Table) dragControl;
                        TableItem[] items = table.getSelection();
                        if (items.length == 0) {
                            event.doit = false;
                        } else {
                            StringBuilder buffer = new StringBuilder();
                            for (int i = 0; i < items.length; i++) {
                                buffer.append(items[i].getText());
                                if (items.length > 1 && i < items.length - 1) {
                                    buffer.append("\n");
                                }
                            }
                            dragDataText = buffer.toString();
                        }
                        break;
                    }
                case TEXT:
                    {
                        Text text = (Text) dragControl;
                        String s = text.getSelectionText();
                        if (s.length() == 0) {
                            event.doit = false;
                        } else {
                            dragDataText = s;
                        }
                        break;
                    }
                case TREE:
                    {
                        Tree tree = (Tree) dragControl;
                        TreeItem[] items = tree.getSelection();
                        if (items.length == 0) {
                            event.doit = false;
                        } else {
                            StringBuilder buffer = new StringBuilder();
                            for (int i = 0; i < items.length; i++) {
                                buffer.append(items[i].getText());
                                if (items.length > 1 && i < items.length - 1) {
                                    buffer.append("\n");
                                }
                            }
                            dragDataText = buffer.toString();
                        }
                        break;
                    }
                case CANVAS:
                    {
                        String[] strings = (String[]) dragControl.getData("STRINGS");
                        if (strings == null || strings.length == 0) {
                            event.doit = false;
                        } else {
                            StringBuilder buffer = new StringBuilder();
                            for (int i = 0; i < strings.length; i++) {
                                buffer.append(strings[i]);
                                if (strings.length > 1 && i < strings.length - 1) {
                                    buffer.append("\n");
                                }
                            }
                            dragDataText = buffer.toString();
                        }
                        break;
                    }
                case LABEL:
                    {
                        Label label = (Label) dragControl;
                        String string = label.getText();
                        if (string.length() == 0) {
                            event.doit = false;
                        } else {
                            dragDataText = string;
                        }
                        break;
                    }
                case LIST:
                    {
                        List list = (List) dragControl;
                        String[] selection = list.getSelection();
                        if (selection.length == 0) {
                            event.doit = false;
                        } else {
                            StringBuilder buffer = new StringBuilder();
                            for (int i = 0; i < selection.length; i++) {
                                buffer.append(selection[i]);
                                if (selection.length > 1 && i < selection.length - 1) {
                                    buffer.append("\n");
                                }
                            }
                            dragDataText = buffer.toString();
                        }
                        break;
                    }
                case COMBO:
                    {
                        Combo combo = (Combo) dragControl;
                        String string = combo.getText();
                        Point selection = combo.getSelection();
                        if (selection.x == selection.y) {
                            event.doit = false;
                        } else {
                            dragDataText = string.substring(selection.x, selection.y);
                        }
                        break;
                    }
                default:
                    throw new SWTError(SWT.ERROR_NOT_IMPLEMENTED);
            }
            if (dragDataText != null) {
                dragDataRTF = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;}\\cf1\\b " + dragDataText + "}";
                dragDataHTML = "<b>" + dragDataText + "</b>";
                dragDataURL = "http://" + dragDataText.replace(' ', '.');
                try {
                    new URL(dragDataURL);
                } catch (MalformedURLException e) {
                    dragDataURL = null;
                }
            }
            for (Transfer dragType : dragTypes) {
                if (dragType instanceof TextTransfer && dragDataText == null) {
                    event.doit = false;
                }
                if (dragType instanceof RTFTransfer && dragDataRTF == null) {
                    event.doit = false;
                }
                if (dragType instanceof HTMLTransfer && dragDataHTML == null) {
                    event.doit = false;
                }
                if (dragType instanceof URLTransfer && dragDataURL == null) {
                    event.doit = false;
                }
                if (dragType instanceof FileTransfer && (dragDataFiles == null || dragDataFiles.length == 0)) {
                    event.doit = false;
                }
            }
        }
    });
}
Also used : MalformedURLException(java.net.MalformedURLException) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) URL(java.net.URL) Button(org.eclipse.swt.widgets.Button) Tree(org.eclipse.swt.widgets.Tree) List(org.eclipse.swt.widgets.List) SWTError(org.eclipse.swt.SWTError) StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) URLTransfer(org.eclipse.swt.dnd.URLTransfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) DragSource(org.eclipse.swt.dnd.DragSource) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) 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) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 2 with URLTransfer

use of org.eclipse.swt.dnd.URLTransfer in project statecharts by Yakindu.

the class ExampleDropTargetInstaller method registerWithExistingTarget.

protected void registerWithExistingTarget(DropTarget target) {
    Transfer[] transfers = target.getTransfer();
    boolean exists = false;
    if (transfers != null) {
        for (Transfer transfer : transfers) {
            if (transfer instanceof URLTransfer) {
                exists = true;
                break;
            }
        }
        if (!exists) {
            Transfer[] newTransfers = new Transfer[transfers.length + 1];
            System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
            newTransfers[transfers.length] = URLTransfer.getInstance();
            target.setTransfer(newTransfers);
        }
    }
}
Also used : URLTransfer(org.eclipse.swt.dnd.URLTransfer) URLTransfer(org.eclipse.swt.dnd.URLTransfer) Transfer(org.eclipse.swt.dnd.Transfer)

Example 3 with URLTransfer

use of org.eclipse.swt.dnd.URLTransfer in project epp.mpc by eclipse.

the class MarketplaceDropAdapter method registerWithExistingTarget.

private void registerWithExistingTarget(DropTarget target) {
    Transfer[] transfers = target.getTransfer();
    boolean exists = false;
    if (transfers != null) {
        for (Transfer transfer : transfers) {
            if (transfer instanceof URLTransfer) {
                exists = true;
                break;
            }
        }
        if (!exists) {
            Transfer[] newTransfers = new Transfer[transfers.length + 1];
            System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
            newTransfers[transfers.length] = URLTransfer.getInstance();
            target.setTransfer(newTransfers);
        }
    }
}
Also used : URLTransfer(org.eclipse.swt.dnd.URLTransfer) URLTransfer(org.eclipse.swt.dnd.URLTransfer) Transfer(org.eclipse.swt.dnd.Transfer)

Example 4 with URLTransfer

use of org.eclipse.swt.dnd.URLTransfer in project egit by eclipse.

the class GitCloneDropAdapter method registerWithExistingTarget.

private void registerWithExistingTarget(DropTarget target) {
    Transfer[] transfers = target.getTransfer();
    if (transfers != null) {
        for (Transfer transfer : transfers) {
            if (transfer instanceof URLTransfer) {
                return;
            }
        }
        Transfer[] newTransfers = new Transfer[transfers.length + 1];
        System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
        newTransfers[transfers.length] = URLTransfer.getInstance();
        target.setTransfer(newTransfers);
    }
}
Also used : URLTransfer(org.eclipse.swt.dnd.URLTransfer) URLTransfer(org.eclipse.swt.dnd.URLTransfer) Transfer(org.eclipse.swt.dnd.Transfer)

Aggregations

Transfer (org.eclipse.swt.dnd.Transfer)4 URLTransfer (org.eclipse.swt.dnd.URLTransfer)4 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 SWTError (org.eclipse.swt.SWTError)1 StyledText (org.eclipse.swt.custom.StyledText)1 DragSource (org.eclipse.swt.dnd.DragSource)1 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)1 DragSourceListener (org.eclipse.swt.dnd.DragSourceListener)1 FileTransfer (org.eclipse.swt.dnd.FileTransfer)1 HTMLTransfer (org.eclipse.swt.dnd.HTMLTransfer)1 RTFTransfer (org.eclipse.swt.dnd.RTFTransfer)1 TextTransfer (org.eclipse.swt.dnd.TextTransfer)1 Point (org.eclipse.swt.graphics.Point)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Label (org.eclipse.swt.widgets.Label)1 List (org.eclipse.swt.widgets.List)1 Table (org.eclipse.swt.widgets.Table)1 TableItem (org.eclipse.swt.widgets.TableItem)1