### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.navigator.resources Index: src/org/eclipse/ui/internal/navigator/resources/actions/NewActionProvider.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/NewActionProvider.java,v retrieving revision 1.2 diff -u -r1.2 NewActionProvider.java --- src/org/eclipse/ui/internal/navigator/resources/actions/NewActionProvider.java 9 Feb 2006 22:37:51 -0000 1.2 +++ src/org/eclipse/ui/internal/navigator/resources/actions/NewActionProvider.java 22 Feb 2006 04:34:55 -0000 @@ -87,7 +87,7 @@ */ public void fillContextMenu(IMenuManager menu) { IMenuManager submenu = new MenuManager( - WorkbenchNavigatorMessages.Workbench_new, + WorkbenchNavigatorMessages.NewActionProvider_NewMenu_label, ICommonMenuConstants.GROUP_NEW); if(!contribute) return; Index: src/org/eclipse/ui/internal/navigator/resources/actions/ResourceOpenListener.java =================================================================== RCS file: src/org/eclipse/ui/internal/navigator/resources/actions/ResourceOpenListener.java diff -N src/org/eclipse/ui/internal/navigator/resources/actions/ResourceOpenListener.java --- src/org/eclipse/ui/internal/navigator/resources/actions/ResourceOpenListener.java 8 Feb 2006 00:47:45 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.ui.internal.navigator.resources.actions; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.viewers.IOpenListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.OpenEvent; -import org.eclipse.ui.actions.OpenFileAction; -import org.eclipse.ui.navigator.CommonNavigator; -import org.eclipse.ui.navigator.INavigatorContentService; - -/** - *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is a guarantee neither that this API will - * work nor that it will remain the same. Please do not use this API without - * consulting with the Platform/UI team. - *

