Search in sources :

Example 16 with Transfer

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

the class ClipboardExample method createRTFTransfer.

void createRTFTransfer(Composite copyParent, Composite pasteParent) {
    // RTF Transfer
    Label l = new Label(copyParent, SWT.NONE);
    // $NON-NLS-1$
    l.setText("RTFTransfer:");
    final Text copyRtfText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    copyRtfText.setText("some\nrtf\ntext");
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    copyRtfText.setLayoutData(data);
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        String textData = copyRtfText.getText();
        if (textData.length() > 0) {
            status.setText("");
            StringBuilder buffer = new StringBuilder();
            buffer.append("{\\rtf1\\ansi\\uc1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i ");
            for (int i = 0; i < textData.length(); i++) {
                char ch = textData.charAt(i);
                if (ch > 0xFF) {
                    buffer.append("\\u");
                    buffer.append(Integer.toString((short) ch));
                    buffer.append('?');
                } else {
                    if (ch == '}' || ch == '{' || ch == '\\') {
                        buffer.append('\\');
                    }
                    buffer.append(ch);
                    if (ch == '\n')
                        buffer.append("\\par ");
                    if (ch == '\r' && (i - 1 == textData.length() || textData.charAt(i + 1) != '\n')) {
                        buffer.append("\\par ");
                    }
                }
            }
            buffer.append("}");
            clipboard.setContents(new Object[] { buffer.toString() }, new Transfer[] { RTFTransfer.getInstance() });
        } else {
            status.setText("No RTF to copy");
        }
    }));
    l = new Label(pasteParent, SWT.NONE);
    // $NON-NLS-1$
    l.setText("RTFTransfer:");
    final Text pasteRtfText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    pasteRtfText.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        String textData = (String) clipboard.getContents(RTFTransfer.getInstance());
        if (textData != null && textData.length() > 0) {
            status.setText("");
            pasteRtfText.setText("start paste>" + textData + "<end paste");
        } else {
            status.setText("No RTF to paste");
        }
    }));
}
Also used : RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) StyledText(org.eclipse.swt.custom.StyledText) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) ImageData(org.eclipse.swt.graphics.ImageData) Table(org.eclipse.swt.widgets.Table) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) ImageDataProvider(org.eclipse.swt.graphics.ImageDataProvider) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) Composite(org.eclipse.swt.widgets.Composite) 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) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display) Group(org.eclipse.swt.widgets.Group) File(java.io.File) Transfer(org.eclipse.swt.dnd.Transfer) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) List(org.eclipse.swt.widgets.List) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) Transfer(org.eclipse.swt.dnd.Transfer) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text)

Example 17 with Transfer

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

the class ClipboardExample method createHTMLTransfer.

void createHTMLTransfer(Composite copyParent, Composite pasteParent) {
    // HTML Transfer
    Label l = new Label(copyParent, SWT.NONE);
    // $NON-NLS-1$
    l.setText("HTMLTransfer:");
    final Text copyHtmlText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    copyHtmlText.setText("<b>Hello World</b>");
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    copyHtmlText.setLayoutData(data);
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        String textData = copyHtmlText.getText();
        if (textData.length() > 0) {
            status.setText("");
            clipboard.setContents(new Object[] { textData }, new Transfer[] { HTMLTransfer.getInstance() });
        } else {
            status.setText("No HTML to copy");
        }
    }));
    l = new Label(pasteParent, SWT.NONE);
    // $NON-NLS-1$
    l.setText("HTMLTransfer:");
    final Text pasteHtmlText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    pasteHtmlText.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        String textData = (String) clipboard.getContents(HTMLTransfer.getInstance());
        if (textData != null && textData.length() > 0) {
            status.setText("");
            pasteHtmlText.setText("start paste>" + textData + "<end paste");
        } else {
            status.setText("No HTML to paste");
        }
    }));
}
Also used : RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) StyledText(org.eclipse.swt.custom.StyledText) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) ImageData(org.eclipse.swt.graphics.ImageData) Table(org.eclipse.swt.widgets.Table) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) ImageDataProvider(org.eclipse.swt.graphics.ImageDataProvider) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) Composite(org.eclipse.swt.widgets.Composite) 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) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display) Group(org.eclipse.swt.widgets.Group) File(java.io.File) Transfer(org.eclipse.swt.dnd.Transfer) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) List(org.eclipse.swt.widgets.List) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) Transfer(org.eclipse.swt.dnd.Transfer) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text)

