org.eclipse.ui.part.ResourceTransfer Java Examples
The following examples show how to use
org.eclipse.ui.part.ResourceTransfer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BonitaStudioWorkbenchWindowAdvisor.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** * Register to selection service to update button enablement * Register the Automatic Perspective switch part listener */ @Override public void postWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); configurer.addEditorAreaTransfer(EditorInputTransfer.getInstance()); configurer.addEditorAreaTransfer(ResourceTransfer.getInstance()); configurer.addEditorAreaTransfer(FileTransfer.getInstance()); configurer.addEditorAreaTransfer(MarkerTransfer.getInstance()); configurer.configureEditorAreaDropListener(new EditorAreaDropAdapter( configurer.getWindow())); final MWindow model = ((WorkbenchPage) window.getActivePage()).getWindowModel(); model.getContext().get(EPartService.class).addPartListener(new AutomaticSwitchPerspectivePartListener()); final Object widget = model.getWidget(); if (widget instanceof Shell) { ((Widget) widget).setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_MAIN_SHELL); } // Replace ObjectActionContributorManager with filtered actions CustomObjectActionContributorManager.getManager(); }
Example #2
Source File: CopyAction.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Set the clipboard contents. Prompt to retry if clipboard is busy. * * @param resources the resources to copy to the clipboard * @param fileNames file names of the resources to copy to the clipboard * @param names string representation of all names */ private void setClipboard(IResource[] resources, String[] fileNames, String names) { try { // set the clipboard contents if (fileNames.length > 0) { clipboard.setContents( new Object[] { resources, fileNames, names }, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() }); } else { clipboard.setContents(new Object[] { resources, names }, new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() }); } } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog.openQuestion(shell, "Problem with copy title", // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title, //$NON-NLS-1$ "Problem with copy.")) { //$NON-NLS-1$ setClipboard(resources, fileNames, names); } } }
Example #3
Source File: CopyAction.java From gama with GNU General Public License v3.0 | 6 votes |
/** * Set the clipboard contents. Prompt to retry if clipboard is busy. * * @param resources * the resources to copy to the clipboard * @param fileNames * file names of the resources to copy to the clipboard * @param names * string representation of all names */ private void setClipboard(final IResource[] resources, final String[] fileNames, final String names) { try { // set the clipboard contents if (fileNames.length > 0) { clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() }); } else { clipboard.setContents(new Object[] { resources, names }, new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() }); } } catch (final SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog.openQuestion(shell, "Problem with copy title", // TODO //$NON-NLS-1$ // ResourceNavigatorMessages.CopyToClipboardProblemDialog_title, "Problem with copy.")) { //$NON-NLS-1$ setClipboard(resources, fileNames, names); } } }
Example #4
Source File: CallHierarchyViewPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void addDragAdapters(StructuredViewer viewer) { int ops= DND.DROP_COPY | DND.DROP_LINK; Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), FileTransfer.getInstance()}; DelegatingDragAdapter dragAdapter= new DelegatingDragAdapter() { @Override public void dragStart(DragSourceEvent event) { IStructuredSelection selection= (IStructuredSelection) fSelectionProviderMediator.getSelection(); if (selection.isEmpty()) { event.doit= false; return; } super.dragStart(event); } }; dragAdapter.addDragSourceListener(new SelectionTransferDragAdapter(fSelectionProviderMediator)); dragAdapter.addDragSourceListener(new EditorInputTransferDragAdapter(fSelectionProviderMediator)); dragAdapter.addDragSourceListener(new ResourceTransferDragAdapter(fSelectionProviderMediator)); dragAdapter.addDragSourceListener(new FileTransferDragAdapter(fSelectionProviderMediator)); viewer.addDragSupport(ops, transfers, dragAdapter); }
Example #5
Source File: JavaSearchResultPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void addDragAdapters(StructuredViewer viewer) { Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance() }; int ops= DND.DROP_COPY | DND.DROP_LINK; JdtViewerDragAdapter dragAdapter= new JdtViewerDragAdapter(viewer); dragAdapter.addDragSourceListener(new SelectionTransferDragAdapter(viewer)); dragAdapter.addDragSourceListener(new EditorInputTransferDragAdapter(viewer)); dragAdapter.addDragSourceListener(new ResourceTransferDragAdapter(viewer)); viewer.addDragSupport(ops, transfers, dragAdapter); }
Example #6
Source File: CopyAction.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * Set the clipboard contents. Prompt to retry if clipboard is busy. * * @param resources the resources to copy to the clipboard * @param fileNames file names of the resources to copy to the clipboard * @param names string representation of all names */ private void setClipboard(IResource[] resources, String[] fileNames, String names) { try { // set the clipboard contents if (fileNames.length > 0) { clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() }); } else { clipboard.setContents(new Object[] { resources, names }, new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() }); } } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog .openQuestion( shell, WorkbenchNavigatorMessages.actions_CopyAction_msgTitle, // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title, //$NON-NLS-1$ WorkbenchNavigatorMessages.actions_CopyAction_msg)) { //$NON-NLS-1$ setClipboard(resources, fileNames, names); } } }
Example #7
Source File: CopyAction.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Set the clipboard contents. Prompt to retry if clipboard is busy. * * @param resources the resources to copy to the clipboard * @param fileNames file names of the resources to copy to the clipboard * @param names string representation of all names */ private void setClipboard(IResource[] resources, String[] fileNames, String names) { try { // set the clipboard contents if (fileNames.length > 0) { clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() }); } else { clipboard.setContents(new Object[] { resources, names }, new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() }); } } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog .openQuestion( shell, WorkbenchNavigatorMessages.actions_CopyAction_msgTitle, // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title, //$NON-NLS-1$ WorkbenchNavigatorMessages.actions_CopyAction_msg)) { //$NON-NLS-1$ setClipboard(resources, fileNames, names); } } }
Example #8
Source File: TypeHierarchyViewPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void addDragAdapters(StructuredViewer viewer) { int ops= DND.DROP_COPY | DND.DROP_LINK; Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), FileTransfer.getInstance()}; JdtViewerDragAdapter dragAdapter= new JdtViewerDragAdapter(viewer); dragAdapter.addDragSourceListener(new SelectionTransferDragAdapter(viewer)); dragAdapter.addDragSourceListener(new EditorInputTransferDragAdapter(viewer)); dragAdapter.addDragSourceListener(new ResourceTransferDragAdapter(viewer)); dragAdapter.addDragSourceListener(new FileTransferDragAdapter(viewer)); viewer.addDragSupport(ops, transfers, dragAdapter); }
Example #9
Source File: JdtViewerDragSupport.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void start() { Assert.isLegal(!fStarted); int ops= DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), FileTransfer.getInstance()}; fViewer.addDragSupport(ops, transfers, fDragAdapter); fStarted= true; }
Example #10
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean canEnable(TransferData[] availableDataTypes) { boolean resourceTransfer= isAvailable(ResourceTransfer.getInstance(), availableDataTypes); boolean javaElementTransfer= isAvailable(JavaElementTransfer.getInstance(), availableDataTypes); if (! javaElementTransfer) return canPasteSimpleProjects(availableDataTypes); if (! resourceTransfer) return canPasteJavaProjects(availableDataTypes); return canPasteJavaProjects(availableDataTypes) && canPasteSimpleProjects(availableDataTypes); }
Example #11
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected final IResource[] getClipboardResources(TransferData[] availableDataTypes) { Transfer transfer= ResourceTransfer.getInstance(); if (isAvailable(transfer, availableDataTypes)) { return (IResource[])getContents(fClipboard2, transfer, getShell()); } return null; }
Example #12
Source File: CopyToClipboardAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static Transfer[] createDataTypeArray(IResource[] resources, IJavaElement[] javaElements, String[] fileNames, TypedSource[] typedSources) { List<ByteArrayTransfer> result= new ArrayList<ByteArrayTransfer>(4); if (resources.length != 0) result.add(ResourceTransfer.getInstance()); if (javaElements.length != 0) result.add(JavaElementTransfer.getInstance()); if (fileNames.length != 0) result.add(FileTransfer.getInstance()); if (typedSources.length != 0) result.add(TypedSourceTransfer.getInstance()); result.add(TextTransfer.getInstance()); return result.toArray(new Transfer[result.size()]); }
Example #13
Source File: NavigatorDropAssistant.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public IStatus handleDrop(final CommonDropAdapter adapter, final DropTargetEvent event, final Object target) { if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) { final String[] files = (String[]) event.data; if (files != null && files.length > 0) { PasteAction.handlePaste(files); return Status.OK_STATUS; } } else if (ResourceTransfer.getInstance().isSupportedType(event.currentDataType)) { } return Status.CANCEL_STATUS; }
Example #14
Source File: PasteAction.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * 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++) { // make sure all resource data are open projects // 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(); // targetResource is null if no valid target is selected (e.g., open project) // 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; }
Example #15
Source File: ProjectExplorerDropAdapterAssistant.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
@Override public IStatus handleDrop(CommonDropAdapter dropAdapter, DropTargetEvent event, Object target) { try { // drop in folder if (target instanceof IXdsFolderContainer || target instanceof IProject || target instanceof IContainer || (dropAdapter.getCurrentOperation() == DND.DROP_COPY && ( target instanceof IFile || target instanceof IXdsResource))) { final Object data= event.data; if (data == null) { return Status.CANCEL_STATUS; } final IContainer destination= getDestination(target); if (destination == null) { return Status.CANCEL_STATUS; } IResource[] resources = null; TransferData currentTransfer = dropAdapter.getCurrentTransfer(); final int dropOperation = dropAdapter.getCurrentOperation(); if (LocalSelectionTransfer.getTransfer().isSupportedType( currentTransfer)) { resources = getSelectedResources(); } else if (ResourceTransfer.getInstance().isSupportedType( currentTransfer)) { resources = (IResource[]) event.data; } if (FileTransfer.getInstance().isSupportedType(currentTransfer)) { final String[] names = (String[]) data; // Run the import operation asynchronously. // Otherwise the drag source (e.g., Windows Explorer) will be blocked Display.getCurrent().asyncExec(new Runnable() { public void run() { getShell().forceActive(); CopyFilesAndFoldersOperation op= new CopyFilesAndFoldersOperation(getShell()); op.copyOrLinkFiles(names, destination, dropOperation); } }); } else if (event.detail == DND.DROP_COPY || event.detail == DND.DROP_LINK) { return performResourceCopy(dropAdapter, getShell(), resources); } else { ReadOnlyStateChecker checker = new ReadOnlyStateChecker( getShell(), "Move Resource Action", //$NON-NLS-1$ "Move Resource Action");//$NON-NLS-1$ resources = checker.checkReadOnlyResources(resources); MoveFilesAndFoldersOperation operation = new MoveFilesAndFoldersOperation(getShell()); operation.copyResources(resources, destination); } return Status.OK_STATUS; } } finally { // The drag source listener must not perform any operation // since this drop adapter did the remove of the source even // if we moved something. event.detail= DND.DROP_NONE; } return Status.CANCEL_STATUS; }
Example #16
Source File: PyResourceDropAdapterAssistant.java From Pydev with Eclipse Public License 1.0 | 4 votes |
@Override public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) { // aTarget = getActual(aTarget); if (DEBUG) { System.out.println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$ } // alwaysOverwrite = false; if (getCurrentTarget(aDropAdapter) == 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) { if (DEBUG) { System.out.println("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$ } status = performResourceCopy(aDropAdapter, getShell(), resources); } else { if (DEBUG) { System.out.println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$ } status = performResourceMove(aDropAdapter, resources); } } openError(status); IContainer target = getActualTarget((IResource) getCurrentTarget(aDropAdapter)); if (target != null && target.isAccessible()) { try { target.refreshLocal(IResource.DEPTH_ONE, null); } catch (CoreException e) { } } return status; }
Example #17
Source File: TypeScriptSearchResultPage.java From typescript.java with MIT License | 4 votes |
private void addDragAdapters(StructuredViewer viewer) { Transfer[] transfers= new Transfer[] { ResourceTransfer.getInstance() }; int ops= DND.DROP_COPY | DND.DROP_LINK; viewer.addDragSupport(ops, transfers, new NavigatorDragAdapter(viewer)); }
Example #18
Source File: PasteAction.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * 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 */ @Override protected boolean updateSelection(IStructuredSelection selection) { if (!super.updateSelection(selection)) { return false; } final IResource[][] clipboardData = new IResource[1][]; shell.getDisplay().syncExec(new Runnable() { @Override 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++) { // make sure all resource data are open projects // 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(); // targetResource is null if no valid target is selected (e.g., open project) // 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<? extends IResource> selectedResources = getSelectedResources(); if (selectedResources.size() > 1) { for (int i = 0; i < selectedResources.size(); i++) { IResource resource = 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) { 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; }
Example #19
Source File: FileSearchPage.java From Pydev with Eclipse Public License 1.0 | 4 votes |
private void addDragAdapters(StructuredViewer viewer) { Transfer[] transfers = new Transfer[] { ResourceTransfer.getInstance() }; int ops = DND.DROP_COPY | DND.DROP_LINK; viewer.addDragSupport(ops, transfers, new NavigatorDragAdapter(viewer)); }
Example #20
Source File: AbstractSearchIndexResultPage.java From Pydev with Eclipse Public License 1.0 | 4 votes |
private void addDragAdapters(StructuredViewer viewer) { Transfer[] transfers = new Transfer[] { ResourceTransfer.getInstance() }; int ops = DND.DROP_COPY | DND.DROP_LINK; viewer.addDragSupport(ops, transfers, new NavigatorDragAdapter(viewer)); }
Example #21
Source File: ResourceDropAdapterAssistant.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) { if (Policy.DEBUG_DND) { System.out .println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$ } // 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("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$ } status = performResourceCopy(aDropAdapter, getShell(), resources); } else { if (Policy.DEBUG_DND) { System.out .println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$ } 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; }
Example #22
Source File: ResourceDropAdapterAssistant.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) { if (Policy.DEBUG_DND) { System.out .println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$ } // 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("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$ } status = performResourceCopy(aDropAdapter, getShell(), resources); } else { if (Policy.DEBUG_DND) { System.out .println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$ } 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; }
Example #23
Source File: PasteAction.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * 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++) { // make sure all resource data are open projects // 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(); // targetResource is null if no valid target is selected (e.g., open project) // 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; }
Example #24
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public boolean canEnable(TransferData[] availableTypes) { return isAvailable(ResourceTransfer.getInstance(), availableTypes) || isAvailable(JavaElementTransfer.getInstance(), availableTypes); }
Example #25
Source File: ProjectExplorerDropAdapterAssistant.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
@Override public boolean isSupportedType(TransferData transferType) { return super.isSupportedType(transferType) || ResourceTransfer.getInstance().isSupportedType(transferType) || FileTransfer.getInstance().isSupportedType(transferType); }
Example #26
Source File: ResourceTransferDragAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public Transfer getTransfer() { return ResourceTransfer.getInstance(); }
Example #27
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public boolean canEnable(TransferData[] availableTypes) { fAvailableTypes= availableTypes; return isAvailable(JavaElementTransfer.getInstance(), availableTypes) || isAvailable(ResourceTransfer.getInstance(), availableTypes); }