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;
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations