Search in sources :

Example 26 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project erlide_eclipse by erlang.

the class ClipboardAction method run.

@Override
public void run() {
    final Clipboard cb = new Clipboard(display);
    final TextTransfer textTransfer = TextTransfer.getInstance();
    cb.setContents(new Object[] { text }, new TextTransfer[] { textTransfer });
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 27 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project liferay-ide by liferay.

the class KaleoPaletteHelper method updateDragSource.

protected void updateDragSource() {
    Transfer[] supportedTypes = { TextTransfer.getInstance() };
    /*
		 * TRH suggested use of the event's doit field by the fListeners, but
		 * there's no other way to guarantee that TextTransfer is considered
		 * last
		 */
    Iterator<TransferDragSourceListener> iterator = getTransferDragSourceListeners().iterator();
    ArrayList<TransferDragSourceListener> oldListeners = new ArrayList<>();
    while (iterator.hasNext()) {
        TransferDragSourceListener listener = iterator.next();
        oldListeners.add(listener);
        iterator.remove();
    }
    boolean addTextTransfer = false;
    for (int i = 0; i < supportedTypes.length; i++) {
        if (TextTransfer.class.equals(supportedTypes[i].getClass())) {
            addTextTransfer = true;
        } else {
            TransferDragSourceListener listener = new TransferDragSourceListenerImpl(supportedTypes[i]);
            _getPaletteViewer().addDragSourceListener(listener);
            getTransferDragSourceListeners().add(listener);
        }
    }
    iterator = oldListeners.iterator();
    while (iterator.hasNext()) {
        TransferDragSourceListener listener = iterator.next();
        _getPaletteViewer().removeDragSourceListener(listener);
        iterator.remove();
    }
    if (addTextTransfer) {
        addTextTransferListener();
    }
}
Also used : TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) TransferDragSourceListener(org.eclipse.jface.util.TransferDragSourceListener) TemplateTransferDragSourceListener(org.eclipse.gef.dnd.TemplateTransferDragSourceListener) ArrayList(java.util.ArrayList)

Example 28 with TextTransfer

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

the class TableView method pasteSelected.

private void pasteSelected() {
    int rownr = getCurrentRownr();
    if (clipboard != null) {
        clipboard.dispose();
        clipboard = null;
    }
    clipboard = new Clipboard(getDisplay());
    TextTransfer tran = TextTransfer.getInstance();
    String text = (String) clipboard.getContents(tran);
    if (text != null) {
        String[] lines = text.split(Const.CR);
        if (lines.length > 1) {
            // ALlocate complete paste grid!
            String[][] grid = new String[lines.length - 1][];
            int[] idx = new int[lines.length - 1];
            for (int i = 1; i < lines.length; i++) {
                grid[i - 1] = lines[i].split("\t");
                idx[i - 1] = rownr + i;
                addItem(idx[i - 1], grid[i - 1]);
            }
            TransAction ta = new TransAction();
            ta.setNew(grid, idx);
            addUndo(ta);
        }
        if (rownr == 0 && table.getItemCount() > rownr + 1) {
            if (isEmpty(rownr, -1)) {
                table.remove(rownr);
            }
        }
        setRowNums();
        unEdit();
        setModified();
    }
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction) Clipboard(org.eclipse.swt.dnd.Clipboard) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 29 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer 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)

Example 30 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project xtext-eclipse by eclipse.

the class TraceEditor method createPageContainer.

@Override
protected Composite createPageContainer(final Composite parent) {
    Composite tree = new Composite(parent, SWT.NONE);
    final Sash sash = new Sash(parent, SWT.HORIZONTAL);
    text = new StyledText(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    text.setFont(JFaceResources.getTextFont());
    final FormLayout form = new FormLayout();
    parent.setLayout(form);
    FormData treeData = new FormData();
    treeData.left = new FormAttachment(0, 0);
    treeData.right = new FormAttachment(100, 0);
    treeData.top = new FormAttachment(0, 0);
    treeData.bottom = new FormAttachment(sash, 0);
    tree.setLayoutData(treeData);
    final int limit = 20, percent = 50;
    final FormData sashData = new FormData();
    sashData.left = new FormAttachment(0, 0);
    sashData.top = new FormAttachment(percent, 0);
    sashData.right = new FormAttachment(100, 0);
    sash.setLayoutData(sashData);
    sash.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            Rectangle sashRect = sash.getBounds();
            Rectangle parentRect = parent.getClientArea();
            int bottom = parentRect.height - sashRect.height - limit;
            e.y = Math.max(Math.min(e.y, bottom), limit);
            if (e.y != sashRect.y) {
                sashData.top = new FormAttachment(0, e.y);
                parent.layout();
            }
        }
    });
    FormData textData = new FormData();
    textData.left = new FormAttachment(0, 0);
    textData.right = new FormAttachment(100, 0);
    textData.top = new FormAttachment(sash, 0);
    textData.bottom = new FormAttachment(100, 0);
    text.setLayoutData(textData);
    addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                try {
                    Object x = ((IStructuredSelection) selection).getFirstElement();
                    if (x instanceof EObject)
                        updateText((EObject) x);
                    if (x instanceof Resource)
                        updateText(((Resource) x).getContents().get(0));
                } catch (Exception e) {
                    text.setText(Throwables.getStackTraceAsString(e));
                }
            }
        }
    });
    Menu contextMenu = new Menu(text);
    MenuItem copyItem = new MenuItem(contextMenu, SWT.PUSH);
    copyItem.setText("&Copy");
    copyItem.setAccelerator(SWT.MOD1 | 'C');
    copyItem.setEnabled(false);
    final Clipboard cb = new Clipboard(Display.getDefault());
    copyItem.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String textData = text.getSelectionText();
            TextTransfer textTransfer = TextTransfer.getInstance();
            cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    text.setMenu(contextMenu);
    text.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final String selectionText = text.getSelectionText();
            copyItem.setEnabled(!"".equals(selectionText));
            final Point range = text.getSelectionRange();
            TraceEditor.super.setSelection(new ITextSelection() {

                @Override
                public boolean isEmpty() {
                    return "".equals(selectionText);
                }

                @Override
                public String getText() {
                    return selectionText;
                }

                @Override
                public int getStartLine() {
                    return -1;
                }

                @Override
                public int getOffset() {
                    return range.x;
                }

                @Override
                public int getLength() {
                    return range.y;
                }

                @Override
                public int getEndLine() {
                    return -1;
                }
            });
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    return tree;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) Rectangle(org.eclipse.swt.graphics.Rectangle) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EObject(org.eclipse.emf.ecore.EObject) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) Sash(org.eclipse.swt.widgets.Sash) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Resource(org.eclipse.emf.ecore.resource.Resource) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TraceNotFoundException(org.eclipse.xtext.generator.trace.TraceNotFoundException) ITextSelection(org.eclipse.jface.text.ITextSelection) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EObject(org.eclipse.emf.ecore.EObject) Clipboard(org.eclipse.swt.dnd.Clipboard) SelectionListener(org.eclipse.swt.events.SelectionListener) 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