Search in sources :

Example 36 with Transfer

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

the class ColumnViewerDND method installDND.

/**
 * DOC qzhang Comment method "installDND".
 */
public static void installDND(final Tree targetControl) {
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
    final CommonViewer commonViewer = findView.getCommonViewer();
    final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
    int operations = DND.DROP_COPY | DND.DROP_MOVE;
    Transfer[] transfers = new Transfer[] { transfer };
    DropTarget dropTarget = new DropTarget(targetControl, operations);
    dropTarget.setTransfer(transfers);
    DropTargetListener dndListener = new TreeDropTargetEffect(targetControl) {

        ISelectionReceiver receiver = null;

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.dnd.DropTargetAdapter#dragEnter(org.eclipse.swt .dnd.DropTargetEvent)
             */
        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
            Object object = selection.getFirstElement();
            // if (object instanceof IFile) {
            if (object instanceof SysIndicatorDefinitionRepNode) {
                receiver = new UDIReceiver();
            } else if (object instanceof PatternRepNode) {
                receiver = new PatternReceiver();
            }
            // MOD klliu 15750 2011-01-17 for Drag&Drop On columnset
            if (object instanceof DBColumnRepNode || object instanceof DBTableRepNode || object instanceof DFColumnRepNode) {
                receiver = new ColumnReceiver();
            }
            if (receiver == null) {
                event.detail = DND.DROP_NONE;
            } else {
                event.feedback = DND.FEEDBACK_EXPAND;
                receiver.doDropValidation(event, commonViewer);
            }
        }

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.dnd.TreeDropTargetEffect#dragOver(org.eclipse .swt.dnd.DropTargetEvent)
             */
        @Override
        public void dragOver(DropTargetEvent event) {
            super.dragOver(event);
            // MOD yyi 2009-09-18 bug: 9044
            if (null != receiver) {
                receiver.doDropValidation(event, commonViewer);
            }
        }

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.dnd.DropTargetAdapter#drop(org.eclipse.swt.dnd .DropTargetEvent)
             */
        @Override
        public void drop(DropTargetEvent event) {
            int index = targetControl.getItemCount();
            super.drop(event);
            if (event.item == null) {
                // TreeItem item = new TreeItem(targetControl, SWT.NONE);
                // item.setText(texts);
                // item.setText(text);
                index = 0;
            } else {
                TreeItem item = (TreeItem) event.item;
                TreeItem[] items = targetControl.getItems();
                for (int i = 0; i < items.length; i++) {
                    if (items[i] == item) {
                        index = i;
                        break;
                    }
                }
            }
            receiver.drop(event, commonViewer, index);
        }
    };
    dropTarget.addDropListener(dndListener);
}
Also used : CommonViewer(org.eclipse.ui.navigator.CommonViewer) TreeItem(org.eclipse.swt.widgets.TreeItem) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) TreeDropTargetEffect(org.eclipse.swt.dnd.TreeDropTargetEffect) DFColumnRepNode(org.talend.dq.nodes.DFColumnRepNode) DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) SysIndicatorDefinitionRepNode(org.talend.dq.nodes.SysIndicatorDefinitionRepNode) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DropTarget(org.eclipse.swt.dnd.DropTarget) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) PatternRepNode(org.talend.dq.nodes.PatternRepNode)

Example 37 with Transfer

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

the class DataFilterDND method installDND.

