Search in sources :

Example 11 with TransferData

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

the class ResourceDropAdapterAssistant method handleDrop.

/*
     * (non-Javadoc)
     *
     * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop (org.eclipse.ui.navigator.CommonDropAdapter,
     * org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object)
     */
@Override
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object target) {
    // alwaysOverwrite = false;
    if (aDropAdapter.getCurrentTarget() == null || aDropTargetEvent.data == null) {
        return Status.CANCEL_STATUS;
    }
    // IStatus status = null;
    IResource[] resources = null;
    TransferData currentTransfer = aDropAdapter.getCurrentTransfer();
    if (LocalSelectionTransfer.getTransfer().isSupportedType(currentTransfer)) {
        resources = getSelectedResources();
    } else if (ResourceTransfer.getInstance().isSupportedType(currentTransfer)) {
        resources = (IResource[]) aDropTargetEvent.data;
    }
    if ((target instanceof IFile)) {
        // && dropRep
        TdReport findReport = RepResourceFileHelper.getInstance().findReport(((IFile) target));
        List<Analysis> analyses = ReportHelper.getAnalyses(findReport);
        Map<String, Analysis> resourcesMap = new HashMap<String, Analysis>();
        for (Analysis ana : analyses) {
            String uriString = ana.eResource().getURI().toString();
            resourcesMap.put(uriString, ana);
        }
        if (resources != null && resources.length > 0) {
            List<Analysis> anaList = new ArrayList<Analysis>();
            for (IResource res : resources) {
                Analysis findAnalysis = AnaResourceFileHelper.getInstance().findAnalysis((IFile) res);
                if (findAnalysis != null) {
                    String uriKey = findAnalysis.eResource().getURI().toString();
                    if (resourcesMap.containsKey(uriKey)) {
                        findReport.removeAnalysis(resourcesMap.get(uriKey));
                    }
                    anaList.add(findAnalysis);
                }
            }
            // ReportHelper.addAnalyses(anaList, findReport);
            RepResourceFileHelper.getInstance().save(findReport);
        }
    } else if (resources != null && (target instanceof IFolder)) {
        // && dropSql
        IFolder folder = (IFolder) target;
        // IPath location = folder.getFullPath();
        for (IResource res : resources) {
            if (res.getType() != IResource.FILE) {
                return null;
            }
            if (folder.equals(res.getParent())) {
                continue;
            }
            String name = res.getName();
            IFile fileRes = (IFile) res;
            IFile movedIFile = folder.getFile(name);
            if (!FactoriesUtil.isEmfFile(fileRes.getFileExtension())) {
                try {
                    fileRes.move(movedIFile.getFullPath(), false, null);
                    fileRes.getParent().refreshLocal(IResource.DEPTH_INFINITE, null);
                    folder.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (CoreException e) {
                    ExceptionHandler.process(e);
                }
                return Status.OK_STATUS;
            }
            IContainer srcParent = fileRes.getParent();
            URI srcUri = URI.createPlatformResourceURI((fileRes).getFullPath().toString(), false);
            Resource resource = EMFSharedResources.getInstance().getResource(srcUri, true);
            if (resource != null) {
                URI desUri = URI.createPlatformResourceURI(folder.getFullPath().toString(), false);
                EMFSharedResources.getInstance().saveToUri(resource, desUri);
                // ADD xqliu 2010-09-21 bug 15685
                IFile propertyFile = PropertyHelper.getPropertyFile(fileRes);
                if (propertyFile != null) {
                    IFile movedPropertyFile = folder.getFile(propertyFile.getName());
                    try {
                        propertyFile.move(movedPropertyFile.getFullPath(), true, null);
                    } catch (CoreException e) {
                        ExceptionHandler.process(e);
                    }
                }
            // ~ 15685
            }
            try {
                closeEditorIfOpened(fileRes);
                fileRes.delete(true, null);
                srcParent.refreshLocal(IResource.DEPTH_INFINITE, null);
                folder.refreshLocal(IResource.DEPTH_INFINITE, null);
                // ADD xqliu 2010-09-25 bug 15685 update the path of ItemState
                Property property = PropertyHelper.getProperty(PropertyHelper.getPropertyFile(movedIFile));
                property.getItem().getState().setPath(PropertyHelper.computePath(property));
            // ~ 15685
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
            movedIFile = folder.getFile(name);
        }
    }
    ProxyRepositoryManager.getInstance().save();
    CorePlugin.getDefault().refreshDQView();
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) TdReport(org.talend.dataquality.reports.TdReport) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) CoreException(org.eclipse.core.runtime.CoreException) TransferData(org.eclipse.swt.dnd.TransferData) Analysis(org.talend.dataquality.analysis.Analysis) IContainer(org.eclipse.core.resources.IContainer) Property(org.talend.core.model.properties.Property) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with TransferData

use of org.eclipse.swt.dnd.TransferData in project knime-workbench by knime.

the class ExplorerDropListener method srcCanMove.

private boolean srcCanMove(final DropTargetEvent event) {
    if (m_canMove == null) {
        if (event.item != null) {
            TransferData transferType = event.currentDataType;
            LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
            boolean isLocalTransfer = transfer.isSupportedType(transferType);
            if (isLocalTransfer || FileTransfer.getInstance().isSupportedType(transferType) || WorkflowManagerTransfer.getTransfer().isSupportedType(transferType)) {
                ISelection selection = transfer.getSelection();
                if (selection instanceof IStructuredSelection) {
                    IStructuredSelection ss = (IStructuredSelection) selection;
                    List<AbstractExplorerFileStore> srcFS = DragAndDropUtils.getExplorerFileStores(ss);
                    if (srcFS != null && srcFS.size() == 1) {
                        m_canMove = srcFS.get(0).canMove();
                    }
                }
            }
        }
        if (m_canMove == null) {
            // default answer is yes
            m_canMove = Boolean.TRUE;
        }
    }
    return m_canMove.booleanValue();
}
Also used : TransferData(org.eclipse.swt.dnd.TransferData) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer)

