diff options
author | Michael Valenta | 2003-06-11 21:51:55 +0000 |
---|---|---|
committer | Michael Valenta | 2003-06-11 21:51:55 +0000 |
commit | be7cd10097f3576f4bec3c0de2aa174790c421c5 (patch) | |
tree | 1b7f3bc1d34880f81ca36ec54b70d05e41983c12 | |
parent | 4930d0459e701fcb9f7c185905135f9fa1b7d422 (diff) | |
download | eclipse.platform.team-MV_CVSOperation_Refactor_Branch.tar.gz eclipse.platform.team-MV_CVSOperation_Refactor_Branch.tar.xz eclipse.platform.team-MV_CVSOperation_Refactor_Branch.zip |
*** empty log message ***MV_CVSOperation_Refactor_Branch
4 files changed, 112 insertions, 130 deletions
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 139535800..39ca590bf 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 @@ import org.eclipse.ui.actions.WorkspaceModifyOperation; * -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 @@ public class AddToWorkspaceAction extends CheckoutAction { 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 83053e331..f93999e6e 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 @@ public class CheckoutAction extends CVSAction { 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 33b09364c..3cab1de2f 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 @@ import org.eclipse.team.internal.ccvs.ui.Policy; * 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 @@ public class CheckoutMultipleProjectsOperation extends CheckoutProjectOperation 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 b351a47c4..05703b74f 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 @@ public abstract class CheckoutProjectOperation extends CheckoutOperation { 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 @@ public abstract class CheckoutProjectOperation extends CheckoutOperation { * 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 @@ public abstract class CheckoutProjectOperation extends CheckoutOperation { // 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 { |