public static void installDND(final Text targetControl) {
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
    final CommonViewer commonViewer = findView.getCommonViewer();
    final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
    int operations = DND.DROP_COPY | DND.DROP_MOVE;
    Transfer[] transfers = new Transfer[] { transfer };
    DropTarget dropTarget = new DropTarget(targetControl, operations);
    dropTarget.setTransfer(transfers);
    dropTarget.addDropListener(new DropTargetAdapter() {

        @Override
        public void dragEnter(DropTargetEvent event) {
            Object obj = ((IStructuredSelection) commonViewer.getSelection()).getFirstElement();
            if (!(obj instanceof DBColumnRepNode)) {
                event.detail = DND.DROP_NONE;
            } else {
                event.detail = DND.DROP_MOVE;
                event.feedback = DND.FEEDBACK_INSERT_AFTER;
            }
        }

        @Override
        public void dropAccept(DropTargetEvent event) {
        // do nothing until now
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (event.detail != DND.DROP_NONE) {
                IStructuredSelection selection = (IStructuredSelection) commonViewer.getSelection();
                if (!selection.isEmpty()) {
                    List list = selection.toList();
                    IEditorPart currentActiveEditor = CorePlugin.getDefault().getCurrentActiveEditor();
                    if (currentActiveEditor instanceof AnalysisEditor) {
                        AnalysisEditor editor = (AnalysisEditor) currentActiveEditor;
                        AnalysisItemEditorInput input = (AnalysisItemEditorInput) editor.getEditorInput();
                        for (Object object : list) {
                            DBColumnRepNode node = (DBColumnRepNode) object;
                            DbmsLanguage language = DbmsLanguageFactory.createDbmsLanguage((Analysis) input.getModel());
                            MetadataColumnRepositoryObject columnObject = (MetadataColumnRepositoryObject) node.getObject();
                            String name = columnObject.getTdColumn().getName();
                            targetControl.insert(language.quote(name));
                            // Focus text.
                            targetControl.forceFocus();
                        }
                    }
                }
            }
        }
    });
}
Also used : CommonViewer(org.eclipse.ui.navigator.CommonViewer) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) Analysis(org.talend.dataquality.analysis.Analysis) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) List(java.util.List) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) DropTarget(org.eclipse.swt.dnd.DropTarget) AnalysisItemEditorInput(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer)

Example 38 with Transfer

use of org.eclipse.swt.dnd.Transfer in project statecharts by Yakindu.

the class ExampleDropTargetInstaller method registerWithExistingTarget.

protected void registerWithExistingTarget(DropTarget target) {
    Transfer[] transfers = target.getTransfer();
    boolean exists = false;
    if (transfers != null) {
        for (Transfer transfer : transfers) {
            if (transfer instanceof URLTransfer) {
                exists = true;
                break;
            }
        }
        if (!exists) {
            Transfer[] newTransfers = new Transfer[transfers.length + 1];
            System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
            newTransfers[transfers.length] = URLTransfer.getInstance();
            target.setTransfer(newTransfers);
        }
    }
}
Also used : URLTransfer(org.eclipse.swt.dnd.URLTransfer) URLTransfer(org.eclipse.swt.dnd.URLTransfer) Transfer(org.eclipse.swt.dnd.Transfer)

Example 39 with Transfer

use of org.eclipse.swt.dnd.Transfer in project ecf by eclipse.

the class EndpointDiscoveryView method makeActions.

