Search in sources :

Example 81 with Clipboard

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

the class TableView method pasteSelected.

private void pasteSelected() {
    int rownr = getCurrentRownr();
    if (clipboard != null) {
        clipboard.dispose();
        clipboard = null;
    }
    clipboard = new Clipboard(getDisplay());
    TextTransfer tran = TextTransfer.getInstance();
    String text = (String) clipboard.getContents(tran);
    if (text != null) {
        String[] lines = text.split(Const.CR);
        if (lines.length > 1) {
            // ALlocate complete paste grid!
            String[][] grid = new String[lines.length - 1][];
            int[] idx = new int[lines.length - 1];
            for (int i = 1; i < lines.length; i++) {
                grid[i - 1] = lines[i].split("\t");
                idx[i - 1] = rownr + i;
                addItem(idx[i - 1], grid[i - 1]);
            }
            TransAction ta = new TransAction();
            ta.setNew(grid, idx);
            addUndo(ta);
        }
        if (rownr == 0 && table.getItemCount() > rownr + 1) {
            if (isEmpty(rownr, -1)) {
                table.remove(rownr);
            }
        }
        setRowNums();
        unEdit();
        setModified();
    }
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction) Clipboard(org.eclipse.swt.dnd.Clipboard) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 82 with Clipboard

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

use of org.eclipse.swt.dnd.Clipboard in project dbeaver by dbeaver.

the class UIUtils method setClipboardContents.

public static void setClipboardContents(Display display, Transfer transfer, Object contents) {
    Clipboard clipboard = new Clipboard(display);
    clipboard.setContents(new Object[] { contents }, new Transfer[] { transfer });
    clipboard.dispose();
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 84 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project dbeaver by dbeaver.

the class BaseChartComposite method doCopyToClipboard.

protected void doCopyToClipboard() {
    Image image = new Image(Display.getDefault(), this.getBounds());
    GC gc = new GC(image);
    try {
        this.print(gc);
    } finally {
        gc.dispose();
    }
    ImageTransfer imageTransfer = ImageTransfer.getInstance();
    Clipboard clipboard = new Clipboard(Display.getCurrent());
    clipboard.setContents(new Object[] { image.getImageData() }, new Transfer[] { imageTransfer });
}
Also used : ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 85 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project dbeaver by dbeaver.

the class NavigatorHandlerObjectCreateCopy method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell activeShell = HandlerUtil.getActiveShell(event);
    Control focusControl = activeShell.getDisplay().getFocusControl();
    if (focusControl instanceof Text) {
        ((Text) focusControl).paste();
        return null;
    } else if (focusControl instanceof StyledText) {
        ((StyledText) focusControl).paste();
        return null;
    } else if (focusControl instanceof Combo) {
        ((Combo) focusControl).paste();
        return null;
    }
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode curNode = NavigatorUtils.getSelectedNode(selection);
    if (curNode != null) {
        Clipboard clipboard = new Clipboard(Display.getDefault());
        try {
            @SuppressWarnings("unchecked") Collection<DBNNode> cbNodes = (Collection<DBNNode>) clipboard.getContents(TreeNodeTransfer.getInstance());
            if (cbNodes != null) {
                for (DBNNode nodeObject : cbNodes) {
                    if (nodeObject instanceof DBNDatabaseNode) {
                        createNewObject(HandlerUtil.getActiveWorkbenchWindow(event), curNode, ((DBNDatabaseNode) nodeObject));
                    } else if (nodeObject instanceof DBNResource && curNode instanceof DBNResource) {
                        pasteResource((DBNResource) nodeObject, (DBNResource) curNode);
                    }
                }
            } else if (curNode instanceof DBNResource) {
                String[] files = (String[]) clipboard.getContents(FileTransfer.getInstance());
                if (files != null) {
                    for (String fileName : files) {
                        final File file = new File(fileName);
                        if (file.exists()) {
                            pasteResource(file, (DBNResource) curNode);
                        }
                    }
                } else {
                    log.debug("Paste error: unsupported clipboard format. File or folder were expected.");
                    Display.getCurrent().beep();
                }
            } else {
                log.debug("Paste error: clipboard contains data in unsupported format");
                Display.getCurrent().beep();
            }
        } finally {
            clipboard.dispose();
        }
    }
    return null;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) StyledText(org.eclipse.swt.custom.StyledText) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) ISelection(org.eclipse.jface.viewers.ISelection) Collection(java.util.Collection) Clipboard(org.eclipse.swt.dnd.Clipboard) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IFile(org.eclipse.core.resources.IFile)

Aggregations

Clipboard (org.eclipse.swt.dnd.Clipboard)167 TextTransfer (org.eclipse.swt.dnd.TextTransfer)93 Transfer (org.eclipse.swt.dnd.Transfer)45 Point (org.eclipse.swt.graphics.Point)21 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)15 Composite (org.eclipse.swt.widgets.Composite)14 ISelection (org.eclipse.jface.viewers.ISelection)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 StyledText (org.eclipse.swt.custom.StyledText)12 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 TableItem (org.eclipse.swt.widgets.TableItem)10 GridData (org.eclipse.swt.layout.GridData)9 Control (org.eclipse.swt.widgets.Control)9 Image (org.eclipse.swt.graphics.Image)8 Display (org.eclipse.swt.widgets.Display)8 Label (org.eclipse.swt.widgets.Label)8 Button (org.eclipse.swt.widgets.Button)7 ArrayList (java.util.ArrayList)6 IAction (org.eclipse.jface.action.IAction)6