Example 18 with Transfer

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

the class Bug497705_BrowserDragDetect method setDrop.

public static void setDrop(final Label label) {
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
    DropTarget target = new DropTarget(label, operations);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {

        @Override
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            label.setText((String) event.data);
        }
    });
}
Also used : DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 19 with Transfer

use of org.eclipse.swt.dnd.Transfer in project pentaho-kettle by pentaho.

the class ExpandedContentManager method createExpandedContent.

/**
 * createExpandedContent( TransGraph parent )
 *
 * Create a web browser for the TransGraph argument.
 *
 * @param parent
 *          a TransGraph that will be the parent of the web browser.
 * @param url
 *          The content to open and expand
 */
public static void createExpandedContent(TransGraph parent, String url) {
    if (parent == null) {
        return;
    }
    Browser browser = getExpandedContentForTransGraph(parent);
    if (browser == null) {
        browser = new Browser(parent, SWT.NONE);
        browser.addKeyListener(new KeyListener() {

            @Override
            public void keyPressed(KeyEvent keyEvent) {
                int state = keyEvent.stateMask, key = keyEvent.keyCode;
                boolean copyContent = state == SWT.CTRL && key == SWT.F6, arrowNavigation = (state == SWT.COMMAND || state == SWT.ALT) && (key == SWT.ARROW_LEFT || key == SWT.ARROW_RIGHT), backslashNavigation = (state == SWT.SHIFT && key == SWT.BS), reloadContent = state == SWT.CTRL && (key == SWT.F5 || key == 114) || key == SWT.F5, zoomContent = state == SWT.CTRL && (key == SWT.KEYPAD_ADD || key == SWT.KEYPAD_SUBTRACT || key == 61 || /* + key */
                key == 45);
                if (copyContent) {
                    Browser thisBrowser = (Browser) keyEvent.getSource();
                    Clipboard clipboard = new Clipboard(thisBrowser.getDisplay());
                    clipboard.setContents(new String[] { lastNavigateURL }, new Transfer[] { TextTransfer.getInstance() });
                    clipboard.dispose();
                } else if (arrowNavigation || backslashNavigation || reloadContent || zoomContent) {
                    keyEvent.doit = false;
                }
            }

            @Override
            public void keyReleased(KeyEvent keyEvent) {
            }
        });
    }
    browser.setUrl(url);
    lastNavigateURL = url;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) KeyListener(org.eclipse.swt.events.KeyListener) Clipboard(org.eclipse.swt.dnd.Clipboard) Browser(org.eclipse.swt.browser.Browser)

Example 20 with Transfer

use of org.eclipse.swt.dnd.Transfer in project pentaho-kettle by pentaho.

the class RepositoryExplorerDialog method open.

