Search in sources :

Example 1 with Transfer

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

the class AbstractElementPropertySectionController method addDragAndDropTarget.

/**
     * Accept Text and StyledText control.
     *
     * @param labelText
     */
public void addDragAndDropTarget(final Control textControl) {
    DropTargetListener dropTargetListener = new DropTargetListener() {

        String propertyName = null;

        @Override
        public void dragEnter(final DropTargetEvent event) {
        }

        @Override
        public void dragLeave(final DropTargetEvent event) {
        }

        @Override
        public void dragOperationChanged(final DropTargetEvent event) {
        }

        @Override
        public void dragOver(final DropTargetEvent event) {
            if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
                propertyName = getParameterName(textControl);
                for (int i = 0; i < elem.getElementParameters().size(); i++) {
                    IElementParameter param = elem.getElementParameters().get(i);
                    if (param.getName().equals(propertyName)) {
                        if (param.isReadOnly()) {
                            event.detail = DND.ERROR_INVALID_DATA;
                        }
                    }
                }
            }
        }

        @Override
        public void drop(final DropTargetEvent event) {
            if (propertyName != null) {
                String text;
                if (textControl instanceof StyledText) {
                    text = ((StyledText) textControl).getText() + (String) event.data;
                    ((StyledText) textControl).setText(text);
                } else {
                    text = ((Text) textControl).getText() + (String) event.data;
                    ((Text) textControl).setText(text);
                }
                Command cmd = new PropertyChangeCommand(elem, propertyName, text);
                // getCommandStack().execute(cmd);
                executeCommand(cmd);
            }
        }

        @Override
        public void dropAccept(final DropTargetEvent event) {
        }
    };
    DropTarget target = new DropTarget(textControl, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
    Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
    target.setTransfer(transfers);
    target.addDropListener(dropTargetListener);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ReconcilerStyledText(org.talend.designer.core.ui.viewer.ReconcilerStyledText) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Command(org.eclipse.gef.commands.Command) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) IElementParameter(org.talend.core.model.process.IElementParameter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) ReconcilerStyledText(org.talend.designer.core.ui.viewer.ReconcilerStyledText) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 2 with Transfer

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

the class CopyAction method run.

/*
     * @see Action#run()
     */
@Override
public void run() {
    if (textData == null || textData.length() == 0) {
        return;
    }
    Clipboard clipboard = new Clipboard(Display.getDefault());
    if (filesData.size() > 0) {
        Object[] clipboardData = new Object[] { filesData.toArray(new String[0]), textData };
        Transfer[] clipboardDataTypes = new Transfer[] { FileTransfer.getInstance(), TextTransfer.getInstance() };
        clipboard.setContents(clipboardData, clipboardDataTypes);
    } else {
        clipboard.setContents(new Object[] { textData }, new Transfer[] { TextTransfer.getInstance() });
    }
}
Also used : Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 3 with Transfer

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

the class CubridNavigatorView method addDragDropSupport.

/**
	 * Add the drag drop support of tree.
	 *
	 * @param tree the tree need to drag and drop.
	 */
protected void addDragDropSupport(final Tree tree) {
    // Define 'Transfer Type', 'Operation'
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    int operations = DND.DROP_MOVE | DND.DROP_COPY;
    // DragSource
    final DragSource source = new DragSource(tree, operations);
    source.setTransfer(types);
    source.addDragListener(new DragSourceListener() {

        public void dragStart(DragSourceEvent event) {
            event.doit = false;
            if (!dataSupportDND(tree.getSelection())) {
                return;
            }
            event.doit = true;
        }

        public void dragSetData(DragSourceEvent event) {
            event.data = ((ICubridNode) tree.getSelection()[0].getData()).getLabel();
        }

        public void dragFinished(DragSourceEvent event) {
        }
    });
    addTreeDropTarget(tree);
    String perspectiveId = PerspectiveManager.getInstance().getCurrentPerspectiveId();
    // DropTarget for query editor.
    QueryEditorDNDController.registerDragSource(perspectiveId, tv);
    // DropTarget for multiple query
    MultiDBQueryDNDController.registerDragSource(perspectiveId, tv);
    // DropTarget for Run SQL file
    RunSQLFileDialogDNDController.registerDragSource(perspectiveId, tv);
    //DropTarget for ERD
    ERDNDController.registerDragSource(perspectiveId, tv);
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) DragSource(org.eclipse.swt.dnd.DragSource) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) Point(org.eclipse.swt.graphics.Point)

Example 4 with Transfer

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

