Search in sources :

Example 96 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.

the class ImportResultDialog method copyDataToClipboard.

/**
	 *
	 * Copy the selected data to clipboard
	 *
	 */
private void copyDataToClipboard() {
    // FIXME move this logic to core module
    TextTransfer textTransfer = TextTransfer.getInstance();
    Clipboard clipboard = CommonUITool.getClipboard();
    StringBuilder content = new StringBuilder();
    TableItem[] items = table.getSelection();
    for (int i = 0; i < items.length; i++) {
        content.append(items[i].getText(1) + System.getProperty("line.separator"));
    }
    String data = content.toString();
    if (data != null && !data.equals("")) {
        clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 97 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.

the class CommonUITool method getClipboard.

/**
	 * Return clipboard object
	 *
	 * @return the Clipboard object
	 */
public static Clipboard getClipboard() {
    synchronized (CommonUITool.class) {
        if (clipboard == null) {
            clipboard = new Clipboard(Display.getDefault());
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent event) {
                    clipboard.dispose();
                    clipboard = null;
                }
            });
        }
        return clipboard;
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Clipboard(org.eclipse.swt.dnd.Clipboard) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 98 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.

the class CommonUITool method getTextContentFromClipboard.

/**
	 *
	 * Get text content from clipboard
	 *
	 * @return the string from clipboard
	 */
public static String getTextContentFromClipboard() {
    Clipboard clipboard = CommonUITool.getClipboard();
    TextTransfer textTransfer = TextTransfer.getInstance();
    Object obj = clipboard.getContents(textTransfer);
    if (obj == null) {
        return "";
    } else {
        return (String) obj;
    }
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 99 with Clipboard

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

the class ResultSetUtils method getAttributeValueFromClipboard.

@Nullable
public static Object getAttributeValueFromClipboard(DBDAttributeBinding attribute) throws DBCException {
    DBPDataSource dataSource = attribute.getDataSource();
    Clipboard clipboard = new Clipboard(Display.getCurrent());
    try (DBCSession session = DBUtils.openUtilSession(VoidProgressMonitor.INSTANCE, dataSource, "Copy from clipboard")) {
        String strValue = (String) clipboard.getContents(TextTransfer.getInstance());
        return attribute.getValueHandler().getValueFromObject(session, attribute.getAttribute(), strValue, true);
    } finally {
        clipboard.dispose();
    }
}
Also used : DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) Clipboard(org.eclipse.swt.dnd.Clipboard) Nullable(org.jkiss.code.Nullable)

Example 100 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.

the class CopyAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    TextTransfer textTransfer = TextTransfer.getInstance();
    Clipboard clipboard = CommonUITool.getClipboard();
    Control control = getFocusProvider();
    if (control instanceof StyledText) {
        StyledText stext = (StyledText) control;
        String data = stext.getSelectionText();
        if (data != null && !data.equals("")) {
            clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            FocusAction.changeActionStatus(pasteAction, stext);
        }
    } else {
        /*Copy from the active editor*/
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window != null) {
            IEditorPart editor = window.getActivePage().getActiveEditor();
            if (editor != null && editor instanceof ICopiableFromTable) {
                ICopiableFromTable copyAbleEditor = (ICopiableFromTable) editor;
                copyAbleEditor.copySelectedItems();
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ICopiableFromTable(com.cubrid.common.ui.query.editor.ICopiableFromTable) Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) IAction(org.eclipse.jface.action.IAction) Clipboard(org.eclipse.swt.dnd.Clipboard) IEditorPart(org.eclipse.ui.IEditorPart) 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