public RepositoryObjectReference open() {
    debug = "opening repository explorer";
    try {
        debug = "open new independent shell";
        Shell parent = getParent();
        Display display = parent.getDisplay();
        shell = new Shell(display, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
        props.setLook(shell);
        shell.setImage(GUIResource.getInstance().getImageFolderConnections());
        shell.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Title") + rep.getName() + "]");
        FormLayout formLayout = new FormLayout();
        formLayout.marginWidth = Const.FORM_MARGIN;
        formLayout.marginHeight = Const.FORM_MARGIN;
        shell.setLayout(formLayout);
        // Add a small toolbar to expand/collapse all items
        // 
        ToolBar treeTb = new ToolBar(shell, SWT.HORIZONTAL | SWT.FLAT);
        props.setLook(treeTb);
        fdTreeTb = new FormData();
        fdTreeTb.left = new FormAttachment(0, 0);
        fdTreeTb.top = new FormAttachment(0, 0);
        treeTb.setLayoutData(fdTreeTb);
        // Add the items...
        // 
        exportToXML = new ToolItem(treeTb, SWT.PUSH);
        exportToXML.setImage(GUIResource.getInstance().getImageExport());
        exportToXML.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExportToXML.Label"));
        exportToXML.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExportToXML.Tooltip"));
        importFromXML = new ToolItem(treeTb, SWT.PUSH);
        importFromXML.setImage(GUIResource.getInstance().getImageImport());
        importFromXML.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ImportFromXML.Label"));
        importFromXML.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ImportFromXML.Tooltip"));
        new ToolItem(treeTb, SWT.SEPARATOR);
        showHideDeleted = new ToolItem(treeTb, SWT.PUSH);
        showHideDeleted.setImage(GUIResource.getInstance().getImageShowDeleted());
        showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Label"));
        showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Tooltip"));
        showHideDeleted.setEnabled(rep.getRepositoryMeta().getRepositoryCapabilities().supportsRevisions());
        new ToolItem(treeTb, SWT.SEPARATOR);
        expandAll = new ToolItem(treeTb, SWT.PUSH);
        expandAll.setImage(GUIResource.getInstance().getImageExpandAll());
        expandAll.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExpandAll.Label"));
        expandAll.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExpandAll.Tooltip"));
        collapseAll = new ToolItem(treeTb, SWT.PUSH);
        collapseAll.setImage(GUIResource.getInstance().getImageCollapseAll());
        collapseAll.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.CollapseAll.Label"));
        collapseAll.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.CollapseAll.Tooltip"));
        // Tree
        wTree = new Tree(shell, SWT.MULTI | SWT.BORDER);
        wTree.setHeaderVisible(true);
        props.setLook(wTree);
        // Add some columns to it as well...
        nameColumn = new TreeColumn(wTree, SWT.LEFT);
        nameColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Name"));
        nameColumn.setWidth(350);
        nameColumn.setAlignment(10);
        nameColumn.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                setSort(0);
            }
        });
        // No sorting on the type column just yet.
        typeColumn = new TreeColumn(wTree, SWT.LEFT);
        typeColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Type"));
        typeColumn.setWidth(100);
        typeColumn.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                setSort(1);
            }
        });
        userColumn = new TreeColumn(wTree, SWT.LEFT);
        userColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.User"));
        userColumn.setWidth(100);
        userColumn.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                setSort(2);
            }
        });
        changedColumn = new TreeColumn(wTree, SWT.LEFT);
        changedColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Changed"));
        changedColumn.setWidth(120);
        changedColumn.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                setSort(3);
            }
        });
        descriptionColumn = new TreeColumn(wTree, SWT.LEFT);
        descriptionColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Description"));
        descriptionColumn.setWidth(120);
        descriptionColumn.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                setSort(4);
            }
        });
        lockColumn = new TreeColumn(wTree, SWT.LEFT);
        lockColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.LockMessage"));
        lockColumn.setWidth(120);
        lockColumn.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                setSort(5);
            }
        });
        // Add a memory to the tree.
        TreeMemory.addTreeListener(wTree, STRING_REPOSITORY_EXPLORER_TREE_NAME);
        // Buttons
        wOK = new Button(shell, SWT.PUSH);
        wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
        FormData fdTree = new FormData();
        int margin = 10;
        // To the right of the label
        fdTree.left = new FormAttachment(0, 0);
        fdTree.top = new FormAttachment(treeTb, 0);
        fdTree.right = new FormAttachment(100, 0);
        fdTree.bottom = new FormAttachment(100, -50);
        wTree.setLayoutData(fdTree);
        BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK }, margin, null);
        // Add listeners
        wOK.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                close();
            }
        });
        wTree.addMenuDetectListener(new MenuDetectListener() {

            @Override
            public void menuDetected(MenuDetectEvent e) {
                setTreeMenu();
            }
        });
        wTree.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDoubleClick(MouseEvent e) {
                if (e.button == 1) {
                    // left double click!
                    doDoubleClick();
                }
            }
        });
        wTree.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                // F2 --> rename...
                if (e.keyCode == SWT.F2) {
                    if (!readonly) {
                        renameInTree();
                    }
                }
                // F5 --> refresh...
                if (e.keyCode == SWT.F5) {
                    refreshTree();
                }
            }
        });
        expandAll.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                expandAllItems(wTree.getItems(), true);
            }
        });
        collapseAll.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                expandAllItems(wTree.getItems(), false);
            }
        });
        importFromXML.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                importAll();
            }
        });
        exportToXML.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                exportAll(null);
            }
        });
        showHideDeleted.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                includeDeleted = !includeDeleted;
                if (includeDeleted) {
                    showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.HideDeleted.Label"));
                    showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.HideDeleted.Tooltip"));
                } else {
                    showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Label"));
                    showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Tooltip"));
                }
                refreshTree();
            }
        });
        // Drag & Drop
        Transfer[] ttypes = new Transfer[] { TextTransfer.getInstance() };
        DragSource ddSource = new DragSource(wTree, DND.DROP_MOVE);
        ddSource.setTransfer(ttypes);
        ddSource.addDragListener(new DragSourceListener() {

            @Override
            public void dragStart(DragSourceEvent event) {
                debug = "drag start";
                event.doit = true;
            }

            @Override
            public void dragSetData(DragSourceEvent event) {
                debug = "drag set data";
                event.data = "";
                event.doit = false;
                TreeItem[] ti = wTree.getSelection();
                if (ti.length >= 1) {
                    int cat = getItemCategory(ti[0]);
                    // 
                    if (cat == ITEM_CATEGORY_TRANSFORMATION) {
                        debug = "drag set: drag around transformation";
                        RepositoryDirectoryInterface repdir = getDirectory(ti[0]);
                        if (repdir != null) {
                            // 
                            // Pass info as a piece of XML
                            // 
                            String xml = XMLHandler.getXMLHeader();
                            xml += "<dragdrop>" + Const.CR;
                            xml += "  " + XMLHandler.addTagValue("directory", repdir.getPath());
                            xml += "  " + XMLHandler.addTagValue("transformation", ti[0].getText());
                            xml += "</dragdrop>" + Const.CR;
                            event.data = xml;
                            event.doit = true;
                        }
                    } else if (cat == ITEM_CATEGORY_JOB) {
                        debug = "drag set: drag around job";
                        RepositoryDirectoryInterface repdir = getDirectory(ti[0]);
                        if (repdir != null) {
                            // 
                            // Pass info as a piece of XML
                            // 
                            String xml = XMLHandler.getXMLHeader();
                            xml += "<dragdrop>" + Const.CR;
                            xml += "  " + XMLHandler.addTagValue("directory", repdir.getPath());
                            xml += "  " + XMLHandler.addTagValue("job", ti[0].getText());
                            xml += "</dragdrop>" + Const.CR;
                            event.data = xml;
                            event.doit = true;
                        }
                    } else {
                        debug = "do nothing";
                        String xml = XMLHandler.getXMLHeader();
                        xml += "<dragdrop>" + Const.CR;
                        xml += "</dragdrop>" + Const.CR;
                        event.data = xml;
                        event.doit = true;
                    }
                }
            }

            @Override
            public void dragFinished(DragSourceEvent event) {
            }
        });
        DropTarget ddTarget = new DropTarget(wTree, DND.DROP_MOVE);
        ddTarget.setTransfer(ttypes);
        ddTarget.addDropListener(new DropTargetListener() {

            @Override
            public void dragEnter(DropTargetEvent event) {
            }

            @Override
            public void dragLeave(DropTargetEvent event) {
                debug = "drag leave";
            }

            @Override
            public void dragOperationChanged(DropTargetEvent event) {
            }

            @Override
            public void dragOver(DropTargetEvent event) {
                debug = "drag over";
            }

            @Override
            public void drop(DropTargetEvent event) {
                try {
                    debug = "Drop item in tree";
                    if (event.data == null) {
                        // no data to copy, indicate failure in event.detail
                        event.detail = DND.DROP_NONE;
                        return;
                    }
                    // event.feedback = DND.FEEDBACK_NONE;
                    TreeItem ti = (TreeItem) event.item;
                    if (ti != null) {
                        debug = "Get category";
                        int category = getItemCategory(ti);
                        if (category == ITEM_CATEGORY_TRANSFORMATION_DIRECTORY || category == ITEM_CATEGORY_TRANSFORMATION) {
                            debug = "Get directory";
                            RepositoryDirectoryInterface repdir = getDirectory(ti);
                            if (repdir != null) {
                                event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
                                if (moveTransformation((String) event.data, repdir)) {
                                    refreshTree();
                                } else {
                                    MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
                                    mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.UnableToMove.Message"));
                                    mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.UnableToMove.Title"));
                                    mb.open();
                                }
                            }
                        } else if (category == ITEM_CATEGORY_JOB_DIRECTORY || category == ITEM_CATEGORY_JOB) {
                            debug = "Get directory";
                            RepositoryDirectoryInterface repdir = getDirectory(ti);
                            if (repdir != null) {
                                event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
                                if (moveJob((String) event.data, repdir)) {
                                    refreshTree();
                                } else {
                                    MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
                                    mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.UnableToMove.Message"));
                                    mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.UnableToMove.Title"));
                                    mb.open();
                                }
                            }
                        } else {
                            MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
                            mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.SorryOneItemAtATime.Message"));
                            mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.SorryOneItemAtATime.Title"));
                            mb.open();
                        }
                    }
                } catch (Throwable e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Message1") + debug + "]" + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Message2"), e);
                }
            }

            @Override
            public void dropAccept(DropTargetEvent event) {
                debug = "drop accept";
            }
        });
        // Detect X or ALT-F4 or something that kills this window...
        shell.addShellListener(new ShellAdapter() {

            @Override
            public void shellClosed(ShellEvent e) {
                close();
            }
        });
        debug = "set screen size and position";
        BaseStepDialog.setSize(shell, 400, 480, true);
        // refreshes too.
        setSort(0);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    } catch (Throwable e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message1") + debug + "]" + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message2") + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message3"), e);
    }
    return lastOpened;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Listener(org.eclipse.swt.widgets.Listener) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) TreeItem(org.eclipse.swt.widgets.TreeItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ShellEvent(org.eclipse.swt.events.ShellEvent) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) KeyEvent(org.eclipse.swt.events.KeyEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Shell(org.eclipse.swt.widgets.Shell) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) Button(org.eclipse.swt.widgets.Button) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) FormAttachment(org.eclipse.swt.layout.FormAttachment) ToolItem(org.eclipse.swt.widgets.ToolItem) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ShellAdapter(org.eclipse.swt.events.ShellAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSource(org.eclipse.swt.dnd.DragSource) MessageBox(org.eclipse.swt.widgets.MessageBox) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) ToolBar(org.eclipse.swt.widgets.ToolBar) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) FocusEvent(org.eclipse.swt.events.FocusEvent) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) DropTarget(org.eclipse.swt.dnd.DropTarget) Display(org.eclipse.swt.widgets.Display)

Aggregations

Transfer (org.eclipse.swt.dnd.Transfer)145 TextTransfer (org.eclipse.swt.dnd.TextTransfer)66 Point (org.eclipse.swt.graphics.Point)61 Clipboard (org.eclipse.swt.dnd.Clipboard)46 Menu (org.eclipse.swt.widgets.Menu)36 IMenuManager (org.eclipse.jface.action.IMenuManager)32 MenuManager (org.eclipse.jface.action.MenuManager)32 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)32 Separator (org.eclipse.jface.action.Separator)31 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)22 GridLayout (org.eclipse.swt.layout.GridLayout)21 Composite (org.eclipse.swt.widgets.Composite)21 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)20