Search in sources :

Example 1 with TransferData

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

the class BusinessDiagramDropTargetListener method getObjectsBeingDropped.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gmf.runtime.diagram.ui.parts.DiagramDropTargetListener#getObjectsBeingDropped()
     */
@Override
protected List getObjectsBeingDropped() {
    TransferData[] data = getCurrentEvent().dataTypes;
    List eObjects = new ArrayList();
    ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        eObjects.addAll(structuredSelection.toList());
    }
    return eObjects;
}
Also used : TransferData(org.eclipse.swt.dnd.TransferData) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) List(java.util.List) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with TransferData

use of org.eclipse.swt.dnd.TransferData in project translationstudio8 by heartsome.

the class ResourceDropAdapterAssistant method handleDrop.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(CommonDropAdapter,
	 *      DropTargetEvent, Object)
	 */
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) {
    if (Policy.DEBUG_DND) {
        System.out.println(//$NON-NLS-1$
        "ResourceDropAdapterAssistant.handleDrop (begin)");
    }
    // alwaysOverwrite = false;
    if (aTarget == 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 (FileTransfer.getInstance().isSupportedType(currentTransfer)) {
        status = performFileDrop(aDropAdapter, aDropTargetEvent.data);
    } else if (resources != null && resources.length > 0) {
        if ((aDropAdapter.getCurrentOperation() == DND.DROP_COPY) || (aDropAdapter.getCurrentOperation() == DND.DROP_LINK)) {
            if (Policy.DEBUG_DND) {
                System.out.println(//$NON-NLS-1$
                "ResourceDropAdapterAssistant.handleDrop executing COPY.");
            }
            status = performResourceCopy(aDropAdapter, getShell(), resources);
        } else {
            if (Policy.DEBUG_DND) {
                System.out.println(//$NON-NLS-1$
                "ResourceDropAdapterAssistant.handleDrop executing MOVE.");
            }
            status = performResourceMove(aDropAdapter, resources);
        }
    }
    openError(status);
    IContainer target = getActualTarget((IResource) aTarget);
    if (target != null && target.isAccessible()) {
        try {
            target.refreshLocal(IResource.DEPTH_ONE, null);
        } catch (CoreException e) {
        }
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) TransferData(org.eclipse.swt.dnd.TransferData) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 3 with TransferData

use of org.eclipse.swt.dnd.TransferData in project translationstudio8 by heartsome.

the class PasteAction method updateSelection.

/**
     * The <code>PasteAction</code> implementation of this
     * <code>SelectionListenerAction</code> method enables this action if 
     * a resource compatible with what is on the clipboard is selected.
     * 
     * -Clipboard must have IResource or java.io.File
     * -Projects can always be pasted if they are open
     * -Workspace folder may not be copied into itself
     * -Files and folders may be pasted to a single selected folder in open 
     * 	project or multiple selected files in the same folder 
     */
protected boolean updateSelection(IStructuredSelection selection) {
    if (!super.updateSelection(selection)) {
        return false;
    }
    final IResource[][] clipboardData = new IResource[1][];
    shell.getDisplay().syncExec(new Runnable() {

        public void run() {
            // clipboard must have resources or files
            ResourceTransfer resTransfer = ResourceTransfer.getInstance();
            clipboardData[0] = (IResource[]) clipboard.getContents(resTransfer);
        }
    });
    IResource[] resourceData = clipboardData[0];
    boolean isProjectRes = resourceData != null && resourceData.length > 0 && resourceData[0].getType() == IResource.PROJECT;
    if (isProjectRes) {
        for (int i = 0; i < resourceData.length; i++) {
            // can paste open projects regardless of selection
            if (resourceData[i].getType() != IResource.PROJECT || ((IProject) resourceData[i]).isOpen() == false) {
                return false;
            }
        }
        return true;
    }
    if (getSelectedNonResources().size() > 0) {
        return false;
    }
    IResource targetResource = getTarget();
    // or selection is empty	
    if (targetResource == null) {
        return false;
    }
    // can paste files and folders to a single selection (file, folder, 
    // open project) or multiple file selection with the same parent
    List selectedResources = getSelectedResources();
    if (selectedResources.size() > 1) {
        for (int i = 0; i < selectedResources.size(); i++) {
            IResource resource = (IResource) selectedResources.get(i);
            if (resource.getType() != IResource.FILE) {
                return false;
            }
            if (!targetResource.equals(resource.getParent())) {
                return false;
            }
        }
    }
    if (resourceData != null) {
        // linked resources can only be pasted into projects
        if (isLinked(resourceData) && targetResource.getType() != IResource.PROJECT && targetResource.getType() != IResource.FOLDER) {
            return false;
        }
        if (targetResource.getType() == IResource.FOLDER) {
            // don't try to copy folder to self
            for (int i = 0; i < resourceData.length; i++) {
                if (targetResource.equals(resourceData[i])) {
                    return false;
                }
            }
        }
        return true;
    }
    TransferData[] transfers = clipboard.getAvailableTypes();
    FileTransfer fileTransfer = FileTransfer.getInstance();
    for (int i = 0; i < transfers.length; i++) {
        if (fileTransfer.isSupportedType(transfers[i])) {
            return true;
        }
    }
    return false;
}
Also used : ResourceTransfer(org.eclipse.ui.part.ResourceTransfer) TransferData(org.eclipse.swt.dnd.TransferData) FileTransfer(org.eclipse.swt.dnd.FileTransfer) List(java.util.List) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 4 with TransferData

use of org.eclipse.swt.dnd.TransferData in project liferay-ide by liferay.

the class WorkflowDropAdapterAssistant method handleDrop.

@Override
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) {
    if (aTarget instanceof WorkflowDefinitionsFolder) {
        WorkflowDefinitionsFolder folder = (WorkflowDefinitionsFolder) aTarget;
        IKaleoConnection kaleoConnection = KaleoCore.getKaleoConnection(folder.getParent());
        TransferData transferData = aDropTargetEvent.currentDataType;
        if (LocalSelectionTransfer.getTransfer().isSupportedType(transferData)) {
            Object dropData = LocalSelectionTransfer.getTransfer().getSelection();
            if (dropData instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) dropData;
                Object element = selection.getFirstElement();
                if (element instanceof IFile) {
                    IFile file = (IFile) element;
                    Runnable runnable = new Runnable() {

                        public void run() {
                            folder.clearCache();
                            Runnable runnable = new Runnable() {

                                public void run() {
                                    IViewPart serversView = UIUtil.showView("org.eclipse.wst.server.ui.ServersView");
                                    CommonViewer viewer = (CommonViewer) serversView.getAdapter(CommonViewer.class);
                                    viewer.refresh(true);
                                }
                            };
                            Display.getDefault().asyncExec(runnable);
                        }
                    };
                    new UploadWorkflowFileJob(kaleoConnection, file, runnable).schedule();
                }
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IKaleoConnection(com.liferay.ide.kaleo.core.IKaleoConnection) IFile(org.eclipse.core.resources.IFile) TransferData(org.eclipse.swt.dnd.TransferData) CommonViewer(org.eclipse.ui.navigator.CommonViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UploadWorkflowFileJob(com.liferay.ide.kaleo.ui.util.UploadWorkflowFileJob)

Example 5 with TransferData

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

the class RepositoryNodeDorpAdapterAssistant method handleDrop.

@Override
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) {
    IRepositoryNode targetNode = (IRepositoryNode) aTarget;
    if (aDropAdapter.getCurrentTarget() == null || aDropTargetEvent.data == null) {
        return Status.CANCEL_STATUS;
    }
    TransferData currentTransfer = aDropAdapter.getCurrentTransfer();
    if (LocalSelectionTransfer.getTransfer().isSupportedType(currentTransfer)) {
        // Call repository node CRULD handler to handle drop action.
        boolean isHandledOK = repositoryObjectCRUD.handleDrop(targetNode);
        if (isHandledOK) {
            return Status.OK_STATUS;
        } else {
            return Status.CANCEL_STATUS;
        }
    } else {
        return Status.CANCEL_STATUS;
    }
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) TransferData(org.eclipse.swt.dnd.TransferData)

Aggregations

TransferData (org.eclipse.swt.dnd.TransferData)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 ViewerDropAdapter (org.eclipse.jface.viewers.ViewerDropAdapter)6 List (java.util.List)5 IFile (org.eclipse.core.resources.IFile)5 IResource (org.eclipse.core.resources.IResource)5 ArrayList (java.util.ArrayList)4 ISelection (org.eclipse.jface.viewers.ISelection)4 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)4 Transfer (org.eclipse.swt.dnd.Transfer)4 CoreException (org.eclipse.core.runtime.CoreException)3 IStatus (org.eclipse.core.runtime.IStatus)3 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 TreeSelection (org.eclipse.jface.viewers.TreeSelection)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 RepositoryBundle (bndtools.model.repo.RepositoryBundle)2