*** empty log message ***
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/AddToWorkspaceAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/AddToWorkspaceAction.java
index 1395358..39ca590 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/AddToWorkspaceAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/AddToWorkspaceAction.java
@@ -10,23 +10,29 @@
  *******************************************************************************/
 package org.eclipse.team.internal.ccvs.ui.actions;
 
+import java.io.File;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.team.core.TeamException;
 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
 import org.eclipse.team.internal.ccvs.core.client.Checkout;
 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
+import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
 import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.team.internal.ui.IPromptCondition;
 import org.eclipse.team.internal.ui.PromptingDialog;
 import org.eclipse.ui.actions.WorkspaceModifyOperation;
 
@@ -35,7 +41,7 @@
  * -Works only for remote folders
  * -Does not prompt for project name; uses folder name instead
  */
-public class AddToWorkspaceAction extends CheckoutAction {
+public class AddToWorkspaceAction extends CVSAction {
 	/**
 	 * Returns the selected remote folders. 
 	 * Remove any module aliases as they may cause problems on checkout this way
@@ -120,5 +126,66 @@
 	protected String getErrorTitle() {
 		return Policy.bind("AddToWorkspaceAction.checkoutFailed"); //$NON-NLS-1$
 	}
+	
+	/*
+	 * Prompt the user to overwrite any projects that overlap with the module expansions.
+	 * 
+	 * This is an all or nothing prompt. If the user says no to one project overwrite
+	 * then the whole operation must be aborted. This is because there is no easy way to
+	 * map the module expansions back to their remote modules.
+	 */
+	private boolean promptForOverwrite(String[] expansions) throws InterruptedException {
 
+		// If the target project exists, prompt the user for overwrite
+		Set targetProjects = new HashSet();
+		for (int i = 0; i < expansions.length; i++) {
+			String string = expansions[i];
+			IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(string).segment(0));
+			targetProjects.add(project);
+		}
+		IResource[] projects = (IResource[]) targetProjects.toArray(new IResource[targetProjects.size()]);
+		PromptingDialog prompt = new PromptingDialog(getShell(), projects, 
+													  getOverwriteLocalAndFileSystemPrompt(), 
+													  Policy.bind("ReplaceWithAction.confirmOverwrite"),
+													  true /* all or nothing*/);//$NON-NLS-1$
+		return (prompt.promptForMultiple().length == projects.length);
+	}
+
+	protected static String getTaskName(ICVSRemoteFolder[] remoteFolders) {
+		if (remoteFolders.length == 1) {
+			ICVSRemoteFolder folder = remoteFolders[0];
+			String label = folder.getRepositoryRelativePath();
+			if (label.equals(FolderSyncInfo.VIRTUAL_DIRECTORY)) {
+				label = folder.getName();
+			}
+			return Policy.bind("AddToWorkspace.taskName1", label);  //$NON-NLS-1$
+		}
+		else {
+			return Policy.bind("AddToWorkspace.taskNameN", new Integer(remoteFolders.length).toString());  //$NON-NLS-1$
+		}
+	}
+
+	protected IPromptCondition getOverwriteLocalAndFileSystemPrompt() {
+		return new IPromptCondition() {
+			// prompt if resource in workspace exists or exists in local file system
+			public boolean needsPrompt(IResource resource) {
+				File localLocation  = getFileLocation(resource);
+				if(resource.exists() || localLocation.exists()) {
+					return true;
+				}
+				return false;
+			}
+			public String promptMessage(IResource resource) {
+				File localLocation  = getFileLocation(resource);
+				if(resource.exists()) {
+					return Policy.bind("AddToWorkspaceAction.thisResourceExists", resource.getName());//$NON-NLS-1$
+				} else {
+					return Policy.bind("AddToWorkspaceAction.thisExternalFileExists", resource.getName());//$NON-NLS-1$
+				}
+			}
+			private File getFileLocation(IResource resource) {
+				return new File(resource.getParent().getLocation().toFile(), resource.getName());
+			}
+		};
+	}
 }
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAction.java
index 83053e3..f93999e 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAction.java
@@ -10,32 +10,14 @@
  *******************************************************************************/
 package org.eclipse.team.internal.ccvs.ui.actions;
 
-import java.io.File;
 import java.lang.reflect.InvocationTargetException;
-import java.util.HashSet;
-import java.util.Set;
 
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.team.core.TeamException;
 import org.eclipse.team.internal.ccvs.core.CVSException;
 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
-import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
-import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
-import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
-import org.eclipse.team.internal.ccvs.ui.Policy;
-import org.eclipse.team.internal.ccvs.ui.operations.CVSOperation;
 import org.eclipse.team.internal.ccvs.ui.operations.CheckoutMultipleProjectsOperation;
-import org.eclipse.team.internal.ui.IPromptCondition;
-import org.eclipse.team.internal.ui.PromptingDialog;
 
 /**
  * Checkout a remote module into the workspace ensuring that the user is prompted for
@@ -54,114 +36,21 @@
 			throw new InvocationTargetException(e);
 		}
 	}
-
-	/*
-	 * Get the module expansions for the selected remote modules.
-	 */
-	private String[] getExpansions(ICVSRemoteFolder[] remoteFolders, IProgressMonitor monitor) throws CVSException {
-		return CVSWorkspaceRoot.getExpansions(remoteFolders, monitor);
-	}
-	
-	/*
-	 * Ensure that the expansions are valid and non-overlapping
-	 */
-	private boolean checkValidExpansions(String[] expansions) throws CVSException {
-		if (expansions == null) return false;
-		// Ensure that the expansions are unique
-		Set unique = new HashSet();
-		for (int i = 0; i < expansions.length; i++) {
-			String expansion = expansions[i];
-			if (unique.contains(expansion)) {
-				throw new CVSException(new Status(IStatus.ERROR, CVSUIPlugin.ID, 0, Policy.bind("CheckoutAction.overlappingModuleExpansions", expansion), null)); //$NON-NLS-1$
-			}
-			unique.add(expansion);
-		}
-		return true;
-	}
-	
-	/*
-	 * Prompt the user to overwrite any projects that overlap with the module expansions.
-	 * 
-	 * This is an all or nothing prompt. If the user says no to one project overwrite
-	 * then the whole operation must be aborted. This is because there is no easy way to
-	 * map the module expansions back to their remote modules.
-	 */
-	private boolean promptForOverwrite(String[] expansions) throws InterruptedException {
-
-		// If the target project exists, prompt the user for overwrite
-		Set targetProjects = new HashSet();
-		for (int i = 0; i < expansions.length; i++) {
-			String string = expansions[i];
-			IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(string).segment(0));
-			targetProjects.add(project);
-		}
-		IResource[] projects = (IResource[]) targetProjects.toArray(new IResource[targetProjects.size()]);
-		PromptingDialog prompt = new PromptingDialog(getShell(), projects, 
-													  getOverwriteLocalAndFileSystemPrompt(), 
-													  Policy.bind("ReplaceWithAction.confirmOverwrite"),
-													  true /* all or nothing*/);//$NON-NLS-1$
-		return (prompt.promptForMultiple().length == projects.length);
-	}
 	
 	/**
-	 * @see TeamAction#isEnabled()
-	 */
-	protected boolean isEnabled() throws TeamException {
-		ICVSRemoteFolder[] folders = getSelectedRemoteFolders();
-		if (folders.length == 0) return false;
-		// only enabled when all folders are in the same repository
-		ICVSRepositoryLocation location = folders[0].getRepository();
-		for (int i = 1; i < folders.length; i++) {
-			ICVSRemoteFolder folder = folders[i];
-			if (!folder.getRepository().equals(location)) {
-				return false;
-			}
-		}
-		return true;
-	}
-
-	protected static String getTaskName(ICVSRemoteFolder[] remoteFolders) {
-		if (remoteFolders.length == 1) {
-			ICVSRemoteFolder folder = remoteFolders[0];
-			String label = folder.getRepositoryRelativePath();
-			if (label.equals(FolderSyncInfo.VIRTUAL_DIRECTORY)) {
-				label = folder.getName();
-			}
-			return Policy.bind("AddToWorkspace.taskName1", label);  //$NON-NLS-1$
-		}
-		else {
-			return Policy.bind("AddToWorkspace.taskNameN", new Integer(remoteFolders.length).toString());  //$NON-NLS-1$
-		}
-	}
-	
-	protected IPromptCondition getOverwriteLocalAndFileSystemPrompt() {
-		return new IPromptCondition() {
-			// prompt if resource in workspace exists or exists in local file system
-			public boolean needsPrompt(IResource resource) {
-				File localLocation  = getFileLocation(resource);
-				if(resource.exists() || localLocation.exists()) {
-					return true;
-				}
-				return false;
-			}
-			public String promptMessage(IResource resource) {
-				File localLocation  = getFileLocation(resource);
-				if(resource.exists()) {
-					return Policy.bind("AddToWorkspaceAction.thisResourceExists", resource.getName());//$NON-NLS-1$
-				} else {
-					return Policy.bind("AddToWorkspaceAction.thisExternalFileExists", resource.getName());//$NON-NLS-1$
-				}
-			}
-			private File getFileLocation(IResource resource) {
-				return new File(resource.getParent().getLocation().toFile(), resource.getName());
-			}
-		};
-	}
-	
-	/**
-	 * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
-	 */
-	protected String getErrorTitle() {
-		return Policy.bind("AddToWorkspaceAction.checkoutFailed"); //$NON-NLS-1$
-	}
+	* @see TeamAction#isEnabled()
+	*/
+   protected boolean isEnabled() throws TeamException {
+	   ICVSRemoteFolder[] folders = getSelectedRemoteFolders();
+	   if (folders.length == 0) return false;
+	   // only enabled when all folders are in the same repository
+	   ICVSRepositoryLocation location = folders[0].getRepository();
+	   for (int i = 1; i < folders.length; i++) {
+		   ICVSRemoteFolder folder = folders[i];
+		   if (!folder.getRepository().equals(location)) {
+			   return false;
+		   }
+	   }
+	   return true;
+   }
 }
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CheckoutMultipleProjectsOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CheckoutMultipleProjectsOperation.java
index 33b0936..3cab1de 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CheckoutMultipleProjectsOperation.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CheckoutMultipleProjectsOperation.java
@@ -22,9 +22,12 @@
  * with the same name).
  */
 public class CheckoutMultipleProjectsOperation extends CheckoutProjectOperation {
+
+	boolean hasTargetLocation;
 	
 	public CheckoutMultipleProjectsOperation(Shell shell, ICVSRemoteFolder[] remoteFolders, String targetLocation) {
 		super(shell, remoteFolders, targetLocation);
+		hasTargetLocation = targetLocation != null;
 		setInvolvesMultipleResources(remoteFolders.length > 1);
 	}
 	
@@ -44,4 +47,12 @@
 		ICVSRemoteFolder[] remoteFolders = getRemoteFolders();
 		return Policy.bind("CheckoutMultipleProjectsOperation.taskName", new Integer(remoteFolders.length).toString());  //$NON-NLS-1$
 	}
