Search in sources :

Example 61 with Clipboard

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

the class LogEditorPart method copyDataToClipboard.

/**
	 *
	 * Copy the selected data to clipboard
	 *
	 * @param type String
	 */
private void copyDataToClipboard(String type) {
    TextTransfer textTransfer = TextTransfer.getInstance();
    Clipboard clipboard = CommonUITool.getClipboard();
    StringBuilder content = new StringBuilder();
    TableItem[] items = table.getSelection();
    for (int i = 0; i < items.length; i++) {
        if (CubridNodeType.BROKER_SQL_LOG.equals(type)) {
            content.append(items[i].getText(1) + System.getProperty("line.separator"));
        }
        if (CubridNodeType.LOGS_BROKER_ERROR_LOG.equals(type)) {
            content.append(items[i].getText(1) + blank + items[i].getText(2) + blank + items[i].getText(3) + blank + items[i].getText(4) + blank + items[i].getText(5) + blank + items[i].getText(6) + blank + System.getProperty("line.separator"));
        }
        if (CubridNodeType.LOGS_MANAGER_ERROR_LOG.equals(type)) {
            content.append(items[i].getText(1) + blank + items[i].getText(2) + blank + items[i].getText(3) + blank + items[i].getText(4) + blank + System.getProperty("line.separator"));
        }
        if (CubridNodeType.LOGS_SERVER_DATABASE_LOG.equals(type) || CubridNodeType.LOGS_APPLY_DATABASE_LOG.equals(type) || CubridNodeType.LOGS_COPY_DATABASE_LOG.equals(type)) {
            content.append(items[i].getText(1) + blank + items[i].getText(2) + blank + items[i].getText(3) + blank + items[i].getText(4) + blank + items[i].getText(5) + blank + items[i].getText(6) + blank + 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 62 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project tdi-studio-se by Talend.

the class CopyColumnNameAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.IAction#run()
     */
public void run() {
    try {
        Clipboard clipBoard = new Clipboard(Display.getCurrent());
        TextTransfer textTransfer = TextTransfer.getInstance();
        TableItem[] items = ptable.getSelection();
        if (items == null || items.length == 0) {
            return;
        }
        int columnIndex = pcursor.getColumn();
        TableColumn column = ptable.getColumn(columnIndex);
        clipBoard.setContents(new Object[] { column.getText() }, new Transfer[] { textTransfer });
    } catch (Exception e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(org.talend.sqlbuilder.Messages.getString("CopyColumnNameAction.logMessage"), e);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Clipboard(org.eclipse.swt.dnd.Clipboard) TableColumn(org.eclipse.swt.widgets.TableColumn) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 63 with Clipboard

use of org.eclipse.swt.dnd.Clipboard in project tdi-studio-se by Talend.

the class CopyCellAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.IAction#run()
     */
public void run() {
    try {
        Clipboard clipBoard = new Clipboard(Display.getCurrent());
        TextTransfer textTransfer = TextTransfer.getInstance();
        TableItem[] items = ptable.getSelection();
        if (items == null || items.length == 0) {
            return;
        }
        int columnIndex = pcursor.getColumn();
        clipBoard.setContents(new Object[] { items[0].getText(columnIndex) }, new Transfer[] { textTransfer });
    } catch (Exception e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(org.talend.sqlbuilder.Messages.getString("CopyCellAction.logMessage"), e);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 64 with Clipboard

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

the class ClipboardExample method open.

public void open(Display display) {
    clipboard = new Clipboard(display);
    shell = new Shell(display);
    shell.setText("SWT Clipboard");
    shell.setLayout(new FillLayout());
    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);
    parent.setLayout(new GridLayout(2, true));
    Group copyGroup = new Group(parent, SWT.NONE);
    copyGroup.setText("Copy From:");
    GridData data = new GridData(GridData.FILL_BOTH);
    copyGroup.setLayoutData(data);
    copyGroup.setLayout(new GridLayout(3, false));
    Group pasteGroup = new Group(parent, SWT.NONE);
    pasteGroup.setText("Paste To:");
    data = new GridData(GridData.FILL_BOTH);
    pasteGroup.setLayoutData(data);
    pasteGroup.setLayout(new GridLayout(3, false));
    Group controlGroup = new Group(parent, SWT.NONE);
    controlGroup.setText("Control API:");
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    controlGroup.setLayoutData(data);
    controlGroup.setLayout(new GridLayout(5, false));
    Group typesGroup = new Group(parent, SWT.NONE);
    typesGroup.setText("Available Types");
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    typesGroup.setLayoutData(data);
    typesGroup.setLayout(new GridLayout(2, false));
    status = new Label(parent, SWT.NONE);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    status.setLayoutData(data);
    createTextTransfer(copyGroup, pasteGroup);
    createRTFTransfer(copyGroup, pasteGroup);
    createHTMLTransfer(copyGroup, pasteGroup);
    createFileTransfer(copyGroup, pasteGroup);
    createImageTransfer(copyGroup, pasteGroup);
    createMyTransfer(copyGroup, pasteGroup);
    createControlTransfer(controlGroup);
    createAvailableTypes(typesGroup);
    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    clipboard.dispose();
}
Also used : Group(org.eclipse.swt.widgets.Group) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Clipboard(org.eclipse.swt.dnd.Clipboard) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point)

Example 65 with Clipboard

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

the class Test_org_eclipse_swt_custom_StyledText method test_cut.

@Test
public void test_cut() {
    if (SwtTestUtil.isCocoa) {
        // TODO Fix Cocoa failure.
        if (SwtTestUtil.verbose) {
            System.out.println("Excluded test_cut(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_custom_StyledText).");
        }
        return;
    }
    Clipboard clipboard = new Clipboard(text.getDisplay());
    TextTransfer transfer = TextTransfer.getInstance();
    String clipboardText;
    String convertedText;
    String before = (String) clipboard.getContents(transfer);
    text.setSelectionRange(0, 0);
    text.cut();
    clipboardText = (String) clipboard.getContents(transfer);
    assertTrue(":a:", before == null ? clipboardText == null : before.equals(clipboardText));
    before = (String) clipboard.getContents(transfer);
    text.setText("0123456789");
    text.setSelectionRange(0, 0);
    text.cut();
    clipboardText = (String) clipboard.getContents(transfer);
    assertTrue(":c:", before == null ? clipboardText == null : before.equals(clipboardText));
    text.setSelectionRange(0, 1);
    text.cut();
    clipboardText = (String) clipboard.getContents(transfer);
    assertTrue(":d:", clipboardText != null && clipboardText.equals("0"));
    text.setSelectionRange(1, 2);
    text.cut();
    clipboardText = (String) clipboard.getContents(transfer);
    assertTrue(":e:", clipboardText != null && clipboardText.equals("23"));
    // test line delimiter conversion
    text.setText("\rLine1\nLine2\r\nLine3\n\rLine4\n");
    text.setSelectionRange(0, text.getCharCount());
    text.cut();
    clipboardText = (String) clipboard.getContents(transfer);
    if (SwtTestUtil.isWindowsOS) {
        convertedText = "\r\nLine1\r\nLine2\r\nLine3\r\n\r\nLine4\r\n";
    } else {
        convertedText = "\nLine1\nLine2\nLine3\n\nLine4\n";
    }
    assertTrue(":f:", clipboardText != null && clipboardText.equals(convertedText));
    // test line delimiter conversion
    text.setText("Line1\r\nLine2");
    text.setSelectionRange(0, text.getCharCount());
    text.cut();
    clipboardText = (String) clipboard.getContents(transfer);
    if (SwtTestUtil.isWindowsOS) {
        convertedText = "Line1\r\nLine2";
    } else {
        convertedText = "Line1\nLine2";
    }
    assertTrue(":g:", clipboardText != null && clipboardText.equals(convertedText));
    clipboard.dispose();
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Test(org.junit.Test)

Aggregations

Clipboard (org.eclipse.swt.dnd.Clipboard)73 TextTransfer (org.eclipse.swt.dnd.TextTransfer)50 Transfer (org.eclipse.swt.dnd.Transfer)19 Point (org.eclipse.swt.graphics.Point)12 StyledText (org.eclipse.swt.custom.StyledText)8 Composite (org.eclipse.swt.widgets.Composite)7 Display (org.eclipse.swt.widgets.Display)7 IAction (org.eclipse.jface.action.IAction)6 ISelection (org.eclipse.jface.viewers.ISelection)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Control (org.eclipse.swt.widgets.Control)6 TableItem (org.eclipse.swt.widgets.TableItem)6 ArrayList (java.util.ArrayList)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 GridData (org.eclipse.swt.layout.GridData)5 Event (org.eclipse.swt.widgets.Event)4 Shell (org.eclipse.swt.widgets.Shell)4 Rectangle (org.eclipse.swt.graphics.Rectangle)3