Search in sources :

Example 36 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project tdq-studio-se by Talend.

the class DataSetTableKeyListener method keyPressed.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
     */
public void keyPressed(KeyEvent e) {
    // _logger.fatal(Integer.toString((int)e.character));
    switch(e.character) {
        case CTRL_C:
            try {
                Clipboard clipBoard = SQLExplorerPlugin.getDefault().getConnectionsView().getClipboard();
                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 ex) {
                SQLExplorerPlugin.error(Messages.getString("CopyColumnNameAction.error"), ex);
            }
            break;
        case CTRL_F:
            // column name typeahead
            createPopup();
            break;
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Clipboard(org.eclipse.swt.dnd.Clipboard) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 37 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project portfolio by buchen.

the class DisplayTextDialog method createButtonsForButtonBar.

@Override
protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    Button button = createButton(parent, 9999, Messages.LabelCopyToClipboard, false);
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (entryText.isDisposed())
                return;
            Clipboard cb = new Clipboard(Display.getCurrent());
            TextTransfer textTransfer = TextTransfer.getInstance();
            cb.setContents(new Object[] { entryText.getText() }, new Transfer[] { textTransfer });
        }
    });
}
Also used : Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 38 with TextTransfer

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

the class ShareSolutionLink method copyLinkToClipboard.

protected void copyLinkToClipboard() {
    Clipboard clipboard = new Clipboard(control.getDisplay());
    TextTransfer textTransfer = TextTransfer.getInstance();
    Transfer[] transfers = new Transfer[] { textTransfer };
    Object[] data = new Object[] { getUrl() };
    clipboard.setContents(data, transfers);
    clipboard.dispose();
}
Also used : TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 39 with TextTransfer

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

the class TextAction method update.

/**
 * Update the actions enabled/disabled state.
 */
protected void update() {
    if (getControl() == null) {
        setEnabled(false);
        return;
    }
    Point selection = getControlSelection();
    String text = getControlText();
    try {
        if (type == CUT_ACTION)
            setEnabled(text != null && text.length() > 0 && selection != null && selection.x < selection.y);
        else if (type == COPY_ACTION)
            setEnabled(text != null && text.length() > 0 && selection != null && selection.x < selection.y);
        else if (type == PASTE_ACTION) {
            Control control = getControl();
            if (!control.isEnabled()) {
                setEnabled(false);
                return;
            }
            if (!(control instanceof Text)) {
                setEnabled(false);
                return;
            }
            Text text2 = (Text) control;
            if (!text2.getEditable()) {
                setEnabled(false);
                return;
            }
            TextTransfer transfer = TextTransfer.getInstance();
            String newText = (String) clipboard.getContents(transfer);
            setEnabled(newText != null && newText.length() > 0);
        }
    } catch (Exception e) {
        if (Trace.SEVERE) {
            Trace.trace(Trace.STRING_SEVERE, "Error updating text action", e);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 40 with TextTransfer

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

the class TextAction method paste.

/**
 * Replaces the selection with the clipboard text or insert the text at
 * the current caret offset if there is no selection.
 * If the widget has the SWT.SINGLE style and the clipboard text contains
 * more than one line, only the first line without line delimiters is
 * inserted in the widget.
 */
public void paste() {
    TextTransfer transfer = TextTransfer.getInstance();
    Point selection = getControlSelection();
    String text = getControlText();
    if (selection == null)
        return;
    String newText = (String) clipboard.getContents(transfer);
    if (newText != null && newText.length() > 0) {
        if (text == null)
            text = newText;
        else
            text = text.substring(0, selection.x) + newText + text.substring(selection.y);
        setControlText(text);
        // set the selection to the end of the paste
        int x = selection.x + newText.length();
        setControlSelection(new Point(x, x));
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) 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