Search in sources :

Example 56 with TextTransfer

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

use of org.eclipse.swt.dnd.TextTransfer in project eclipse.platform.text by eclipse.

the class AbstractTemplatesPage method initializeDND.

/**
 * Initializes drag and drop the template items
 */
private void initializeDND() {
    DragSourceAdapter dragListener = new DragSourceAdapter() {

        @Override
        public void dragStart(DragSourceEvent event) {
            if (getSelectedTemplates().length == 0) {
                event.doit = false;
            }
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (TemplatesTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = getSelectedTemplates();
            }
        }
    };
    fTreeViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { TemplatesTransfer.getInstance() }, dragListener);
    DropTargetAdapter dropListener = new DropTargetAdapter() {

        Transfer textTransfer = TextTransfer.getInstance();

        Transfer templateTransfer = TemplatesTransfer.getInstance();

        @Override
        public void dragEnter(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT)
                event.detail = DND.DROP_COPY;
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT)
                event.detail = DND.DROP_COPY;
        }

        @Override
        public void dragOver(DropTargetEvent event) {
            event.feedback |= DND.FEEDBACK_SCROLL;
            if (event.item == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            int index = 0;
            boolean isTemplateTransfer = false;
            while (index < event.dataTypes.length) {
                if (textTransfer.isSupportedType(event.dataTypes[index])) {
                    break;
                }
                if (templateTransfer.isSupportedType(event.dataTypes[index])) {
                    isTemplateTransfer = true;
                    break;
                }
                index++;
            }
            if (index < event.dataTypes.length) {
                event.currentDataType = event.dataTypes[index];
                if (event.detail == DND.DROP_DEFAULT || !isTemplateTransfer)
                    event.detail = DND.DROP_COPY;
                return;
            }
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (event.item == null)
                return;
            Object object = ((TreeItem) event.item).getData();
            final String contextId;
            if (object instanceof TemplateContextType)
                contextId = ((TemplateContextType) object).getId();
            else
                contextId = ((TemplatePersistenceData) object).getTemplate().getContextTypeId();
            if (textTransfer.isSupportedType(event.currentDataType)) {
                // $NON-NLS-1$ //$NON-NLS-2$
                String text = ((String) event.data).replaceAll("\\$", "\\$\\$");
                final Template template = new Template(createTemplateName(), TemplatesMessages.TemplatesPage_paste_description, contextId, text, true);
                getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        addTemplate(template);
                    }
                });
                return;
            }
            if (templateTransfer.isSupportedType(event.currentDataType)) {
                final TemplatePersistenceData[] templates = (TemplatePersistenceData[]) event.data;
                final int dropType = event.detail;
                getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (dropType == DND.DROP_COPY)
                            copyTemplates(templates, contextId);
                        else
                            moveTemplates(templates, contextId);
                    }
                });
            }
        }
    };
    Transfer[] transfers = new Transfer[] { TextTransfer.getInstance(), TemplatesTransfer.getInstance() };
    fTreeViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, dropListener);
}
Also used : DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) TreeItem(org.eclipse.swt.widgets.TreeItem) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) Point(org.eclipse.swt.graphics.Point) Template(org.eclipse.jface.text.templates.Template) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 58 with TextTransfer

use of org.eclipse.swt.dnd.TextTransfer in project linuxtools by eclipse.

the class PrepareCommitHandler method populateClipboardBuffer.

private void populateClipboardBuffer(String input) {
    TextTransfer plainTextTransfer = TextTransfer.getInstance();
    Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
    clipboard.setContents(new String[] { input }, new Transfer[] { plainTextTransfer });
    clipboard.dispose();
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 59 with TextTransfer

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

the class CopyNodeAction method run.

public void run() {
    Object[] selectedObjs = this.getSelectedObj();
    if (selectedObjs == null || selectedObjs.length == 0) {
        return;
    }
    StringBuilder names = new StringBuilder();
    for (Object obj : selectedObjs) {
        if (!(obj instanceof ICubridNode)) {
            continue;
        }
        ICubridNode cubridNode = (ICubridNode) obj;
        String type = cubridNode.getType();
        if (names.length() > 0) {
            names.append(",");
        }
        if (type.equals(NodeType.TABLE_COLUMN)) {
            TableColumn tc = (TableColumn) cubridNode.getAdapter(TableColumn.class);
            names.append(tc.getColumnName());
        } else {
            names.append(cubridNode.getLabel());
        }
    }
    if (names.length() > 0) {
        TextTransfer textTransfer = TextTransfer.getInstance();
        Clipboard clipboard = CommonUITool.getClipboard();
        clipboard.setContents(new Object[] { names.toString() }, new Transfer[] { textTransfer });
    }
}
Also used : ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Clipboard(org.eclipse.swt.dnd.Clipboard) TableColumn(com.cubrid.cubridmanager.core.cubrid.table.model.TableColumn) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 60 with TextTransfer

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

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