protected void makeActions() {
    copyValueAction = new Action() {

        public void run() {
            Object o = ((ITreeSelection) viewer.getSelection()).getFirstElement();
            String data = ((EndpointPropertyNode) o).getPropertyValue().toString();
            if (data != null && data.length() > 0) {
                clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() });
            }
        }
    };
    copyValueAction.setText(Messages.EndpointDiscoveryView_COPY_PROPERTY_VALUE);
    copyValueAction.setToolTipText(Messages.EndpointDiscoveryView_COPY_PROPERTY_VALUE);
    copyValueAction.setImageDescriptor(RSAImageRegistry.DESC_PROPERTY_OBJ);
    copyNameAction = new Action() {

        public void run() {
            Object o = ((ITreeSelection) viewer.getSelection()).getFirstElement();
            String data = ((EndpointPropertyNode) o).getPropertyName();
            if (data != null && data.length() > 0) {
                clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() });
            }
        }
    };
    copyNameAction.setText(Messages.EndpointDiscoveryView_COPY_PROPERTY_NAME);
    copyNameAction.setToolTipText(Messages.EndpointDiscoveryView_COPY_PROPERTY_NAME);
    copyNameAction.setImageDescriptor(RSAImageRegistry.DESC_PROPERTY_OBJ);
    importAction = new Action() {

        public void run() {
            EndpointNode edNode = getEDNodeSelected();
            if (edNode != null) {
                RemoteServiceAdmin rsa = discovery.getRSA();
                if (rsa == null)
                    showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IS_NULL);
                else {
                    // Do import
                    EndpointDescription ed = edNode.getEndpointDescription();
                    ImportRegistration reg = (ImportRegistration) rsa.importService(ed);
                    if (reg == null) {
                        logError(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED, // $NON-NLS-1$
                        new Exception("Import Registration Is Null"));
                        showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED_PREFIX + // $NON-NLS-1$
                        "Import Registration Is Null" + Messages.EndpointDiscoveryView_ERROR_MSG_SUFFIX);
                        return;
                    }
                    // Check if import exception in returned registration
                    Throwable exception = reg.getException();
                    if (exception != null) {
                        logError(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED, exception);
                        showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_RSA_IMPORTSERVICE_FAILED_PREFIX + exception.getMessage() + Messages.EndpointDiscoveryView_ERROR_MSG_SUFFIX);
                    } else {
                        // Success! Set registration
                        // and refresh
                        edNode.setImportReference((ImportReference) reg.getImportReference());
                        viewer.refresh();
                    }
                }
            }
        }
    };
    importAction.setText(Messages.EndpointDiscoveryView_IMPORT_REMOTE_SERVICE);
    importAction.setToolTipText(Messages.EndpointDiscoveryView_IMPORT_REMOTE_SERVICE_TT);
    importAction.setImageDescriptor(RSAImageRegistry.DESC_RSPROXY_CO);
    edefDiscoverAction = new Action() {

        public void run() {
            IEndpointDescriptionLocator locator = discovery.getEndpointDescriptionLocator();
            if (locator != null) {
                FileDialog dialog = new FileDialog(viewer.getControl().getShell(), SWT.OPEN);
                // $NON-NLS-1$
                dialog.setFilterExtensions(new String[] { "*.xml" });
                dialog.setText(Messages.EndpointDiscoveryView_OPEN_EDEF_FILE);
                dialog.setFilterPath(null);
                String result = dialog.open();
                if (result != null)
                    try {
                        EndpointDescription[] eds = (EndpointDescription[]) new EndpointDescriptionReader().readEndpointDescriptions(new FileInputStream(result));
                        if (eds != null) {
                            for (int i = 0; i < eds.length; i++) locator.discoverEndpoint(eds[i]);
                        }
                    } catch (IOException e) {
                        logError(Messages.EndpointDiscoveryView_ERROR_MSG_ENDPOINT_PARSING_FAILED, e);
                        showMessage(Messages.EndpointDiscoveryView_ERROR_MSG_ENDPOINT_PARSING_FAILED_PREFIX + e.getMessage() + Messages.EndpointDiscoveryView_ERROR_MSG_SUFFIX);
                    }
            }
        }
    };
    edefDiscoverAction.setText(Messages.EndpointDiscoveryView_OPEN_EDEF_FILE_DIALOG);
    edefDiscoverAction.setToolTipText(Messages.EndpointDiscoveryView_OPEN_EDEF_FILE_DIALOG_TT);
    edefDiscoverAction.setEnabled(discovery.getRSA() != null);
    edefDiscoverAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE));
    undiscoverAction = new Action() {

        public void run() {
            EndpointNode endpoint = getEDNodeSelected();
            if (endpoint != null && endpoint.getImportReference() == null) {
                IEndpointDescriptionLocator l = discovery.getEndpointDescriptionLocator();
                if (l != null && MessageDialog.openQuestion(viewer.getControl().getShell(), Messages.EndpointDiscoveryView_REMOVE_ENDPOINT_QUESTION_TITLE, Messages.EndpointDiscoveryView_REMOVE_ENDPOINT_QUESTION))
                    l.undiscoverEndpoint(endpoint.getEndpointDescription());
            }
        }
    };
    undiscoverAction.setText(Messages.EndpointDiscoveryView_REMOVE_ENDPOINT);
    undiscoverAction.setToolTipText(Messages.EndpointDiscoveryView_REMOVE_ENDPOINT_TT);
}
Also used : EndpointPropertyNode(org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.EndpointPropertyNode) Action(org.eclipse.jface.action.Action) RemoteServiceAdmin(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin) EndpointNode(org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.EndpointNode) AbstractEndpointNode(org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.AbstractEndpointNode) ImportReference(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportReference) EndpointDescriptionReader(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionReader) EndpointDescription(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription) IOException(java.io.IOException) ImportRegistration(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportRegistration) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IEndpointDescriptionLocator(org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionLocator) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 40 with Transfer

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

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