/** * @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 dropAdapter, DropTargetEvent event, Object target) { switch (event.detail) { case DND.DROP_DEFAULT: case DND.DROP_MOVE: return handleDropMove(target, event); case DND.DROP_COPY: return handleDropCopy(target, event); default: break; } return Status.CANCEL_STATUS; }
/** * Performs a drop using the FileTransfer transfer type. */ private IStatus performFileDrop(final CommonDropAdapter anAdapter, final Object data) { final int currentOperation = anAdapter.getCurrentOperation(); final MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 0, WorkbenchNavigatorMessages.DropAdapter_problemImporting, null); mergeStatus(problems, validateTarget(anAdapter.getCurrentTarget(), anAdapter.getCurrentTransfer(), currentOperation)); final IContainer target = getActualTarget(ResourceManager.getResource(anAdapter.getCurrentTarget())); final String[] names = (String[]) data; // Run the import operation asynchronously. // Otherwise the drag source (e.g., Windows Explorer) will be blocked // while the operation executes. Fixes bug 16478. Display.getCurrent().asyncExec(() -> { getShell().forceActive(); new CopyFilesAndFoldersOperation(getShell()).copyOrLinkFiles(names, target, currentOperation); }); return problems; }
@Override public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) { IStatus status = null; if ((aDropAdapter.getCurrentTarget() == null) || (aDropTargetEvent.data == null)) { return Status.CANCEL_STATUS; } // TransferData currentTransfer = aDropAdapter.getCurrentTransfer(); // if (FileTransfer.getInstance().isSupportedType(currentTransfer)) status = performFileDrop(aDropAdapter, aDropTargetEvent.data); openError(status); IContainer target = getActualTarget(((MediaRootNode) aDropAdapter.getCurrentTarget()).getResource()); if ((target != null) && target.isAccessible()) { try { target.refreshLocal(IResource.DEPTH_ONE, null); } catch (CoreException e) { // } } return status; }
/** * Performs a drop using the FileTransfer transfer type. * * @param anAdapter * the an adapter * @param data * the data * @return the i status */ private IStatus performFileDrop(CommonDropAdapter anAdapter, Object data) { MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 0, WorkbenchNavigatorMessages.DropAdapter_problemImporting, null); mergeStatus(problems, validateTarget(anAdapter.getCurrentTarget(), anAdapter.getCurrentTransfer(), anAdapter.getCurrentOperation())); final IContainer target = getActualTarget(((MediaRootNode) anAdapter.getCurrentTarget()).getResource()); final String[] names = (String[]) data; // Run the import operation asynchronously. // Otherwise the drag source (e.g., Windows Explorer) will be blocked // while the operation executes. Fixes bug 16478. Display.getCurrent().asyncExec(new Runnable() { public void run() { getShell().forceActive(); CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(getShell()); operation.copyFiles(names, target); } }); return problems; }
/** * Performs a drop using the FileTransfer transfer type. */ private IStatus performFileDrop(final CommonDropAdapter anAdapter, Object data) { final int currentOperation = anAdapter.getCurrentOperation(); MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 0, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_problemImporting, null); mergeStatus(problems, validateTarget(anAdapter.getCurrentTarget(), anAdapter .getCurrentTransfer(), currentOperation)); final IContainer target = getActualTarget((IResource) anAdapter .getCurrentTarget()); final String[] names = (String[]) data; // Run the import operation asynchronously. // Otherwise the drag source (e.g., Windows Explorer) will be blocked // while the operation executes. Fixes bug 16478. Display.getCurrent().asyncExec(new Runnable() { public void run() { getShell().forceActive(); new CopyFilesAndFoldersOperation(getShell()).copyOrLinkFiles(names, target, currentOperation); } }); return problems; }
/** * Performs a resource copy */ private IStatus performResourceCopy(CommonDropAdapter dropAdapter, Shell shell, IResource[] sources) { MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, WorkbenchNavigatorMessages.DropAdapter_problemsMoving, null); mergeStatus( problems, validateTarget(getCurrentTarget(dropAdapter), dropAdapter.getCurrentTransfer(), dropAdapter.getCurrentOperation())); IContainer target = getActualTarget((IResource) getCurrentTarget(dropAdapter)); CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell); IResource[] copiedResources = operation.copyResources(sources, target); if (copiedResources.length > 0) { PythonPathHelper.updatePyPath(copiedResources, target, PythonPathHelper.OPERATION_COPY); } return problems; }
/** * Performs a drop using the FileTransfer transfer type. */ private IStatus performFileDrop(CommonDropAdapter anAdapter, Object data) { data = getActual(data); MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 0, WorkbenchNavigatorMessages.DropAdapter_problemImporting, null); mergeStatus( problems, validateTarget(getCurrentTarget(anAdapter), anAdapter.getCurrentTransfer(), anAdapter.getCurrentOperation())); final IContainer target = getActualTarget((IResource) getCurrentTarget(anAdapter)); final String[] names = (String[]) data; // Run the import operation asynchronously. // Otherwise the drag source (e.g., Windows Explorer) will be blocked // while the operation executes. Fixes bug 16478. Display.getCurrent().asyncExec(new Runnable() { @Override public void run() { getShell().forceActive(); CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(getShell()); operation.copyFiles(names, target); } }); return problems; }
@Override protected void initDragAndDrop() { int operations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; CommonDragAdapter dragAdapter = createDragAdapter(); addDragSupport(operations, dragAdapter.getSupportedDragTransfers(), dragAdapter); CommonDropAdapter dropAdapter = createDropAdapter(); addDropSupport(operations, dropAdapter.getSupportedDropTransfers(), dropAdapter); // Set the drop adaptor of the PyDev content service instead of the standard one, // which shouldn't be used for drop policies. NavigatorDnDService dnd = (NavigatorDnDService) pyContentService.getDnDService(); dnd.setDropAdaptor(dropAdapter); }
private IStatus performProjectCopy(final CommonDropAdapter aDropAdapter, final Shell shell, final IResource[] resources) { ResourceManager.setSelectedFolder(aDropAdapter.getCurrentTarget()); for (int i = 0; i < resources.length; i++) { final CopyProjectOperation operation = new CopyProjectOperation(shell); operation.copyProject((IProject) resources[i]); } return null; }
@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; }
@Override public IStatus handleDrop(CommonDropAdapter dropAdapter, DropTargetEvent dropTargetEvent, Object target) { Navigator navigator = (Navigator) PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage() .findView(Navigator.ID); DropTarget dropTarget = (DropTarget) dropTargetEvent.getSource(); INavigationElement<?> targetElement = (INavigationElement<?>) target; if (dropTarget.getControl() == navigator.getCommonViewer().getTree()) doIt(dropTargetEvent, targetElement); return null; }
/** * Performs a resource copy */ private IStatus performResourceCopy(final CommonDropAdapter dropAdapter, final Shell shell, final IResource[] sources) { final MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, WorkbenchNavigatorMessages.DropAdapter_problemsMoving, null); mergeStatus(problems, validateTarget(dropAdapter.getCurrentTarget(), dropAdapter.getCurrentTransfer(), dropAdapter.getCurrentOperation())); final IContainer target = getActualTarget(ResourceManager.getResource(dropAdapter.getCurrentTarget())); boolean shouldLinkAutomatically = false; if (target.isVirtual()) { shouldLinkAutomatically = true; for (int i = 0; i < sources.length; i++) { if (sources[i].getType() != IResource.FILE && sources[i].getLocation() != null) { // If the source is a folder, but the location is null (a // broken link, for example), // we still generate a link automatically (the best option). shouldLinkAutomatically = false; break; } } } final CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell); // if the target is a virtual folder and all sources are files, then // automatically create links if (shouldLinkAutomatically) { operation.setCreateLinks(true); operation.copyResources(sources, target); } else { boolean allSourceAreLinksOrVirtualFolders = true; for (int i = 0; i < sources.length; i++) { if (!sources[i].isVirtual() && !sources[i].isLinked()) { allSourceAreLinksOrVirtualFolders = false; break; } } // if all sources are either links or groups, copy then normally, // don't show the dialog if (!allSourceAreLinksOrVirtualFolders) { final IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); final String dndPreference = store.getString( target.isVirtual() ? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE : IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE); if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT)) { final ImportTypeDialog dialog = new ImportTypeDialog(getShell(), dropAdapter.getCurrentOperation(), sources, target); dialog.setResource(target); if (dialog.open() == Window.OK) { if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS) operation.setVirtualFolders(true); if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK) operation.setCreateLinks(true); if (dialog.getVariable() != null) operation.setRelativeVariable(dialog.getVariable()); operation.copyResources(sources, target); } else return problems; } else operation.copyResources(sources, target); } else operation.copyResources(sources, target); } return problems; }
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; }
/** * Performs a resource copy */ private IStatus performResourceCopy(CommonDropAdapter dropAdapter, Shell shell, IResource[] sources) { MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_problemsMoving, null); mergeStatus(problems, validateTarget(dropAdapter.getCurrentTarget(), dropAdapter.getCurrentTransfer(), dropAdapter.getCurrentOperation())); IContainer target = getActualTarget((IResource) dropAdapter.getCurrentTarget()); boolean shouldLinkAutomatically = false; if (target.isVirtual()) { shouldLinkAutomatically = true; for (int i = 0; i < sources.length; i++) { if ((sources[i].getType() != IResource.FILE) && (sources[i].getLocation() != null)) { // If the source is a folder, but the location is null (a // broken link, for example), // we still generate a link automatically (the best option). shouldLinkAutomatically = false; break; } } } CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell); // if the target is a virtual folder and all sources are files, then // automatically create links if (shouldLinkAutomatically) { operation.setCreateLinks(true); operation.copyResources(sources, target); } else { // boolean allSourceAreLinksOrVirtualFolders = true; // for (int i = 0; i < sources.length; i++) { // if (!sources[i].isVirtual() && !sources[i].isLinked()) { // allSourceAreLinksOrVirtualFolders = false; // break; // } // } // // if all sources are either links or groups, copy then normally, // // don't show the dialog // if (!allSourceAreLinksOrVirtualFolders) { // IPreferenceStore store= IDEWorkbenchPlugin.getDefault().getPreferenceStore(); // String dndPreference= store.getString(target.isVirtual() ? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE : IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE); // // if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT)) { // ImportTypeDialog dialog = new ImportTypeDialog(getShell(), dropAdapter.getCurrentOperation(), sources, target); // dialog.setResource(target); // if (dialog.open() == Window.OK) { // if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS) // operation.setVirtualFolders(true); // if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK) // operation.setCreateLinks(true); // if (dialog.getVariable() != null) // operation.setRelativeVariable(dialog.getVariable()); // operation.copyResources(sources, target); // } else // return problems; // } // else // operation.copyResources(sources, target); // } else operation.copyResources(sources, target); } return problems; }
@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; }
private Object getCurrentTarget(CommonDropAdapter dropAdapter) { return getActual(dropAdapter.getCurrentTarget()); }
@Override public void setDropAdaptor(CommonDropAdapter da) { super.setDropAdaptor(da); pyDropAdapter = da; }
@Override protected CommonDropAdapter createDropAdapter() { return new CommonDropAdapter(pyContentService, this); }
/** * Made public for testing purposes. * * <p> * {@inheritDoc} */ @Override @VisibleForTesting public CommonDropAdapter getCommonDropAdapter() { return super.getCommonDropAdapter(); }