the class ParamDumpResultDialog method createDialogArea.

/**
	 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 * @param parent The parent composite to contain the dialog area
	 * @return the dialog area control
	 */
protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(parentComp, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    layout.numColumns = 5;
    composite.setLayout(layout);
    //dynamicHelp end		
    createdbNameGroup(composite);
    table = new Table(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    table.setHeaderVisible(true);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.horizontalSpan = 7;
    gridData.verticalSpan = 10;
    gridData.heightHint = 300;
    table.setLayoutData(gridData);
    table.setLinesVisible(true);
    CommonUITool.hackForYosemite(table);
    /*
		 * // fill in context menu
		 */
    Menu menu = new Menu(parent.getShell(), SWT.POP_UP);
    table.setMenu(menu);
    MenuItem copy = new MenuItem(menu, SWT.PUSH);
    copy.setText(Messages.bind(com.cubrid.cubridmanager.ui.logs.Messages.contextCopy, "Ctrl+C"));
    copy.setAccelerator(SWT.CTRL + 'C');
    copy.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            TextTransfer textTransfer = TextTransfer.getInstance();
            Clipboard clipboard = CommonUITool.getClipboard();
            StringBuilder content = new StringBuilder();
            TableItem[] items = table.getSelection();
            for (int i = 0; i < items.length; i++) {
                content.append(items[i].getText(0) + blank + items[i].getText(1) + blank + items[i].getText(2) + blank + System.getProperty("line.separator"));
            }
            String data = content.toString();
            if (data != null && !data.equals("")) {
                clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
            }
        }
    });
    table.addKeyListener(new org.eclipse.swt.events.KeyAdapter() {

        public void keyPressed(org.eclipse.swt.events.KeyEvent event) {
            if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0 && event.keyCode == 'c') {
                TextTransfer textTransfer = TextTransfer.getInstance();
                Clipboard clipboard = CommonUITool.getClipboard();
                StringBuilder content = new StringBuilder();
                TableItem[] items = table.getSelection();
                for (int i = 0; i < items.length; i++) {
                    content.append(items[i].getText(0) + blank + items[i].getText(1) + blank + items[i].getText(2) + blank + System.getProperty("line.separator"));
                }
                String data = content.toString();
                if (data != null && !data.equals("")) {
                    clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
                }
            }
        }
    });
    setTitle(Messages.titleParamDumpDialog);
    setMessage(Messages.msgParamDumpDialog);
    initial();
    return parentComp;
}
Also used : Table(org.eclipse.swt.widgets.Table) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) MenuItem(org.eclipse.swt.widgets.MenuItem) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Event(org.eclipse.swt.widgets.Event) Menu(org.eclipse.swt.widgets.Menu) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 5 with Transfer

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

the class ColumnViewerSorter method copyNamesToClipboard.

public void copyNamesToClipboard(List<String> nameList) {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final Clipboard cb = new Clipboard(shell.getDisplay());
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < nameList.size(); i++) {
        if (i != 0) {
            sb.append(StringUtil.NEWLINE);
        }
        sb.append(nameList.get(i));
    }
    TextTransfer textTransfer = TextTransfer.getInstance();
    Transfer[] transfers = new Transfer[] { textTransfer };
    Object[] data = new Object[] { sb.toString() };
    cb.setContents(data, transfers);
    cb.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

Transfer (org.eclipse.swt.dnd.Transfer)145 TextTransfer (org.eclipse.swt.dnd.TextTransfer)66 Point (org.eclipse.swt.graphics.Point)61 Clipboard (org.eclipse.swt.dnd.Clipboard)46 Menu (org.eclipse.swt.widgets.Menu)36 IMenuManager (org.eclipse.jface.action.IMenuManager)32 MenuManager (org.eclipse.jface.action.MenuManager)32 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)32 Separator (org.eclipse.jface.action.Separator)31 EditingDomainViewerDropAdapter (org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter)30 LocalTransfer (org.eclipse.emf.edit.ui.dnd.LocalTransfer)30 ViewerDragAdapter (org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter)30 UnwrappingSelectionProvider (org.eclipse.emf.edit.ui.provider.UnwrappingSelectionProvider)30 FileTransfer (org.eclipse.swt.dnd.FileTransfer)30 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)27 DropTarget (org.eclipse.swt.dnd.DropTarget)23 GridData (org.eclipse.swt.layout.GridData)22 GridLayout (org.eclipse.swt.layout.GridLayout)21 Composite (org.eclipse.swt.widgets.Composite)21 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)20