Example 13 with TransferData

use of org.eclipse.swt.dnd.TransferData in project jbosstools-base by jbosstools.

the class DropContext method setDropTargetEvent.

public void setDropTargetEvent(TypedEvent event) {
    this.event = event;
    TransferData[] ds = null;
    if (this.event instanceof DropTargetEvent) {
        ds = ((DropTargetEvent) event).dataTypes;
    } else if (this.event instanceof VpeDnDEvent) {
        ds = ((VpeDnDEvent) this.event).getDataTypes();
    }
    if (ds != null) {
        for (int i = 0; i < TRANSFERS.length; i++) {
            TransferData data = TRANSFERS[i].getSupportedData(ds);
            if (data != null) {
                TRANSFERS[i].process(data);
                break;
            }
        }
    }
}
Also used : VpeDnDEvent(org.jboss.tools.common.model.ui.dnd.VpeDnDEvent) TransferData(org.eclipse.swt.dnd.TransferData) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent)

Example 14 with TransferData

use of org.eclipse.swt.dnd.TransferData in project bndtools by bndtools.

the class JarListWizardPage method createControl.

@Override
public void createControl(final Composite parent) {
    setTitle("Select JARs");
    final Composite composite = new Composite(parent, SWT.NONE);
    Label lblHint = new Label(composite, SWT.WRAP);
    lblHint.setText("Selected files (hint: drag files from an external application into this list):");
    final Table table = new Table(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ClassPathLabelProvider());
    btnAdd = new Button(composite, SWT.PUSH);
    btnAdd.setText("Add");
    btnAddExternal = new Button(composite, SWT.PUSH);
    btnAddExternal.setText("Add External");
    btnRemove = new Button(composite, SWT.PUSH);
    btnRemove.setText("Remove");
    viewer.setInput(paths);
    update();
    // Listeners
    ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {

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

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            return true;
        }

        @Override
        public boolean performDrop(Object data) {
            if (data instanceof String[]) {
                String[] newPaths = (String[]) data;
                List<IPath> added = new ArrayList<IPath>(newPaths.length);
                for (String path : newPaths) {
                    added.add(new Path(path));
                }
                if (!added.isEmpty()) {
                    addToPaths(added);
                    viewer.add(added.toArray());
                    update();
                }
            }
            return true;
        }
    };
    dropAdapter.setFeedbackEnabled(false);
    dropAdapter.setSelectionFeedbackEnabled(false);
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { FileTransfer.getInstance() }, dropAdapter);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            update();
        }
    });
    btnAdd.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // IResource newFile = ResourcesPlugin.getWorkspace().getRoot();
            // if(newFile != null) {
            ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
            dialog.setValidator(new ISelectionStatusValidator() {

                @Override
                public IStatus validate(Object[] selection) {
                    if (selection.length > 0 && selection[0] instanceof IFile) {
                        // $NON-NLS-1$
                        return new Status(IStatus.OK, Plugin.PLUGIN_ID, IStatus.OK, "", null);
                    }
                    // $NON-NLS-1$
                    return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, IStatus.ERROR, "", null);
                }
            });
            dialog.setAllowMultiple(true);
            dialog.setTitle("JAR File Selection");
            dialog.setMessage("Select one or more JAR files.");
            // $NON-NLS-1$
            dialog.addFilter(new FileExtensionFilter("jar"));
            dialog.setInput(ResourcesPlugin.getWorkspace());
            if (dialog.open() == Window.OK) {
                Object[] files = dialog.getResult();
                List<IPath> added = new ArrayList<IPath>(files.length);
                for (Object file : files) {
                    added.add(((IResource) file).getFullPath().makeRelative());
                }
                if (!added.isEmpty()) {
                    addToPaths(added);
                    viewer.add(added.toArray());
                }
            }
            // }
            update();
        }
    });
    btnAddExternal.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.MULTI);
            dialog.setFilterExtensions(new String[] { // $NON-NLS-1$
            "*.jar" });
            String res = dialog.open();
            if (res != null) {
                IPath filterPath = new Path(dialog.getFilterPath());
                String[] fileNames = dialog.getFileNames();
                List<IPath> added = new ArrayList<IPath>(fileNames.length);
                for (String fileName : fileNames) {
                    added.add(filterPath.append(fileName));
                }
                if (!added.isEmpty()) {
                    addToPaths(added);
                    viewer.add(added.toArray());
                }
            }
            update();
        }
    });
    btnRemove.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            removeFromPaths(((IStructuredSelection) viewer.getSelection()).toList());
            viewer.remove(((IStructuredSelection) viewer.getSelection()).toArray());
            update();
        }
    });
    // Layout
    composite.setLayout(new GridLayout(2, false));
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
    btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    btnAddExternal.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    lblHint.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));
    setControl(composite);
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ClassPathLabelProvider(bndtools.utils.ClassPathLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) TransferData(org.eclipse.swt.dnd.TransferData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileExtensionFilter(bndtools.utils.FileExtensionFilter) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 15 with TransferData

use of org.eclipse.swt.dnd.TransferData in project webtools.sourceediting by eclipse.

the class ExtendedEditorDropTargetAdapter method dragEnter.

/**
 */
public void dragEnter(DropTargetEvent event) {
    TransferData data = null;
    Transfer[] ts = getTransfers();
    for (int i = 0; i < ts.length; i++) {
        for (int j = 0; j < event.dataTypes.length; j++) {
            if (ts[i].isSupportedType(event.dataTypes[j])) {
                data = event.dataTypes[j];
                break;
            }
        }
        if (data != null) {
            event.currentDataType = data;
            break;
        }
    }
    if (textViewer != null) {
        originalRange = textViewer.getSelectedRange();
    }
}
Also used : TransferData(org.eclipse.swt.dnd.TransferData) FileTransfer(org.eclipse.swt.dnd.FileTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Point(org.eclipse.swt.graphics.Point)

Aggregations

TransferData (org.eclipse.swt.dnd.TransferData)30 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 ViewerDropAdapter (org.eclipse.jface.viewers.ViewerDropAdapter)12 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)11 Transfer (org.eclipse.swt.dnd.Transfer)10 List (java.util.List)9 ArrayList (java.util.ArrayList)7 IResource (org.eclipse.core.resources.IResource)7 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)7 IFile (org.eclipse.core.resources.IFile)5 ISelection (org.eclipse.jface.viewers.ISelection)5 CoreException (org.eclipse.core.runtime.CoreException)4 IStatus (org.eclipse.core.runtime.IStatus)4 TreeSelection (org.eclipse.jface.viewers.TreeSelection)4 AbstractObject (org.netxms.client.objects.AbstractObject)4 URI (java.net.URI)3 IContainer (org.eclipse.core.resources.IContainer)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 Point (org.eclipse.swt.graphics.Point)3