+	
+	/* (non-Javadoc)
+	 * @see org.eclipse.team.internal.ccvs.ui.operations.CheckoutProjectOperation#getTargetProjects(org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder[])
+	 */
+	protected IProject[] getTargetProjects(ICVSRemoteFolder[] folders) {
+		return null;
+	}
+	
 }
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CheckoutProjectOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CheckoutProjectOperation.java
index b351a47..05703b7 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CheckoutProjectOperation.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CheckoutProjectOperation.java
@@ -183,8 +183,14 @@
 			session.open(Policy.subMonitorFor(pm, 50));
 			
 			// Determine the local target projects (either the project provider or the module expansions) 
-			IProject[] targetProjects = prepareProjects(session, project,moduleName, Policy.subMonitorFor(pm, 50));
+			IProject[] targetProjects = prepareProjects(session, project, moduleName, Policy.subMonitorFor(pm, 50));
 			if (targetProjects == null) return;
+			
+			// Determine if the target project is the same name as the remote folder
+			// in which case we'll use -d to flatten the directory structure
+			if (targetProjects.length == 1 && targetProjects[0].getName().equals(resource.getName())) {
+				project = targetProjects[0];
+			}
 		
 			// Build the local options
 			List localOptions = new ArrayList();
@@ -229,6 +235,9 @@
 	 * Prepare the workspace to receive the project(s). If project is not null, then
 	 * if will be the only target project of the checkout. Otherwise, the remote folder
 	 * could expand to multiple projects.
+	 * 
+	 * If the remote resource is a folder which is not a root folder (i.e. a/b/c),
+	 * then the target project will be the last segment (i.e. c).
 	 */
 	private IProject[] prepareProjects(Session session, IProject project, String moduleName, IProgressMonitor pm) throws CVSException {
 			
@@ -245,8 +254,14 @@
 			
 			// Convert the module expansions to local projects
 			String[] expansions = session.getModuleExpansions();
-			for (int j = 0; j < expansions.length; j++) {
-				targetProjectSet.add(ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(expansions[j]).segment(0)));
+			if (expansions.length == 1 && expansions[0].equals(moduleName)) {
+				// For a remote folder, use the last segment as the project to be created
+				String lastSegment = new Path(expansions[0]).lastSegment();
+				targetProjectSet.add(ResourcesPlugin.getWorkspace().getRoot().getProject(lastSegment));
+			} else {
+				for (int j = 0; j < expansions.length; j++) {
+					targetProjectSet.add(ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(expansions[j]).segment(0)));
+				}
 			}
 			
 		} else {