Search in sources :

Example 86 with Transfer

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

the class JobHierarchyViewPart method addDropAdapters.

private void addDropAdapters(AbstractTreeViewer viewer) {
    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getInstance() };
    int ops = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT;
    DelegatingDropAdapter delegatingDropAdapter = new DelegatingDropAdapter();
    delegatingDropAdapter.addDropTargetListener(new JobHierarchyTransferDropAdapter(this));
    viewer.addDropSupport(ops, transfers, delegatingDropAdapter);
}
Also used : DelegatingDropAdapter(org.eclipse.jface.util.DelegatingDropAdapter) Transfer(org.eclipse.swt.dnd.Transfer) LocalSelectionTransfer(org.eclipse.ui.views.navigator.LocalSelectionTransfer) Point(org.eclipse.swt.graphics.Point)

Example 87 with Transfer

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

the class GEFCopyAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    List objects = GEFDeleteAction.filterSameObject(getSelectedObjects());
    if (!objects.isEmpty()) {
        Clipboard clipboard = Clipboard.getDefault();
        org.eclipse.swt.dnd.Clipboard systemClipboard = new org.eclipse.swt.dnd.Clipboard(Display.getCurrent());
        boolean noteTextActived = false;
        boolean connectionTextActived = false;
        boolean nodeLabelActived = false;
        Text text = null;
        if (objects.size() == 1) {
            if (objects.get(0) instanceof NoteEditPart) {
                NoteDirectEditManager directEditManager = ((NoteEditPart) objects.get(0)).getDirectEditManager();
                if (directEditManager != null && directEditManager.getCellEditor() != null) {
                    noteTextActived = true;
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart) {
                ConnLabelEditPart connLabelEditPart = (ConnLabelEditPart) objects.get(0);
                if (connLabelEditPart.getDirectEditManager() != null && connLabelEditPart.getDirectEditManager().getTextControl() != null) {
                    connectionTextActived = true;
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart) {
                NodeLabelEditPart nodeLabelEditPart = (NodeLabelEditPart) objects.get(0);
                if (nodeLabelEditPart.getDirectEditManager() != null && nodeLabelEditPart.getDirectEditManager().getCellEditor() != null) {
                    nodeLabelActived = true;
                }
            }
        }
        if (noteTextActived) {
            text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
            clipboard.setContents(text.getSelectionText());
        } else if (connectionTextActived) {
            text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
            clipboard.setContents(text.getSelectionText());
        } else if (nodeLabelActived) {
            text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
            clipboard.setContents(text.getSelectionText());
        } else {
            clipboard.setContents(objects);
        }
        if (text != null && !("").equals(text.getSelectionText())) {
            TextTransfer textTransfer = TextTransfer.getInstance();
            Transfer[] transfers = new Transfer[] { textTransfer };
            Object[] data = new Object[] { text.getSelectionText() };
            systemClipboard.setContents(data, transfers);
        }
    }
    // Refreshes the pasteAction's enable status.
    IWorkbenchPart part = getWorkbenchPart();
    if (part instanceof AbstractTalendEditor) {
        AbstractTalendEditor talendEditor = (AbstractTalendEditor) part;
        IAction action = talendEditor.getActionRegistry().getAction(ActionFactory.PASTE.getId());
        action.setEnabled(true);
    }
}
Also used : NoteDirectEditManager(org.talend.designer.core.ui.editor.notes.NoteDirectEditManager) IAction(org.eclipse.jface.action.IAction) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) Text(org.eclipse.swt.widgets.Text) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) List(java.util.List) Clipboard(org.eclipse.gef.ui.actions.Clipboard) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 88 with Transfer

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

use of org.eclipse.swt.dnd.Transfer in project knime-core by knime.

the class AbstractRepositoryView method createPartControl.

/**
 * This callback creates the content of the view. The TreeViewer is initialized.
 *
 * @see org.eclipse.ui.IWorkbenchPart #createPartControl(org.eclipse.swt.widgets.Composite)
 * @param parent the parent composite
 */
