Search in sources :

Example 61 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project epp.mpc by eclipse.

the class ShareSolutionLink method openNewMail.

protected void openNewMail() {
    String subject = NLS.bind(Messages.ShareSolutionLink_mailSubject, new Object[] { catalogItem.getName() });
    String body = computeMessage();
    String recipient = Messages.ShareSolutionLink_recipient;
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String mailToString = "mailto:" + recipient + "?subject=" + subject + "&body=" + body;
    try {
        URI uri = URIUtil.fromString(mailToString);
        openMail(uri);
    } catch (Exception e) {
        boolean copyToClipboard = MessageDialog.openQuestion(WorkbenchUtil.getShell(), Messages.ShareSolutionLink_share, Messages.ShareSolutionLink_failed_to_open_manually_share);
        if (copyToClipboard) {
            Clipboard clipboard = new Clipboard(control.getDisplay());
            TextTransfer textTransfer = TextTransfer.getInstance();
            Transfer[] transfers = new Transfer[] { textTransfer };
            Object[] data = new Object[] { body };
            clipboard.setContents(data, transfers);
            clipboard.dispose();
        }
        MarketplaceClientUi.error(e);
    }
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 62 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project webtools.servertools by eclipse.

the class TextAction method copy.

/**
 * Copies the selected text to the clipboard.  The text will be put in the
 * clipboard in plain text format.
 */
public void copy() {
    Point selection = getControlSelection();
    Control control = getControl();
    if (control == null)
        return;
    if (control instanceof Text) {
        Text textcontrol = (Text) control;
        if ((textcontrol.getStyle() & SWT.PASSWORD) != 0)
            return;
    }
    String text = getControlText();
    if (selection == null || text == null)
        return;
    int length = selection.y - selection.x;
    if (length > 0) {
        TextTransfer plainTextTransfer = TextTransfer.getInstance();
        try {
            clipboard.setContents(new String[] { text.substring(selection.x, selection.y) }, new Transfer[] { plainTextTransfer });
        } catch (SWTError error) {
        // Copy to clipboard failed. This happens when another application
        // is accessing the clipboard while we copy. Ignore the error.
        }
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) Control(org.eclipse.swt.widgets.Control) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 63 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project core by jcryptool.

the class HexTextbox method paste.

@Override
public void paste() {
    final Clipboard cb = new Clipboard(this.getDisplay());
    TextTransfer transfer = TextTransfer.getInstance();
    String data = (String) cb.getContents(transfer);
    for (int i = 0; i < data.length(); i++) enteredCharacter(data.charAt(i));
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 64 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project tdq-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 = _table.getSelection();
        if (items == null || items.length == 0) {
            return;
        }
        int columnIndex = _cursor.getColumn();
        TableColumn column = _table.getColumn(columnIndex);
        clipBoard.setContents(new Object[] { column.getText() }, new Transfer[] { textTransfer });
    } catch (Exception e) {
        SQLExplorerPlugin.error(Messages.getString("CopyColumnNameAction.error"), 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 65 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project tdq-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 = _table.getSelection();
        if (items == null || items.length == 0) {
            return;
        }
        int columnIndex = _cursor.getColumn();
        clipBoard.setContents(new Object[] { items[0].getText(columnIndex) }, new Transfer[] { textTransfer });
    } catch (Exception e) {
        SQLExplorerPlugin.error("Error exporting cell to clipboard ", e);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

TextTransfer (org.eclipse.swt.dnd.TextTransfer)77 Clipboard (org.eclipse.swt.dnd.Clipboard)65 Point (org.eclipse.swt.graphics.Point)19 Transfer (org.eclipse.swt.dnd.Transfer)18 TableItem (org.eclipse.swt.widgets.TableItem)14 StyledText (org.eclipse.swt.custom.StyledText)10 Control (org.eclipse.swt.widgets.Control)8 Text (org.eclipse.swt.widgets.Text)6 IAction (org.eclipse.jface.action.IAction)5 HTMLTransfer (org.eclipse.swt.dnd.HTMLTransfer)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Button (org.eclipse.swt.widgets.Button)5 Composite (org.eclipse.swt.widgets.Composite)5 ArrayList (java.util.ArrayList)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Label (org.eclipse.swt.widgets.Label)4