Search in sources :

Example 76 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project GT by Tencent.

the class CopySelectedItemsFromTableViewAction method run.

@Override
public void run() {
    StringBuffer sb = getContents();
    clipboard = new Clipboard(Display.getCurrent());
    Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
    clipboard.setContents(new String[] { sb.toString() }, transfers);
}
Also used : TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 77 with Clipboard

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

the class GISLeafletViewer method updateToolbar.

private void updateToolbar() {
    toolBarManager.removeAll();
    toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_open, DBeaverIcons.getImageDescriptor(UIIcon.BROWSER)) {

        @Override
        public void run() {
            UIUtils.launchProgram(scriptFile.getAbsolutePath());
        }
    });
    toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_copy_as, DBeaverIcons.getImageDescriptor(UIIcon.PICTURE)) {

        @Override
        public void run() {
            Image image = new Image(Display.getDefault(), browser.getBounds());
            GC gc = new GC(image);
            try {
                browser.print(gc);
            } finally {
                gc.dispose();
            }
            ImageTransfer imageTransfer = ImageTransfer.getInstance();
            Clipboard clipboard = new Clipboard(Display.getCurrent());
            clipboard.setContents(new Object[] { image.getImageData() }, new Transfer[] { imageTransfer });
        }
    });
    toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_save_as, DBeaverIcons.getImageDescriptor(UIIcon.PICTURE_SAVE)) {

        @Override
        public void run() {
            final Shell shell = browser.getShell();
            FileDialog saveDialog = new FileDialog(shell, SWT.SAVE);
            String[] extensions = new String[SUPPORTED_FORMATS.length];
            String[] filterNames = new String[SUPPORTED_FORMATS.length];
            for (int i = 0; i < SUPPORTED_FORMATS.length; i++) {
                extensions[i] = "*." + SUPPORTED_FORMATS[i];
                filterNames[i] = SUPPORTED_FORMATS[i].toUpperCase() + " (*." + SUPPORTED_FORMATS[i] + ")";
            }
            saveDialog.setFilterExtensions(extensions);
            saveDialog.setFilterNames(filterNames);
            String filePath = DialogUtils.openFileDialog(saveDialog);
            if (filePath == null) {
                return;
            }
            int imageType = SWT.IMAGE_BMP;
            {
                String filePathLower = filePath.toLowerCase();
                if (filePathLower.endsWith(".png")) {
                    imageType = SWT.IMAGE_PNG;
                } else if (filePathLower.endsWith(".gif")) {
                    imageType = SWT.IMAGE_GIF;
                }
            }
            Image image = new Image(Display.getDefault(), browser.getBounds());
            GC gc = new GC(image);
            try {
                browser.print(gc);
            } finally {
                gc.dispose();
            }
            ImageLoader imageLoader = new ImageLoader();
            imageLoader.data = new ImageData[1];
            imageLoader.data[0] = image.getImageData();
            File outFile = new File(filePath);
            try (OutputStream fos = new FileOutputStream(outFile)) {
                imageLoader.save(fos, imageType);
            } catch (IOException e) {
                DBWorkbench.getPlatformUI().showError("Image save error", "Error saving as picture", e);
            }
            UIUtils.launchProgram(outFile.getAbsolutePath());
        }
    });
    toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_print, DBeaverIcons.getImageDescriptor(UIIcon.PRINT)) {

        @Override
        public void run() {
            GC gc = new GC(browser.getDisplay());
            try {
                browser.execute("javascript:window.print();");
            } finally {
                gc.dispose();
            }
        }
    });
    toolBarManager.add(new Separator());
    Action crsSelectorAction = new SelectCRSAction(this);
    toolBarManager.add(ActionUtils.makeActionContribution(crsSelectorAction, true));
    Action tilesSelectorAction = new SelectTilesAction(this);
    toolBarManager.add(ActionUtils.makeActionContribution(tilesSelectorAction, true));
    toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_flip, Action.AS_CHECK_BOX) {

        {
            setToolTipText(GISMessages.panel_leaflet_viewer_tool_bar_action_tool_tip_text_flip);
            setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.LINK_TO_EDITOR));
        }

        @Override
        public boolean isChecked() {
            return flipCoordinates;
        }

        @Override
        public void run() {
            flipCoordinates = !flipCoordinates;
            try {
                reloadGeometryData(lastValue, true);
            } catch (DBException e) {
                DBWorkbench.getPlatformUI().showError("Render error", "Error rendering geometry", e);
            }
            saveAttributeSettings();
            updateToolbar();
        }
    });
    toolBarManager.add(new Separator());
    toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_show_hide, Action.AS_CHECK_BOX) {

        {
            setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.PALETTE));
        }

        @Override
        public boolean isChecked() {
            return toolsVisible;
        }

        @Override
        public void run() {
            toolsVisible = !toolsVisible;
            updateControlsVisibility();
            updateToolbar();
        }
    });
    toolBarManager.update(true);
}
Also used : ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) DBException(org.jkiss.dbeaver.DBException) Action(org.eclipse.jface.action.Action) Image(org.eclipse.swt.graphics.Image) ImageData(org.eclipse.swt.graphics.ImageData) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) GC(org.eclipse.swt.graphics.GC) ImageLoader(org.eclipse.swt.graphics.ImageLoader) Separator(org.eclipse.jface.action.Separator)