@Override
public void createPartControl(final Composite parent) {
    parent.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_WAIT));
    m_viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    m_viewer.getControl().setToolTipText("Loading node repository...");
    m_viewer.setContentProvider(new RepositoryContentProvider());
    m_viewer.setLabelProvider(new RepositoryStyledLabelProvider(new RepositoryLabelProvider(), false));
    m_viewer.setInput("Loading node repository...");
    contributeToActionBars();
    hookContextMenu();
    hookDoubleClickAction();
    // The viewer provides the selection to the workbench.
    this.getSite().setSelectionProvider(m_viewer);
    // The viewer supports drag&drop
    // (well, actually only drag - objects are dropped into the editor ;-)
    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    m_viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new NodeTemplateDragListener(m_viewer));
    PlatformUI.getWorkbench().getHelpSystem().setHelp(m_viewer.getControl(), "org.knime.workbench.help.repository_view_context");
    final Job treeUpdater = new KNIMEJob("Node Repository Loader", FrameworkUtil.getBundle(getClass())) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            readRepository(parent, monitor);
            return Status.OK_STATUS;
        }
    };
    treeUpdater.setSystem(true);
    treeUpdater.schedule();
}
Also used : KNIMEJob(org.knime.core.util.KNIMEJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TreeViewer(org.eclipse.jface.viewers.TreeViewer) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Cursor(org.eclipse.swt.graphics.Cursor) KNIMEJob(org.knime.core.util.KNIMEJob) Job(org.eclipse.core.runtime.jobs.Job)

Example 90 with Transfer

use of org.eclipse.swt.dnd.Transfer in project knime-core by knime.

the class FavoritesView method createPartControl.

/**
 * {@inheritDoc}
 */
@Override
public void createPartControl(final Composite parent) {
    m_viewer = new TreeViewer(parent, SWT.SINGLE | SWT.V_SCROLL);
    this.getSite().setSelectionProvider(m_viewer);
    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    m_viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new FavoriteNodesDragSource(this));
    m_viewer.addDropSupport(DND.DROP_COPY, transfers, new FavoriteNodesDropTarget(this));
    m_viewer.setLabelProvider(new RepositoryLabelProvider());
    m_viewer.setContentProvider(new RepositoryContentProvider());
    // no sorting
    m_viewer.setComparator(null);
    m_viewer.setInput("Loading favorite nodes...");
    Job treeUpdater = new KNIMEJob("Favorite Nodes Loader", FrameworkUtil.getBundle(getClass())) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            final Root root = FavoriteNodesManager.getInstance().getRoot();
            final Object category = root.getChildByID(FavoriteNodesManager.FAV_CAT_ID, false);
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            } else {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (!parent.isDisposed()) {
                            m_viewer.setInput(root);
                            m_viewer.expandToLevel(category, 1);
                        }
                    }
                });
            }
            return Status.OK_STATUS;
        }
    };
    treeUpdater.setSystem(true);
    treeUpdater.schedule();
    NodeUsageRegistry.addNodeUsageListener(FavoritesView.this);
    hookDoubleClickAction();
}
Also used : Root(org.knime.workbench.repository.model.Root) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) RepositoryLabelProvider(org.knime.workbench.repository.view.RepositoryLabelProvider) KNIMEJob(org.knime.core.util.KNIMEJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RepositoryContentProvider(org.knime.workbench.repository.view.RepositoryContentProvider) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) KNIMEJob(org.knime.core.util.KNIMEJob) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

Transfer (org.eclipse.swt.dnd.Transfer)151 TextTransfer (org.eclipse.swt.dnd.TextTransfer)71 Point (org.eclipse.swt.graphics.Point)63 Clipboard (org.eclipse.swt.dnd.Clipboard)51 Menu (org.eclipse.swt.widgets.Menu)37 IMenuManager (org.eclipse.jface.action.IMenuManager)32 MenuManager (org.eclipse.jface.action.MenuManager)32 Separator (org.eclipse.jface.action.Separator)32 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)32 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)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 Composite (org.eclipse.swt.widgets.Composite)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)20