- * @since 3.2 - */ -public class ResourceOpenListener implements IOpenListener { - OpenFileAction openFileAction ; - private CommonNavigator commonNavigator; - private INavigatorContentService contentService; - - public void initialize(CommonNavigator aCommonNavigator, INavigatorContentService aContentService) { - commonNavigator = aCommonNavigator; - contentService = aContentService; - openFileAction = new OpenFileAction(commonNavigator.getSite().getPage()); - - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IOpenListener#open(org.eclipse.jface.viewers.OpenEvent) - */ - public void open(OpenEvent event) { - ISelection selection = event.getSelection(); - if (selection != null && selection instanceof IStructuredSelection) { - if (openFileAction != null ) { - IStructuredSelection structureSelection = (IStructuredSelection) selection; - Object element = structureSelection.getFirstElement(); - if (element instanceof IFile) { - openFileAction.selectionChanged(structureSelection); - openFileAction.run(); - } - } - } - } - -} Index: src/org/eclipse/ui/internal/navigator/resources/actions/OpenActionProvider.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/OpenActionProvider.java,v retrieving revision 1.2 diff -u -r1.2 OpenActionProvider.java --- src/org/eclipse/ui/internal/navigator/resources/actions/OpenActionProvider.java 9 Feb 2006 22:37:51 -0000 1.2 +++ src/org/eclipse/ui/internal/navigator/resources/actions/OpenActionProvider.java 22 Feb 2006 04:34:55 -0000 @@ -91,7 +91,7 @@ if (openable != null) { // Create a menu flyout. IMenuManager submenu = new MenuManager( - WorkbenchNavigatorMessages.OpenWithMenu_label, + WorkbenchNavigatorMessages.OpenActionProvider_OpenWithMenu_label, ICommonMenuConstants.GROUP_OPEN_WITH); submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP)); submenu.add(new OpenWithMenu(viewSite.getPage(), openable)); Index: src/org/eclipse/ui/internal/navigator/resources/actions/PortingActionProvider.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/PortingActionProvider.java,v retrieving revision 1.2 diff -u -r1.2 PortingActionProvider.java --- src/org/eclipse/ui/internal/navigator/resources/actions/PortingActionProvider.java 9 Feb 2006 22:37:51 -0000 1.2 +++ src/org/eclipse/ui/internal/navigator/resources/actions/PortingActionProvider.java 22 Feb 2006 04:34:56 -0000 @@ -159,7 +159,7 @@ } IMenuManager submenu = new MenuManager( - WorkbenchNavigatorMessages.ImportResourcesMenu_text, + WorkbenchNavigatorMessages.PortingActionProvider_ImportResourcesMenu_label, COMMON_NAVIGATOR_IMPORT_MENU); importWizardActionGroup.fillContextMenu(submenu); @@ -177,7 +177,7 @@ return; } IMenuManager submenu = new MenuManager( - WorkbenchNavigatorMessages.ExportResourcesMenu_text, + WorkbenchNavigatorMessages.PortingActionProvider_ExportResourcesMenu_label, COMMON_NAVIGATOR_EXPORT_MENU); exportWizardActionGroup.fillContextMenu(submenu); Index: property_files/messages.properties =================================================================== RCS file: property_files/messages.properties diff -N property_files/messages.properties --- property_files/messages.properties 4 Jan 2006 22:42:20 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,19 +0,0 @@ -############################################################################### -# Copyright (c) 2005 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -ResourceExtensionFilterProvider_Hides=Hides - -ImportResourcesMenu_text = &Import - -ExportResourcesMenu_text = E&xport - - -Workbench_new = &New -OpenWithMenu_label=Open With Index: src/org/eclipse/ui/internal/navigator/resources/plugin/WorkbenchNavigatorPlugin.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/plugin/WorkbenchNavigatorPlugin.java,v retrieving revision 1.1 diff -u -r1.1 WorkbenchNavigatorPlugin.java --- src/org/eclipse/ui/internal/navigator/resources/plugin/WorkbenchNavigatorPlugin.java 8 Feb 2006 00:47:45 -0000 1.1 +++ src/org/eclipse/ui/internal/navigator/resources/plugin/WorkbenchNavigatorPlugin.java 22 Feb 2006 04:34:56 -0000 @@ -12,7 +12,7 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -26,11 +26,14 @@ * work nor that it will remain the same. Please do not use this API without * consulting with the Platform/UI team. *

+ * * @since 3.2 */ public class WorkbenchNavigatorPlugin extends AbstractUIPlugin { - //The shared instance. + // The shared instance. private static WorkbenchNavigatorPlugin plugin; + + /** The plugin id */ public static String PLUGIN_ID = "org.eclipse.ui.navigator.resources"; //$NON-NLS-1$ /** @@ -42,14 +45,14 @@ } /** - * Returns the shared instance. + * @return the shared instance. */ public static WorkbenchNavigatorPlugin getDefault() { return plugin; } /** - * Returns the workspace instance. + * @return the workspace instance. */ public static IWorkspace getWorkspace() { return ResourcesPlugin.getWorkspace(); @@ -57,13 +60,89 @@ /** * Logs errors. + * @param message The message to log + * @param status The status to log */ public static void log(String message, IStatus status) { if (message != null) { - getDefault().getLog().log( new Status(IStatus.ERROR, PLUGIN_ID, 0, message, null)); + getDefault().getLog().log( + new Status(IStatus.ERROR, PLUGIN_ID, 0, message, null)); System.err.println(message + "\nReason:"); //$NON-NLS-1$ } getDefault().getLog().log(status); System.err.println(status.getMessage()); } + + /** + * Create a status associated with this plugin. + * + * @param severity + * @param aCode + * @param aMessage + * @param exception + * @return A status configured with this plugin's id and the given + * parameters. + */ + public static IStatus createStatus(int severity, int aCode, + String aMessage, Throwable exception) { + return new Status(severity, PLUGIN_ID, aCode, + aMessage != null ? aMessage : "No message.", exception); //$NON-NLS-1$ + } + + /** + * + * @param aCode + * @param aMessage + * @param exception + * @return A status configured with this plugin's id and the given + * parameters. + */ + public static IStatus createErrorStatus(int aCode, String aMessage, + Throwable exception) { + return createStatus(IStatus.ERROR, aCode, aMessage, exception); + } + + + /** + * + * @param aMessage + * @param exception + * @return A status configured with this plugin's id and the given + * parameters. + */ + public static IStatus createErrorStatus(String aMessage, Throwable exception) { + return createStatus(IStatus.ERROR, 0, aMessage, exception); + } + + /** + * + * @param aMessage + * @return A status configured with this plugin's id and the given + * parameters. + */ + public static IStatus createErrorStatus(String aMessage) { + return createStatus(IStatus.ERROR, 0, aMessage, null); + } + + + /** + * + * @param aMessage + * @return A status configured with this plugin's id and the given + * parameters. + */ + public static IStatus createInfoStatus(String aMessage) { + return createStatus(IStatus.INFO, 0, aMessage, null); + } + + + /** + * + * @param aMessage + * @return A status configured with this plugin's id and the given + * parameters. + */ + public static IStatus createWarningStatus(String aMessage) { + return createStatus(IStatus.WARNING, 0, aMessage, null); + } } Index: src/org/eclipse/ui/internal/navigator/resources/plugin/WorkbenchNavigatorMessages.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/plugin/WorkbenchNavigatorMessages.java,v retrieving revision 1.1 diff -u -r1.1 WorkbenchNavigatorMessages.java --- src/org/eclipse/ui/internal/navigator/resources/plugin/WorkbenchNavigatorMessages.java 8 Feb 2006 00:47:45 -0000 1.1 +++ src/org/eclipse/ui/internal/navigator/resources/plugin/WorkbenchNavigatorMessages.java 22 Feb 2006 04:34:56 -0000 @@ -16,26 +16,61 @@ * Utility class which helps managing messages * * - *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is a guarantee neither that this API will - * work nor that it will remain the same. Please do not use this API without - * consulting with the Platform/UI team. - *

* @since 3.2 */ -public class WorkbenchNavigatorMessages extends NLS { - public static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$ +public class WorkbenchNavigatorMessages extends NLS { + /** The bundle properties file */ + public static final String BUNDLE_NAME = "org.eclipse.ui.internal.navigator.resources.plugin.messages"; //$NON-NLS-1$ - public static String ResourceExtensionFilterProvider_Hides; - public static String ImportResourcesMenu_text; - public static String ExportResourcesMenu_text; - + /** Message key. */ + public static String PortingActionProvider_ImportResourcesMenu_label; - public static String Workbench_new; - public static String OpenWithMenu_label; - + /** Message key. */ + public static String PortingActionProvider_ExportResourcesMenu_label; + + /** Message key. */ + public static String NewActionProvider_NewMenu_label; + + /** Message key. */ + public static String OpenActionProvider_OpenWithMenu_label; + + /** Message key. */ + public static String DropAdapter_title; + + /** Message key. */ + public static String DropAdapter_problemImporting; + + /** Message key. */ + public static String DropAdapter_problemsMoving; + + /** Message key. */ + public static String DropAdapter_question; + + /** Message key. */ + public static String DropAdapter_targetMustBeResource; + + /** Message key. */ + public static String DropAdapter_canNotDropIntoClosedProject; + + /** Message key. */ + public static String DropAdapter_resourcesCanNotBeSiblings; + + /** Message key. */ + public static String DropAdapter_ok; + + /** Message key. */ + public static String DropAdapter_overwriteQuery; + + /** Message key. */ + public static String DropAdapter_dropOperationErrorOther; + + /** Message key. */ + public static String MoveResourceAction_title; + + /** Message key. */ + public static String MoveResourceAction_checkMoveMessage; + static { initializeMessages(BUNDLE_NAME, WorkbenchNavigatorMessages.class); } Index: .classpath =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/.classpath,v retrieving revision 1.2 diff -u -r1.2 .classpath --- .classpath 1 Dec 2005 22:00:23 -0000 1.2 +++ .classpath 22 Feb 2006 04:34:54 -0000 @@ -1,7 +1,6 @@ - Index: plugin.xml =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/plugin.xml,v retrieving revision 1.16 diff -u -r1.16 plugin.xml --- plugin.xml 8 Feb 2006 00:47:45 -0000 1.16 +++ plugin.xml 22 Feb 2006 04:34:55 -0000 @@ -49,6 +49,9 @@ + @@ -96,6 +99,17 @@ + + + + + + + + + @@ -199,30 +213,5 @@ - - - - - - - - - - - - - - - - Index: build.properties =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/build.properties,v retrieving revision 1.5 diff -u -r1.5 build.properties --- build.properties 3 Jan 2006 16:28:59 -0000 1.5 +++ build.properties 22 Feb 2006 04:34:54 -0000 @@ -8,8 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation ############################################################################### -source.. = src/,\ - property_files/ +source.. = src/ bin.includes = plugin.xml,\ icons/,\ .,\ Index: .settings/org.eclipse.core.resources.prefs =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/.settings/org.eclipse.core.resources.prefs,v retrieving revision 1.1 diff -u -r1.1 org.eclipse.core.resources.prefs --- .settings/org.eclipse.core.resources.prefs 27 Oct 2005 16:19:49 -0000 1.1 +++ .settings/org.eclipse.core.resources.prefs 22 Feb 2006 04:34:55 -0000 @@ -1,3 +1,3 @@ -#Thu Oct 27 12:07:09 EDT 2005 +#Tue Feb 21 13:59:06 EST 2006 eclipse.preferences.version=1 -encoding//property_files/messages.properties=8859_1 +encoding//src/org/eclipse/ui/internal/navigator/resources/plugin/messages.properties=8859_1 Index: src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceDropAction.java =================================================================== RCS file: src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceDropAction.java diff -N src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceDropAction.java --- src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceDropAction.java 9 Feb 2006 21:31:52 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,439 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.ui.internal.navigator.resources.workbench; - -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ViewerDropAdapter; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.DropTargetEvent; -import org.eclipse.swt.dnd.FileTransfer; -import org.eclipse.swt.dnd.TransferData; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.CopyFilesAndFoldersOperation; -import org.eclipse.ui.actions.MoveFilesAndFoldersOperation; -import org.eclipse.ui.actions.ReadOnlyStateChecker; -import org.eclipse.ui.dialogs.IOverwriteQuery; -import org.eclipse.ui.internal.navigator.AdaptabilityUtility; -import org.eclipse.ui.navigator.CommonDropAdapterAssistant; -import org.eclipse.ui.part.PluginDropAdapter; -import org.eclipse.ui.part.ResourceTransfer; -import org.eclipse.ui.views.navigator.LocalSelectionTransfer; -import org.eclipse.ui.views.navigator.ResourceNavigatorMessages; - -/** - *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is a guarantee neither that this API will - * work nor that it will remain the same. Please do not use this API without - * consulting with the Platform/UI team. - *

- * @since 3.2 - * - */ -public class ResourceDropAction extends CommonDropAdapterAssistant implements IOverwriteQuery { - - /** - * A flag indicating that overwrites should always occur. - */ - private boolean alwaysOverwrite = false; - - /** - * The last valid operation. - */ - private int lastValidOperation = DND.DROP_NONE; - - protected static final Class IRESOURCE_CLASS = IResource.class; - - private CopyFilesAndFoldersOperation copyOperation; - - private CopyFilesAndFoldersOperation moveOperation; - - /** - * - */ - public ResourceDropAction() { - super(); - } - - /** - * Returns an error status with the given info. - */ - private IStatus error(String message) { - return error(message, null); - } - - /** - * Returns an error status with the given info. - */ - private IStatus error(String message, Throwable exception) { - return new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, message, exception); - } - - /** - * Returns the actual target of the drop, given the resource under the mouse. If the mouse - * target is a file, then the drop actually occurs in its parent. If the drop location is before - * or after the mouse target and feedback is enabled, the target is also the parent. - */ - private IContainer getActualTarget(PluginDropAdapter dropAdapter, IResource mouseTarget) { - /* if cursor is before or after mouseTarget, set target to parent */ - if (dropAdapter.getFeedbackEnabled()) { - if (getCurrentLocation() == ViewerDropAdapter.LOCATION_BEFORE || getCurrentLocation() == ViewerDropAdapter.LOCATION_AFTER) { - return mouseTarget.getParent(); - } - } - /* if cursor is on a file, return the parent */ - if (mouseTarget.getType() == IResource.FILE) { - return mouseTarget.getParent(); - } - /* otherwise the mouseTarget is the real target */ - return (IContainer) mouseTarget; - } - - /** - * @return - */ - private int getCurrentLocation() { - // TODO Auto-generated method stub - return 0; - } - - /** - * Returns the resource selection from the LocalSelectionTransfer. - * - * @return the resource selection from the LocalSelectionTransfer - */ - private IResource[] getSelectedResources() { - IResource[] selectedResources = null; - - ISelection selection = LocalSelectionTransfer.getInstance().getSelection(); - if (selection instanceof IStructuredSelection) { - List selectionList = ((IStructuredSelection) selection).toList(); - selectedResources = (IResource[]) selectionList.toArray(new IResource[selectionList.size()]); - } - return selectedResources; - } - - /** - * Returns an error status with the given info. - */ - private IStatus info(String message) { - return new Status(IStatus.INFO, PlatformUI.PLUGIN_ID, 0, message, null); - } - - /** - * Adds the given status to the list of problems. Discards OK statuses. If the status is a - * multi-status, only its children are added. - */ - private void mergeStatus(MultiStatus status, IStatus toMerge) { - if (!toMerge.isOK()) { - status.merge(toMerge); - } - } - - /** - * Returns an status indicating success. - */ - private IStatus ok() { - return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, ResourceNavigatorMessages.getString("DropAdapter.ok"), null); //$NON-NLS-1$ - } - - /** - * Opens an error dialog if necessary. Takes care of complex rules necessary for making the - * error dialog look nice. - */ - private void openError(IStatus status) { - if (status == null) - return; - - String genericTitle = ResourceNavigatorMessages.getString("DropAdapter.title"); //$NON-NLS-1$ - int codes = IStatus.ERROR | IStatus.WARNING; - - //simple case: one error, not a multistatus - if (!status.isMultiStatus()) { - ErrorDialog.openError(getShell(), genericTitle, null, status, codes); - return; - } - - //one error, single child of multistatus - IStatus[] children = status.getChildren(); - if (children.length == 1) { - ErrorDialog.openError(getShell(), status.getMessage(), null, children[0], codes); - return; - } - //several problems - ErrorDialog.openError(getShell(), genericTitle, null, status, codes); - } - - /** - * @return - */ - private Shell getShell() { - // TODO Auto-generated method stub - return null; - } - - /** - * Performs a drop using the FileTransfer transfer type. - */ - private IStatus performFileDrop(PluginDropAdapter dropAdapter, Object data) { - MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 0, ResourceNavigatorMessages.getString("DropAdapter.problemImporting"), null); //$NON-NLS-1$ - mergeStatus(problems, validateTarget(dropAdapter, getCurrentTarget(), getCurrentTransfer())); - - try { - final IContainer target = getActualTarget(dropAdapter, getResource(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(); - CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(getShell()); - operation.copyFiles(names, target); - } - }); - } catch (Throwable t) { - t.printStackTrace(); - } - return problems; - } - - /** - * @return - */ - private TransferData getCurrentTransfer() { - // TODO Auto-generated method stub - return null; - } - - /** - * Performs a resource copy - */ - private IStatus performResourceCopy(PluginDropAdapter dropAdapter, IResource[] sources) { - MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, ResourceNavigatorMessages.getString("DropAdapter.problemsMoving"), null); //$NON-NLS-1$ - mergeStatus(problems, validateTarget(dropAdapter, getCurrentTarget(), getCurrentTransfer())); - - IContainer target = getActualTarget(dropAdapter, getResource(getCurrentTarget())); - getCopyOperation().copyResources(sources, target); - copyOperation = null; - return problems; - } - - /** - * @return - */ - private Object getCurrentTarget() { - // TODO Auto-generated method stub - return null; - } - - /** - * Performs a resource move - */ - private IStatus performResourceMove(PluginDropAdapter dropAdapter, IResource[] sources) { - MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, ResourceNavigatorMessages.getString("DropAdapter.problemsMoving"), null); //$NON-NLS-1$ - mergeStatus(problems, validateTarget(dropAdapter, getCurrentTarget(), getCurrentTransfer())); - - IContainer target = getActualTarget(dropAdapter, getResource(getCurrentTarget())); - ReadOnlyStateChecker checker = new ReadOnlyStateChecker(getShell(), ResourceNavigatorMessages.getString("MoveResourceAction.title"), //$NON-NLS-1$ - ResourceNavigatorMessages.getString("MoveResourceAction.checkMoveMessage"));//$NON-NLS-1$ - sources = checker.checkReadOnlyResources(sources); - - getMoveOperation().copyResources(sources, target); - moveOperation = null; - - return problems; - } - - /* - * @see IOverwriteQuery#queryOverwrite(String) - */ - public String queryOverwrite(String pathString) { - if (this.alwaysOverwrite) - return ALL; - - final String returnCode[] = {CANCEL}; - final String msg = ResourceNavigatorMessages.format("DropAdapter.overwriteQuery", new Object[]{pathString}); //$NON-NLS-1$ - final String[] options = {IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL}; - getDisplay().syncExec(new Runnable() { - - public void run() { - MessageDialog dialog = new MessageDialog(getShell(), ResourceNavigatorMessages.getString("DropAdapter.question"), null, msg, MessageDialog.QUESTION, options, 0); //$NON-NLS-1$ - dialog.open(); - int returnVal = dialog.getReturnCode(); - String[] returnCodes = {YES, ALL, NO, CANCEL}; - returnCode[0] = returnVal < 0 ? CANCEL : returnCodes[returnVal]; - } - }); - if (returnCode[0] == ALL) - this.alwaysOverwrite = true; - return returnCode[0]; - } - - /** - * @return - */ - private Display getDisplay() { - // TODO Auto-generated method stub - return null; - } - - public boolean validateDrop(PluginDropAdapter dropAdapter, Object target, int operation, TransferData transferType) { - return validateTarget(dropAdapter, target, transferType).isOK(); - } - - - public boolean run(PluginDropAdapter dropAdapter, Object data, Object target) { - - this.alwaysOverwrite = false; - if (getCurrentTarget() == null || data == null) { - return false; - } - boolean result = false; - IStatus status = null; - IResource[] resources = null; - TransferData currentTransfer = getCurrentTransfer(); - if (LocalSelectionTransfer.getInstance().isSupportedType(currentTransfer)) { - resources = getSelectedResources(); - } else if (ResourceTransfer.getInstance().isSupportedType(currentTransfer)) { - resources = (IResource[]) data; - } else if (FileTransfer.getInstance().isSupportedType(currentTransfer)) { - status = performFileDrop(dropAdapter, data); - result = status.isOK(); - } - if (resources != null) { - if (getCurrentOperation() == DND.DROP_COPY) - status = performResourceCopy(dropAdapter, resources); - else - status = performResourceMove(dropAdapter, resources); - } - openError(status); - return result; - } - - /** - * @return - */ - private int getCurrentOperation() { - // TODO Auto-generated method stub - return 0; - } - - /** - * Ensures that the drop target meets certain criteria - */ - private IStatus validateTarget(PluginDropAdapter dropAdapter, Object target, TransferData transferType) { - if (!(target instanceof IResource)) { - return info(ResourceNavigatorMessages.getString("DropAdapter.targetMustBeResource")); //$NON-NLS-1$ - } - IResource resource = getResource(getCurrentTarget()); - if (!resource.isAccessible()) { - return error(ResourceNavigatorMessages.getString("DropAdapter.canNotDropIntoClosedProject")); //$NON-NLS-1$ - } - IContainer destination = getActualTarget(dropAdapter, resource); - if (destination.getType() == IResource.ROOT) { - return error(ResourceNavigatorMessages.getString("DropAdapter.resourcesCanNotBeSiblings")); //$NON-NLS-1$ - } - String message = null; - // drag within Eclipse? - if (LocalSelectionTransfer.getInstance().isSupportedType(transferType)) { - IResource[] selectedResources = getSelectedResources(); - - if (selectedResources == null) - message = ResourceNavigatorMessages.getString("DropAdapter.dropOperationErrorOther"); //$NON-NLS-1$ - else { - CopyFilesAndFoldersOperation operation; - if (this.lastValidOperation == DND.DROP_COPY) { - operation = getCopyOperation(); - } else { - operation = getMoveOperation(); - } - message = operation.validateDestination(destination, selectedResources); - } - } // file import? - else if (FileTransfer.getInstance().isSupportedType(transferType)) { - String[] sourceNames = (String[]) FileTransfer.getInstance().nativeToJava(transferType); - if (sourceNames == null) { - // source names will be null on Linux. Use empty names to do - // destination validation. - // Fixes bug 29778 - sourceNames = new String[0]; - } - message = getCopyOperation().validateImportDestination(destination, sourceNames); - } - if (message != null) { - return error(message); - } - return ok(); - } - - /** - * @return - */ - private CopyFilesAndFoldersOperation getMoveOperation() { - if (moveOperation == null) - moveOperation = new MoveFilesAndFoldersOperation(getShell()); - return moveOperation; - } - - /** - * @return - */ - private CopyFilesAndFoldersOperation getCopyOperation() { - if (copyOperation == null) - copyOperation = new CopyFilesAndFoldersOperation(getShell()); - return copyOperation; - } - - protected IResource getResource(Object target) { - return (IResource) AdaptabilityUtility.getAdapter(target, IRESOURCE_CLASS); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData) - */ - public boolean validateDrop(Object target, int operation, TransferData transferType) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object) - */ - public boolean handleDrop(DropTargetEvent aDropTargetEvent, Object aTarget) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#findSupportedTransferData(org.eclipse.swt.dnd.TransferData[]) - */ - public TransferData findSupportedTransferData(TransferData[] theAvailableTransferData) { - // TODO Auto-generated method stub - return null; - } - -} Index: src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceExtensionLabelProvider.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceExtensionLabelProvider.java,v retrieving revision 1.2 diff -u -r1.2 ResourceExtensionLabelProvider.java --- src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceExtensionLabelProvider.java 9 Feb 2006 22:37:51 -0000 1.2 +++ src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceExtensionLabelProvider.java 22 Feb 2006 04:34:57 -0000 @@ -40,13 +40,10 @@ return null; } - public void restoreState(IMemento aMemento) { - // TODO Auto-generated method stub + public void restoreState(IMemento aMemento) { } - public void saveState(IMemento aMemento) { - // TODO Auto-generated method stub - + public void saveState(IMemento aMemento) { } } Index: META-INF/MANIFEST.MF =================================================================== RCS file: /home/eclipse/org.eclipse.ui.navigator.resources/META-INF/MANIFEST.MF,v retrieving revision 1.9 diff -u -r1.9 MANIFEST.MF --- META-INF/MANIFEST.MF 8 Feb 2006 00:47:45 -0000 1.9 +++ META-INF/MANIFEST.MF 22 Feb 2006 04:34:55 -0000 @@ -9,7 +9,8 @@ Export-Package: ., org.eclipse.ui.internal.navigator.resources.actions, org.eclipse.ui.internal.navigator.resources.plugin, - org.eclipse.ui.internal.navigator.resources.workbench + org.eclipse.ui.internal.navigator.resources.workbench, + org.eclipse.ui.navigator.resources Require-Bundle: org.eclipse.ui.ide, org.eclipse.core.resources, org.eclipse.jface, Index: src/org/eclipse/ui/navigator/resources/ResourceDragAdapterAssistant.java =================================================================== RCS file: src/org/eclipse/ui/navigator/resources/ResourceDragAdapterAssistant.java diff -N src/org/eclipse/ui/navigator/resources/ResourceDragAdapterAssistant.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/navigator/resources/ResourceDragAdapterAssistant.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.ui.navigator.resources; + +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.ui.navigator.CommonDragAdapterAssistant; +import org.eclipse.ui.part.ResourceTransfer; +import org.eclipse.ui.views.navigator.LocalSelectionTransfer; + +/** + * Clients may reference this class in the dragAssistant element of a + * org.eclipse.ui.navigator.viewer extension point. + * + *

+ * Clients may not extend or instantiate this class. Clients may have no direct + * dependencies on the contract of this class. + *

+ * + * @since 3.2 + * + */ +public final class ResourceDragAdapterAssistant extends + CommonDragAdapterAssistant { + + private static final boolean DEBUG = true; + + private static final Transfer[] SUPPORTED_TRANSFERS = new Transfer[] { + ResourceTransfer.getInstance(), + LocalSelectionTransfer.getInstance(), FileTransfer.getInstance() }; + + private static final Class IRESOURCE_TYPE = IResource.class; + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#getSupportedTransferTypes() + */ + public Transfer[] getSupportedTransferTypes() { + return SUPPORTED_TRANSFERS; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#setDragData(org.eclipse.swt.dnd.DragSourceEvent, + * org.eclipse.jface.viewers.IStructuredSelection) + */ + public void setDragData(DragSourceEvent anEvent, + IStructuredSelection aSelection) { + + if (LocalSelectionTransfer.getInstance().isSupportedType( + anEvent.dataType)) { + anEvent.data = aSelection; + if (DEBUG) + System.out + .println("ResourceDragAdapterAssistant.dragSetData set LocalSelectionTransfer"); //$NON-NLS-1$ + } else if (ResourceTransfer.getInstance().isSupportedType( + anEvent.dataType)) { + anEvent.data = getSelectedResources(aSelection); + if (DEBUG) + System.out + .println("ResourceDragAdapterAssistant.dragSetData set ResourceTransfer"); //$NON-NLS-1$ + + } else if (FileTransfer.getInstance().isSupportedType(anEvent.dataType)) { + + IResource[] resources = getSelectedResources(aSelection); + + // Get the path of each file and set as the drag data + final int length = resources.length; + int actualLength = 0; + String[] fileNames = new String[length]; + for (int i = 0; i < length; i++) { + IPath location = resources[i].getLocation(); + // location may be null. See bug 29491. + if (location != null) + fileNames[actualLength++] = location.toOSString(); + } + if (actualLength == 0) + return; + // was one or more of the locations null? + if (actualLength < length) { + String[] tempFileNames = fileNames; + fileNames = new String[actualLength]; + for (int i = 0; i < actualLength; i++) + fileNames[i] = tempFileNames[i]; + } + anEvent.data = fileNames; + + if (DEBUG) + System.out + .println("ResourceDragAdapterAssistant.dragSetData set FileTransfer"); //$NON-NLS-1$ + + } + + } + + private IResource[] getSelectedResources(IStructuredSelection aSelection) { + Set resources = new LinkedHashSet(); + IResource resource = null; + for (Iterator iter = aSelection.iterator(); iter.hasNext();) { + Object selected = iter.next(); + resource = adaptToResource(selected); + if (resource != null) + + resources.add(resource); + } + return (IResource[]) resources.toArray(new IResource[resources.size()]); + } + + private IResource adaptToResource(Object selected) { + IResource resource; + if (selected instanceof IResource) + resource = (IResource) selected; + else if (selected instanceof IAdaptable) + resource = (IResource) ((IAdaptable) selected) + .getAdapter(IRESOURCE_TYPE); + else + resource = (IResource) Platform.getAdapterManager().getAdapter( + selected, IRESOURCE_TYPE); + return resource; + } + +} Index: src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java =================================================================== RCS file: src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java diff -N src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,489 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.ui.navigator.resources; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.dnd.TransferData; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.CopyFilesAndFoldersOperation; +import org.eclipse.ui.actions.MoveFilesAndFoldersOperation; +import org.eclipse.ui.actions.ReadOnlyStateChecker; +import org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorMessages; +import org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorPlugin; +import org.eclipse.ui.navigator.CommonDropAdapter; +import org.eclipse.ui.navigator.CommonDropAdapterAssistant; +import org.eclipse.ui.part.ResourceTransfer; + +/** + * @since 3.2 + * + */ +public class ResourceDropAdapterAssistant extends CommonDropAdapterAssistant { + + private static final boolean DEBUG = false; + private static final IResource[] NO_RESOURCES = new IResource[0]; + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#isSupportedType(org.eclipse.swt.dnd.TransferData) + */ + public boolean isSupportedType(TransferData aTransferType) { + return super.isSupportedType(aTransferType) + || FileTransfer.getInstance().isSupportedType(aTransferType); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object, + * int, org.eclipse.swt.dnd.TransferData) + */ + public IStatus validateDrop(Object target, int aDropOperation, + TransferData transferType) { + + if (!(target instanceof IResource)) { + return WorkbenchNavigatorPlugin + .createStatus( + IStatus.INFO, + 0, + WorkbenchNavigatorMessages.DropAdapter_targetMustBeResource, + null); + } + IResource resource = (IResource) target; + if (!resource.isAccessible()) { + return WorkbenchNavigatorPlugin + .createErrorStatus( + 0, + WorkbenchNavigatorMessages.DropAdapter_canNotDropIntoClosedProject, + null); + } + IContainer destination = getActualTarget(resource); + if (destination.getType() == IResource.ROOT) { + return WorkbenchNavigatorPlugin + .createErrorStatus( + 0, + WorkbenchNavigatorMessages.DropAdapter_resourcesCanNotBeSiblings, + null); + } + String message = null; + // drag within Eclipse? + if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) { + IResource[] selectedResources = getSelectedResources(); + + if (selectedResources.length == 0) + message = WorkbenchNavigatorMessages.DropAdapter_dropOperationErrorOther; + else { + CopyFilesAndFoldersOperation operation; + if (aDropOperation == DND.DROP_COPY) { + if (DEBUG) + System.out + .println("ResourceDropAdapterAssistant.validateDrop validating COPY."); //$NON-NLS-1$ + + operation = new CopyFilesAndFoldersOperation(getShell()); + } else { + if (DEBUG) + System.out + .println("ResourceDropAdapterAssistant.validateDrop validating MOVE."); //$NON-NLS-1$ + operation = new MoveFilesAndFoldersOperation(getShell()); + } + message = operation.validateDestination(destination, + selectedResources); + } + } // file import? + else if (FileTransfer.getInstance().isSupportedType(transferType)) { + String[] sourceNames = (String[]) FileTransfer.getInstance() + .nativeToJava(transferType); + if (sourceNames == null) { + // source names will be null on Linux. Use empty names to do + // destination validation. + // Fixes bug 29778 + sourceNames = new String[0]; + } + CopyFilesAndFoldersOperation copyOperation = new CopyFilesAndFoldersOperation( + getShell()); + message = copyOperation.validateImportDestination(destination, + sourceNames); + } + if (message != null) { + return WorkbenchNavigatorPlugin.createErrorStatus(0, message, null); + } + return Status.OK_STATUS; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(CommonDropAdapter, + * DropTargetEvent, Object) + */ + public IStatus handleDrop(CommonDropAdapter aDropAdapter, + DropTargetEvent aDropTargetEvent, Object aTarget) { + + if (DEBUG) + System.out + .println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$ + + // 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 (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) aDropAdapter + .getCurrentTarget()); + if (target != null && target.isAccessible()) + try { + target.refreshLocal(IResource.DEPTH_ONE, null); + } catch (CoreException e) { + } + return status; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validatePluginTransferDrop(org.eclipse.jface.viewers.IStructuredSelection, + * java.lang.Object) + */ + public IStatus validatePluginTransferDrop( + IStructuredSelection aDragSelection, Object aDropTarget) { + if (!(aDropTarget instanceof IResource)) { + return WorkbenchNavigatorPlugin + .createStatus( + IStatus.INFO, + 0, + WorkbenchNavigatorMessages.DropAdapter_targetMustBeResource, + null); + } + IResource resource = (IResource) aDropTarget; + if (!resource.isAccessible()) { + return WorkbenchNavigatorPlugin + .createErrorStatus( + 0, + WorkbenchNavigatorMessages.DropAdapter_canNotDropIntoClosedProject, + null); + } + IContainer destination = getActualTarget(resource); + if (destination.getType() == IResource.ROOT) { + return WorkbenchNavigatorPlugin + .createErrorStatus( + 0, + WorkbenchNavigatorMessages.DropAdapter_resourcesCanNotBeSiblings, + null); + } + + IResource[] selectedResources = getSelectedResources(aDragSelection); + + String message = null; + if (selectedResources.length == 0) + message = WorkbenchNavigatorMessages.DropAdapter_dropOperationErrorOther; + else { + MoveFilesAndFoldersOperation operation; + + operation = new MoveFilesAndFoldersOperation(getShell()); + message = operation.validateDestination(destination, + selectedResources); + } + if (message != null) + return WorkbenchNavigatorPlugin.createErrorStatus(0, message, null); + return Status.OK_STATUS; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handlePluginTransferDrop(org.eclipse.jface.viewers.IStructuredSelection, java.lang.Object) + */ + public IStatus handlePluginTransferDrop(IStructuredSelection aDragSelection, Object aDropTarget) { + + IContainer target = getActualTarget((IResource) aDropTarget); + IResource[] resources = getSelectedResources(aDragSelection); + + MoveFilesAndFoldersOperation operation = new MoveFilesAndFoldersOperation( + getShell()); + operation.copyResources(resources, target); + + if (target != null && target.isAccessible()) + try { + target.refreshLocal(IResource.DEPTH_ONE, null); + } catch (CoreException e) { + } + return Status.OK_STATUS; + } + + /** + * Returns the actual target of the drop, given the resource under the + * mouse. If the mouse target is a file, then the drop actually occurs in + * its parent. If the drop location is before or after the mouse target and + * feedback is enabled, the target is also the parent. + */ + private IContainer getActualTarget(IResource mouseTarget) { + + /* if cursor is on a file, return the parent */ + if (mouseTarget.getType() == IResource.FILE) { + return mouseTarget.getParent(); + } + /* otherwise the mouseTarget is the real target */ + return (IContainer) mouseTarget; + } + + /** + * Returns the resource selection from the LocalSelectionTransfer. + * + * @return the resource selection from the LocalSelectionTransfer + */ + private IResource[] getSelectedResources() { + + ISelection selection = LocalSelectionTransfer.getTransfer() + .getSelection(); + if (selection instanceof IStructuredSelection) + return getSelectedResources((IStructuredSelection)selection); + return NO_RESOURCES; + } + + /** + * Returns the resource selection from the LocalSelectionTransfer. + * + * @return the resource selection from the LocalSelectionTransfer + */ + private IResource[] getSelectedResources(IStructuredSelection selection) { + ArrayList selectedResources = new ArrayList(); + + for (Iterator i = selection.iterator(); i.hasNext();) { + Object o = i.next(); + if (o instanceof IResource) { + selectedResources.add(o); + } else if (o instanceof IAdaptable) { + IAdaptable a = (IAdaptable) o; + IResource r = (IResource) a.getAdapter(IResource.class); + if (r != null) { + selectedResources.add(r); + } + } + } + return (IResource[]) selectedResources + .toArray(new IResource[selectedResources.size()]); + } + + /** + * 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(dropAdapter.getCurrentTarget(), + dropAdapter.getCurrentTransfer(), dropAdapter + .getCurrentOperation())); + + IContainer target = getActualTarget((IResource) dropAdapter + .getCurrentTarget()); + CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation( + shell); + operation.copyResources(sources, target); + + return problems; + } + + /** + * Performs a resource move + */ + private IStatus performResourceMove(CommonDropAdapter dropAdapter, + IResource[] sources) { + MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, + WorkbenchNavigatorMessages.DropAdapter_problemsMoving, null); + mergeStatus(problems, validateTarget(dropAdapter.getCurrentTarget(), + dropAdapter.getCurrentTransfer(), dropAdapter + .getCurrentOperation())); + + IContainer target = getActualTarget((IResource) dropAdapter + .getCurrentTarget()); + ReadOnlyStateChecker checker = new ReadOnlyStateChecker(getShell(), + WorkbenchNavigatorMessages.MoveResourceAction_title, + WorkbenchNavigatorMessages.MoveResourceAction_checkMoveMessage); + sources = checker.checkReadOnlyResources(sources); + MoveFilesAndFoldersOperation operation = new MoveFilesAndFoldersOperation( + getShell()); + operation.copyResources(sources, target); + + return problems; + } + + /** + * Performs a drop using the FileTransfer transfer type. + */ + 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((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(); + CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation( + getShell()); + operation.copyFiles(names, target); + } + }); + return problems; + } + + /** + * Ensures that the drop target meets certain criteria + */ + private IStatus validateTarget(Object target, TransferData transferType, + int dropOperation) { + if (!(target instanceof IResource)) { + return WorkbenchNavigatorPlugin + .createInfoStatus(WorkbenchNavigatorMessages.DropAdapter_targetMustBeResource); + } + IResource resource = (IResource) target; + if (!resource.isAccessible()) { + return WorkbenchNavigatorPlugin + .createErrorStatus(WorkbenchNavigatorMessages.DropAdapter_canNotDropIntoClosedProject); + } + IContainer destination = getActualTarget(resource); + if (destination.getType() == IResource.ROOT) { + return WorkbenchNavigatorPlugin + .createErrorStatus(WorkbenchNavigatorMessages.DropAdapter_resourcesCanNotBeSiblings); + } + String message = null; + // drag within Eclipse? + if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) { + IResource[] selectedResources = getSelectedResources(); + + if (selectedResources.length == 0) + message = WorkbenchNavigatorMessages.DropAdapter_dropOperationErrorOther; + else { + CopyFilesAndFoldersOperation operation; + if (dropOperation == DND.DROP_COPY) { + operation = new CopyFilesAndFoldersOperation(getShell()); + } else { + operation = new MoveFilesAndFoldersOperation(getShell()); + } + message = operation.validateDestination(destination, + selectedResources); + } + } // file import? + else if (FileTransfer.getInstance().isSupportedType(transferType)) { + String[] sourceNames = (String[]) FileTransfer.getInstance() + .nativeToJava(transferType); + if (sourceNames == null) { + // source names will be null on Linux. Use empty names to do + // destination validation. + // Fixes bug 29778 + sourceNames = new String[0]; + } + CopyFilesAndFoldersOperation copyOperation = new CopyFilesAndFoldersOperation( + getShell()); + message = copyOperation.validateImportDestination(destination, + sourceNames); + } + if (message != null) { + return WorkbenchNavigatorPlugin.createErrorStatus(message); + } + return Status.OK_STATUS; + } + + /** + * Adds the given status to the list of problems. Discards OK statuses. If + * the status is a multi-status, only its children are added. + */ + private void mergeStatus(MultiStatus status, IStatus toMerge) { + if (!toMerge.isOK()) { + status.merge(toMerge); + } + } + + /** + * Opens an error dialog if necessary. Takes care of complex rules necessary + * for making the error dialog look nice. + */ + private void openError(IStatus status) { + if (status == null) + return; + + String genericTitle = WorkbenchNavigatorMessages.DropAdapter_title; + int codes = IStatus.ERROR | IStatus.WARNING; + + // simple case: one error, not a multistatus + if (!status.isMultiStatus()) { + ErrorDialog + .openError(getShell(), genericTitle, null, status, codes); + return; + } + + // one error, single child of multistatus + IStatus[] children = status.getChildren(); + if (children.length == 1) { + ErrorDialog.openError(getShell(), status.getMessage(), null, + children[0], codes); + return; + } + // several problems + ErrorDialog.openError(getShell(), genericTitle, null, status, codes); + } + +} Index: src/org/eclipse/ui/internal/navigator/resources/plugin/messages.properties =================================================================== RCS file: src/org/eclipse/ui/internal/navigator/resources/plugin/messages.properties diff -N src/org/eclipse/ui/internal/navigator/resources/plugin/messages.properties --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/navigator/resources/plugin/messages.properties 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,19 @@ +#String externalization, key=value +#Tue Feb 21 14:03:39 EST 2006 +DropAdapter_title=Drag and Drop Problem +OpenActionProvider_OpenWithMenu_label=Open With +DropAdapter_ok=ok +DropAdapter_question=Question +DropAdapter_resourcesCanNotBeSiblings=Resources cannot be siblings of projects +PortingActionProvider_ImportResourcesMenu_label=&Import +DropAdapter_overwriteQuery={0} already exists. Would you like to overwrite it? +PortingActionProvider_ExportResourcesMenu_label=E&xport +DropAdapter_targetMustBeResource=Target must be a resource +DropAdapter_problemImporting=Problems occurred while importing resources. +DropAdapter_problemsMoving=Problems occurred while moving resources. +DropAdapter_canNotDropIntoClosedProject=Cannot drop a resource into closed project +DropAdapter_dropOperationErrorOther=An error occurred during the drop operation. +NewActionProvider_NewMenu_label=&New + +MoveResourceAction_title = Check Move +MoveResourceAction_checkMoveMessage = ''{0}'' is read only. Do you still wish to move it?