Example 78 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project hale by halestudio.

the class InstanceExplorer method createControls.

/**
 * @see InstanceViewer#createControls(Composite, SchemaSpaceID)
 */
@Override
public void createControls(Composite parent, SchemaSpaceID schemaSpace) {
    main = new Composite(parent, SWT.NONE);
    main.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create());
    // selector composite
    selectorComposite = new Composite(main, SWT.NONE);
    selectorComposite.setLayoutData(GridDataFactory.swtDefaults().create());
    selectorComposite.setLayout(GridLayoutFactory.fillDefaults().create());
    // viewer composite
    Composite viewerComposite = new Composite(main, SWT.NONE);
    viewerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    TreeColumnLayout layout = new TreeColumnLayout();
    viewerComposite.setLayout(layout);
    viewer = new TreeViewer(viewerComposite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    viewer.getTree().setLinesVisible(true);
    // set content provider
    viewer.setContentProvider(new InstanceContentProvider());
    viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
    // TODO set label provider?
    // add definition columns
    TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.LEFT);
    column.getColumn().setText("Definition");
    column.setLabelProvider(new TreeColumnViewerLabelProvider(new PairLabelProvider(true, new DefinitionMetaLabelProvider(viewer, false, true))));
    layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
    // add value column
    column = new TreeViewerColumn(viewer, SWT.LEFT);
    column.getColumn().setText("Value");
    final InstanceValueLabelProvider instanceLabelProvider = new InstanceValueLabelProvider();
    column.setLabelProvider(instanceLabelProvider);
    // new PairLabelProvider(false, new LabelProvider())));
    ColumnViewerToolTipSupport.enableFor(viewer);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
    MetadataActionProvider maep = new MetadataExploreActionProvider(viewer);
    maep.setup();
    // Add an editor for copying instance values
    editor = new TreeEditor(viewer.getTree());
    editor.horizontalAlignment = SWT.RIGHT;
    viewer.getTree().addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            final ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
            // Selected cell changed?
            if (cell == null || editor.getItem() != cell.getItem() || editor.getColumn() != cell.getColumnIndex()) {
                // Clean up any previous editor control
                Control oldEditor = editor.getEditor();
                if (oldEditor != null) {
                    oldEditor.dispose();
                    editor.setEditor(null, null, 0);
                }
            }
            // No valid selected cell
            if (cell == null || cell.getColumnIndex() == 0) {
                return;
            }
            // cell didn't change
            if ((editor.getItem() == cell.getItem() && editor.getColumn() == cell.getColumnIndex())) {
                return;
            }
            // determine instance value
            Object value = ((Pair<?, ?>) cell.getViewerRow().getTreePath().getLastSegment()).getSecond();
            if (value instanceof Instance) {
                value = ((Instance) value).getValue();
            }
            // copy button
            if (value != null) {
                final String textValue = value.toString();
                if (!textValue.isEmpty()) {
                    // empty string invalid for
                    // clipboard
                    Button button = new Button(viewer.getTree(), SWT.PUSH | SWT.FLAT);
                    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
                    button.setToolTipText("Copy string value");
                    button.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            // copy content to clipboard
                            Clipboard clipBoard = new Clipboard(Display.getCurrent());
                            clipBoard.setContents(new Object[] { textValue }, new Transfer[] { TextTransfer.getInstance() });
                            clipBoard.dispose();
                        }
                    });
                    // calculate editor size
                    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                    editor.minimumHeight = size.y;
                    editor.minimumWidth = size.x;
                    editor.setEditor(button, (TreeItem) cell.getItem(), cell.getColumnIndex());
                }
            }
        }
    });
    update();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PairLabelProvider(eu.esdihumboldt.hale.ui.util.viewer.PairLabelProvider) TreeColumnViewerLabelProvider(org.eclipse.jface.viewers.TreeColumnViewerLabelProvider) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) TreeEditor(org.eclipse.swt.custom.TreeEditor) MetadataActionProvider(eu.esdihumboldt.hale.ui.views.data.internal.MetadataActionProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 79 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project hale by halestudio.

the class StackTraceErrorDialog method copyToClipboard.

/**
 * Copies the stack trace to the clipboard
 */
protected void copyToClipboard() {
    if (_clipboard != null) {
        _clipboard.dispose();
    }
    String stackTrace = stackTraceToString(_status.getException());
    _clipboard = new Clipboard(_list.getDisplay());
    _clipboard.setContents(new Object[] { stackTrace }, new Transfer[] { TextTransfer.getInstance() });
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 80 with Clipboard

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

the class StyledTextComp method checkPaste.

// Check if something is stored inside the Clipboard
private boolean checkPaste() {
    try {
        Clipboard clipboard = new Clipboard(xParent.getDisplay());
        TextTransfer transfer = TextTransfer.getInstance();
        String text = (String) clipboard.getContents(transfer);
        if (text != null && text.length() > 0) {
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        return false;
    }
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

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