diff options
author | Michael Valenta | 2003-01-31 19:21:48 +0000 |
---|---|---|
committer | Michael Valenta | 2003-01-31 19:21:48 +0000 |
commit | c686f9c102072d994f235db119d3fd511c49d764 (patch) | |
tree | 3ff91f75ea1561fd90b27d45fe97755dc5529ee6 | |
parent | 5eb211e13f104cefd597f074c8506ff717dd4faf (diff) | |
download | eclipse.platform.team-c686f9c102072d994f235db119d3fd511c49d764.tar.gz eclipse.platform.team-c686f9c102072d994f235db119d3fd511c49d764.tar.xz eclipse.platform.team-c686f9c102072d994f235db119d3fd511c49d764.zip |
30339: Checkout of multiple projects simultaneously needs to allow destination override
4 files changed, 605 insertions, 47 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/TagetLocationSelectionDialog.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/TagetLocationSelectionDialog.java new file mode 100644 index 000000000..af5f9c686 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/TagetLocationSelectionDialog.java @@ -0,0 +1,437 @@ +/******************************************************************************* + * Copyright (c) 2003 IBM Corporation and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v0.5 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM - Initial API and implementation + ******************************************************************************/ +package org.eclipse.team.internal.ccvs.ui; + +import java.io.File; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.resource.JFaceColors; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.SelectionDialog; + +/** + * Select the target location that will be the parent of the selected projects. + * The behavior of the dialog differs between 1 project and multiple projects. + * For one project, the location specified is the location of the project and + * the project name can be modified. For multiple projects, it is the parent + * location which is specified. + */ +public class TagetLocationSelectionDialog extends SelectionDialog { + + // widgets + private Text projectNameField; + private Text locationPathField; + private Label locationLabel; + private Label statusMessageLabel; + private Button browseButton; + + // state + private boolean useDefaults = true; + private IProject[] targetProjects; + private String newProjectName; + private String targetLocation; + + // constants + private static final int SIZING_TEXT_FIELD_WIDTH = 250; + + /** + * Constructor. + * @param parentShell + */ + public TagetLocationSelectionDialog(Shell parentShell, String title, IProject targetProject) { + this(parentShell, title, new IProject[] { targetProject }); + } + + /** + * Constructor. + * @param parentShell + */ + public TagetLocationSelectionDialog(Shell parentShell, String title, IProject[] targetProjects) { + super(parentShell); + setTitle(title); + this.targetProjects = targetProjects; + if (targetProjects.length == 1) newProjectName = targetProjects[0].getName(); + } + + /* (non-Javadoc) + * Method declared on Dialog. + */ + protected Control createDialogArea(Composite parent) { + // page group + Composite composite = (Composite) super.createDialogArea(parent); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + if (isSingleCheckout()) + createProjectNameGroup(composite); + createProjectLocationGroup(composite); + + //Add in a label for status messages if required + statusMessageLabel = new Label(composite, SWT.NONE); + statusMessageLabel.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Dialog.applyDialogFont(parent); + return composite; + } + + /** + * Creates the project name specification controls. + * + * @param parent the parent composite + */ + private void createProjectNameGroup(Composite parent) { + // project specification group + Composite projectGroup = new Composite(parent,SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + // new project label + Label projectLabel = new Label(projectGroup,SWT.NONE); + projectLabel.setText(Policy.bind("TargetLocationSelectionDialog.projectNameLabel")); + + // new project name entry field + projectNameField = new Text(projectGroup, SWT.BORDER); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = SIZING_TEXT_FIELD_WIDTH; + projectNameField.setLayoutData(data); + + // Set the initial value first before listener + // to avoid handling an event during the creation. + projectNameField.setText(getNewProjectName()); + projectNameField.selectAll(); + + createNameListener(); + + } + + /** + * Create the listener that is used to validate the entries for the receiver + */ + private void createNameListener() { + + Listener listener = new Listener() { + public void handleEvent(Event event) { + newProjectName = projectNameField.getText(); + setLocationForSelection(); + applyValidationResult(checkValid()); + } + }; + + this.projectNameField.addListener(SWT.Modify, listener); + } + + /** + * Set the location to the default location if we are set to useDefaults. + */ + private void setLocationForSelection() { + if (useDefaults) { + IPath defaultPath = null; + if (isSingleCheckout()) { + try { + defaultPath = getSingleProject().getDescription().getLocation(); + } catch (CoreException e) { + // ignore + } + if (defaultPath == null) { + defaultPath = Platform.getLocation().append(getSingleProject().getName()); + } + } else { + defaultPath = Platform.getLocation(); + } + locationPathField.setText(defaultPath.toOSString()); + targetLocation = null; + } else { + IPath location = null; + try { + location = this.targetProjects[0].getDescription().getLocation(); + } catch (CoreException e) { + // ignore the exception + } + if (location == null) { + targetLocation = null; + locationPathField.setText(""); + } else { + if (isSingleCheckout()) { + targetLocation = location.toOSString(); + } else { + targetLocation = location.removeLastSegments(1).toOSString(); + } + locationPathField.setText(targetLocation); + } + } + } + + /** + * Creates the project location specification controls. + * + * @param parent the parent composite + */ + private final void createProjectLocationGroup(Composite parent) { + + // project specification group + Composite projectGroup = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + final Button useDefaultsButton = + new Button(projectGroup, SWT.CHECK | SWT.RIGHT); + useDefaultsButton.setText(Policy.bind("TargetLocationSelectionDialog.useDefaultLabel")); //$NON-NLS-1$ + useDefaultsButton.setSelection(this.useDefaults); + GridData buttonData = new GridData(); + buttonData.horizontalSpan = 3; + useDefaultsButton.setLayoutData(buttonData); + + createUserSpecifiedProjectLocationGroup(projectGroup, !this.useDefaults); + + SelectionListener listener = new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + useDefaults = useDefaultsButton.getSelection(); + browseButton.setEnabled(!useDefaults); + locationPathField.setEnabled(!useDefaults); + locationLabel.setEnabled(!useDefaults); + setLocationForSelection(); + } + }; + useDefaultsButton.addSelectionListener(listener); + } + + /** + * Creates the project location specification controls. + * + * @return the parent of the widgets created + * @param projectGroup the parent composite + * @param enabled - sets the initial enabled state of the widgets + */ + private Composite createUserSpecifiedProjectLocationGroup(Composite projectGroup, boolean enabled) { + + // location label + locationLabel = new Label(projectGroup, SWT.NONE); + if (isSingleCheckout()) { + locationLabel.setText(Policy.bind("TargetLocationSelectionDialog.locationLabel")); + } else { + locationLabel.setText(Policy.bind("TargetLocationSelectionDialog.parentDirectoryLabel")); + } + locationLabel.setEnabled(enabled); + + // project location entry field + locationPathField = new Text(projectGroup, SWT.BORDER); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = SIZING_TEXT_FIELD_WIDTH; + locationPathField.setLayoutData(data); + locationPathField.setEnabled(enabled); + + // browse button + this.browseButton = new Button(projectGroup, SWT.PUSH); + this.browseButton.setText(Policy.bind("TargetLocationSelectionDialog.browseLabel")); + this.browseButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + handleLocationBrowseButtonPressed(); + } + }); + this.browseButton.setEnabled(enabled); + setButtonLayoutData(this.browseButton); + + // Set the initial value first before listener + // to avoid handling an event during the creation. + setLocationForSelection(); + createLocationListener(); + return projectGroup; + + } + + /** + * Open an appropriate directory browser + */ + private void handleLocationBrowseButtonPressed() { + DirectoryDialog dialog = new DirectoryDialog(locationPathField.getShell()); + if (isSingleCheckout()) { + dialog.setMessage(Policy.bind("TargetLocationSelectionDialog.messageForSingle", newProjectName)); + } else { + dialog.setMessage(Policy.bind("TargetLocationSelectionDialog.messageForMulti", new Integer(targetProjects.length).toString())); + } + + String dirName = locationPathField.getText(); + if (!dirName.equals("")) {//$NON-NLS-1$ + File path = new File(dirName); + if (path.exists()) + dialog.setFilterPath(dirName); + } + + String selectedDirectory = dialog.open(); + if (selectedDirectory != null) { + if (targetProjects.length == 1) { + locationPathField.setText(new Path(selectedDirectory).append(newProjectName).toOSString()); + } else { + locationPathField.setText(new Path(selectedDirectory).toOSString()); + } + } + targetLocation = locationPathField.getText(); + } + + /** + * Method isSingleCheckout. + * @return boolean + */ + private boolean isSingleCheckout() { + return targetProjects.length == 1; + } + + private IProject getSingleProject() { + if (newProjectName == null || newProjectName.length() == 0 || targetProjects[0].getName().equals(newProjectName)) + return targetProjects[0]; + else + return ResourcesPlugin.getWorkspace().getRoot().getProject(newProjectName); + } + + /** + * Create the listener that is used to validate the location entered by the iser + */ + private void createLocationListener() { + + Listener listener = new Listener() { + public void handleEvent(Event event) { + applyValidationResult(checkValid()); + } + }; + + this.locationPathField.addListener(SWT.Modify, listener); + } + + /** + * Check the message. If it is null then continue otherwise inform the user via the + * status value and disable the OK. + * @param message - the error message to show if it is not null. + */ + private void applyValidationResult(String errorMsg) { + + if (errorMsg == null) { + statusMessageLabel.setText("");//$NON-NLS-1$ + getOkButton().setEnabled(true); + } else { + statusMessageLabel.setForeground( + JFaceColors.getErrorText( + statusMessageLabel.getDisplay())); + statusMessageLabel.setText(errorMsg); + getOkButton().setEnabled(false); + } + } + /** + * Check whether the entries are valid. If so return null. Otherwise + * return a string that indicates the problem. + */ + private String checkValid() { + if (isSingleCheckout()) { + String valid = checkValidName(); + if (valid != null) + return valid; + } + return checkValidLocation(); + } + /** + * Check if the entry in the widget location is valid. If it is valid return null. Otherwise + * return a string that indicates the problem. + */ + private String checkValidLocation() { + + if (useDefaults) { + targetLocation = null; + return null; + } else { + targetLocation = locationPathField.getText(); + if (targetLocation.equals("")) {//$NON-NLS-1$ + return(Policy.bind("TagetLocationSelectionDialog.locationEmpty")); //$NON-NLS-1$ + } + else{ + IPath path = new Path("");//$NON-NLS-1$ + if (!path.isValidPath(targetLocation)) { + return Policy.bind("TagetLocationSelectionDialog.invalidLocation"); + } + } + + if (isSingleCheckout()) { + IStatus locationStatus = + ResourcesPlugin.getWorkspace().validateProjectLocation( + getSingleProject(), + new Path(targetLocation)); + + if (!locationStatus.isOK()) + return locationStatus.getMessage(); + } else { + for (int i = 0; i < targetProjects.length; i++) { + ResourcesPlugin.getWorkspace().validateProjectLocation( + targetProjects[i], + new Path(targetLocation).append(targetProjects[i].getName())); + } + } + + return null; + } + } + /** + * Check if the entries in the widget are valid. If they are return null otherwise + * return a string that indicates the problem. + */ + private String checkValidName() { + + newProjectName = this.projectNameField.getText(); + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IStatus nameStatus = workspace.validateName(newProjectName, IResource.PROJECT); + if (!nameStatus.isOK()) + return nameStatus.getMessage(); +// IProject newProject = workspace.getRoot().getProject(newProjectName); +// if (newProject.exists()) { +// return Policy.bind("TagetLocationSelectionDialog.alreadyExists", newProjectName); //$NON-NLS-1$ +// } + + return null; + } + + /** + * @return String + */ + public String getNewProjectName() { + return newProjectName; + } + + /** + * @return String + */ + public String getTargetLocation() { + return targetLocation; + } + +} 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 4dd5f960d..77568782d 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 @@ -57,6 +57,10 @@ public class AddToWorkspaceAction extends CheckoutAction { * @see CVSAction#execute() */ public void execute(IAction action) throws InvocationTargetException, InterruptedException { + checkoutSelectionIntoWorkspaceDirectory(); + } + + protected void checkoutSelectionIntoWorkspaceDirectory() throws InvocationTargetException, InterruptedException { run(new WorkspaceModifyOperation() { public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException { try { diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAsAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAsAction.java index bac7606b4..2f44ff475 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAsAction.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAsAction.java @@ -21,10 +21,8 @@ import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.operation.IRunnableWithProgress; @@ -33,12 +31,12 @@ import org.eclipse.team.internal.ccvs.core.CVSException; import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder; import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; import org.eclipse.team.internal.ccvs.ui.Policy; +import org.eclipse.team.internal.ccvs.ui.TagetLocationSelectionDialog; import org.eclipse.team.internal.ui.IPromptCondition; import org.eclipse.team.internal.ui.PromptingDialog; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.NewProjectAction; import org.eclipse.ui.actions.WorkspaceModifyOperation; -import org.eclipse.ui.dialogs.ProjectLocationSelectionDialog; /** * Add a remote resource to the workspace. Current implementation: @@ -50,25 +48,96 @@ public class CheckoutAsAction extends AddToWorkspaceAction { * @see IActionDelegate#run(IAction) */ public void execute(IAction action) throws InvocationTargetException, InterruptedException { - final ICVSRemoteFolder[] folders = getSelectedRemoteFolders(); - if (folders.length != 1) return; - final String remoteFolderName = folders[0].getName(); - // make a copy of the folder so that we will not effect the original folder when we refetch the members - final ICVSRemoteFolder folder = (ICVSRemoteFolder)folders[0].forTag(folders[0].getTag()); + if (folders.length == 1){ + // make a copy of the folder so that we will not effect the original folder when we refetch the members + // todo: this is a strang thing to need to do. We shold fix this. + final ICVSRemoteFolder folder = (ICVSRemoteFolder)folders[0].forTag(folders[0].getTag()); + checkoutSingleProject(folder); + } else { + checkoutMultipleProjects(folders); + } + } + + private void checkoutMultipleProjects(final ICVSRemoteFolder[] folders) throws InvocationTargetException, InterruptedException { + + // create the target project handles + IProject[] targetProjects = new IProject[folders.length]; + for (int i = 0; i < folders.length; i++) { + ICVSRemoteFolder remoteFolder = folders[i]; + targetProjects[i] = ResourcesPlugin.getWorkspace().getRoot().getProject(remoteFolder.getName()); + } + // prompt for the parent location + TagetLocationSelectionDialog dialog = new TagetLocationSelectionDialog( + getShell(), + Policy.bind("CheckoutAsAction.enterLocationTitle", new Integer(targetProjects.length).toString()), //$NON-NLS-1$ + targetProjects); + int result = dialog.open(); + if (result != Dialog.OK) return; + String targetParentLocation = dialog.getTargetLocation(); + + // if the location is null, just checkout the projects into the workspace + if (targetParentLocation == null) { + checkoutSelectionIntoWorkspaceDirectory(); + return; + } + + // create the project descriptions for each project + IProjectDescription[] descriptions = new IProjectDescription[targetProjects.length]; + for (int i = 0; i < targetProjects.length; i++) { + String projectName = targetProjects[i].getName(); + descriptions[i] = ResourcesPlugin.getWorkspace().newProjectDescription(projectName); + descriptions[i].setLocation(new Path(targetParentLocation).append(projectName)); + } + + // prompt if the projects or locations exist locally + PromptingDialog prompt = new PromptingDialog(getShell(), targetProjects, + getOverwriteLocalAndFileSystemPrompt(descriptions), Policy.bind("ReplaceWithAction.confirmOverwrite"));//$NON-NLS-1$ + IResource[] projectsToCheckout = prompt.promptForMultiple(); + if (projectsToCheckout.length== 0) return; + + // copy the selected projects to a new array + final IProject[] projects = new IProject[projectsToCheckout.length]; + for (int i = 0; i < projects.length; i++) { + projects[i] = projectsToCheckout[i].getProject(); + } + + // perform the checkout + final IProjectDescription[] newDescriptions = descriptions; + run(new WorkspaceModifyOperation() { + public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException { + try { + monitor.beginTask(null, 100); + monitor.setTaskName(Policy.bind("CheckoutAsAction.multiCheckout", new Integer(projects.length).toString())); //$NON-NLS-1$ + // create the projects + createAndOpenProjects(projects, newDescriptions, Policy.subMonitorFor(monitor, 5)); + checkoutProjects(folders, projects, Policy.subMonitorFor(monitor, 95)); + + + } catch (TeamException e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); + } + } + }, true /* cancelable */, PROGRESS_DIALOG); + } + + private void checkoutSingleProject(final ICVSRemoteFolder remoteFolder) throws InvocationTargetException, InterruptedException { // Fetch the members of the folder to see if they contain a .project file. + final String remoteFolderName = remoteFolder.getName(); final boolean[] hasProjectMetaFile = new boolean[] { false }; run(new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException { try { - folder.members(monitor); + remoteFolder.members(monitor); } catch (TeamException e) { throw new InvocationTargetException(e); } // Check for the existance of the .project file try { - folder.getFile(".project"); //$NON-NLS-1$ + remoteFolder.getFile(".project"); //$NON-NLS-1$ hasProjectMetaFile[0] = true; } catch (TeamException e) { // We couldn't retrieve the meta file so assume it doesn't exist @@ -77,7 +146,7 @@ public class CheckoutAsAction extends AddToWorkspaceAction { // If the above failed, look for the old .vcm_meta file if (! hasProjectMetaFile[0]) { try { - folder.getFile(".vcm_meta"); //$NON-NLS-1$ + remoteFolder.getFile(".vcm_meta"); //$NON-NLS-1$ hasProjectMetaFile[0] = true; } catch (TeamException e) { // We couldn't retrieve the meta file so assume it doesn't exist @@ -94,26 +163,25 @@ public class CheckoutAsAction extends AddToWorkspaceAction { // prompt for the project name and location newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(remoteFolderName); - ProjectLocationSelectionDialog dialog = new ProjectLocationSelectionDialog(getShell(), newProject); - dialog.setTitle(Policy.bind("CheckoutAsAction.enterProjectTitle", remoteFolderName)); //$NON-NLS-1$ + TagetLocationSelectionDialog dialog = new TagetLocationSelectionDialog(getShell(), Policy.bind("CheckoutAsAction.enterProjectTitle", remoteFolderName), newProject); //$NON-NLS-1$ int result = dialog.open(); if (result != Dialog.OK) return; - Object[] destinationPaths = dialog.getResult(); - if (destinationPaths == null) return; - String newName = (String) destinationPaths[0]; - IPath newLocation = new Path((String) destinationPaths[1]); + // get the name and location from the dialog + String targetLocation = dialog.getTargetLocation(); + String targetName = dialog.getNewProjectName(); // create the project description for a custom location - boolean useDefaultLocation = newLocation.equals(Platform.getLocation()); - if (!useDefaultLocation) { + if (targetLocation != null) { newDesc = ResourcesPlugin.getWorkspace().newProjectDescription(newProject.getName()); - newDesc.setLocation(newLocation); + newDesc.setLocation(new Path(targetLocation)); } // prompt if the project or location exists locally - newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(newName); + newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(targetName); PromptingDialog prompt = new PromptingDialog(getShell(), new IResource[] { newProject }, - getOverwriteLocalAndFileSystemPrompt(newDesc), Policy.bind("ReplaceWithAction.confirmOverwrite"));//$NON-NLS-1$ + getOverwriteLocalAndFileSystemPrompt( + newDesc == null ? new IProjectDescription[0] : new IProjectDescription[] {newDesc}), + Policy.bind("ReplaceWithAction.confirmOverwrite"));//$NON-NLS-1$ if (prompt.promptForMultiple().length == 0) return; } else { @@ -126,31 +194,14 @@ public class CheckoutAsAction extends AddToWorkspaceAction { run(new WorkspaceModifyOperation() { public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException { try { + monitor.beginTask(null, 100); + monitor.setTaskName(Policy.bind("CheckoutAsAction.taskname", remoteFolderName, project.getName())); //$NON-NLS-1$ + int used = 0; if (hasProjectMetaFile[0]) { - - monitor.beginTask(null, 100); - monitor.setTaskName(Policy.bind("CheckoutAsAction.taskname", remoteFolderName, project.getName())); //$NON-NLS-1$ - - // create the project - try { - if (desc == null) { - // create in default location - project.create(Policy.subMonitorFor(monitor, 3)); - } else { - // create in some other location - project.create(desc, Policy.subMonitorFor(monitor, 3)); - } - project.open(Policy.subMonitorFor(monitor, 2)); - } catch (CoreException e) { - throw CVSException.wrapException(e); - } - } else { - monitor.beginTask(null, 95); - monitor.setTaskName(Policy.bind("CheckoutAsAction.taskname", remoteFolderName, project.getName())); //$NON-NLS-1$ + used = 5; + createAndOpenProject(project, desc, Policy.subMonitorFor(monitor, used)); } - - CVSWorkspaceRoot.checkout(folders, new IProject[] { project }, Policy.subMonitorFor(monitor, 95)); - + checkoutProjects(new ICVSRemoteFolder[] { remoteFolder }, new IProject[] { project }, Policy.subMonitorFor(monitor, 100 - used)); } catch (TeamException e) { throw new InvocationTargetException(e); } finally { @@ -160,11 +211,51 @@ public class CheckoutAsAction extends AddToWorkspaceAction { }, true /* cancelable */, PROGRESS_DIALOG); } + private void createAndOpenProjects(IProject[] projects, IProjectDescription[] descriptions, IProgressMonitor monitor) throws CVSException { + monitor.beginTask(null, projects.length* 100); + for (int i = 0; i < projects.length; i++) { + IProject project = projects[i]; + IProjectDescription desc = findDescription(descriptions, project); + createAndOpenProject(project, desc, Policy.subMonitorFor(monitor, 100)); + } + monitor.done(); + } + + private void createAndOpenProject(IProject project, IProjectDescription desc, IProgressMonitor monitor) throws CVSException { + try { + monitor.beginTask(null, 5); + if (project.exists()) { + if (desc != null) { + project.move(desc, true, Policy.subMonitorFor(monitor, 3)); + } + } else { + if (desc == null) { + // create in default location + project.create(Policy.subMonitorFor(monitor, 3)); + } else { + // create in some other location + project.create(desc, Policy.subMonitorFor(monitor, 3)); + } + } + if (!project.isOpen()) { + project.open(Policy.subMonitorFor(monitor, 2)); + } + } catch (CoreException e) { + throw CVSException.wrapException(e); + } finally { + monitor.done(); + } + } + + private void checkoutProjects(ICVSRemoteFolder[] folders, IProject[] projects, IProgressMonitor monitor) throws TeamException { + CVSWorkspaceRoot.checkout(folders, projects, monitor); + } + /* * @see TeamAction#isEnabled() */ protected boolean isEnabled() throws TeamException { - return getSelectedRemoteFolders().length == 1; + return getSelectedRemoteFolders().length > 0; } /** @@ -232,12 +323,13 @@ public class CheckoutAsAction extends AddToWorkspaceAction { return Policy.bind("CheckoutAsAction.checkoutFailed"); //$NON-NLS-1$ } - protected IPromptCondition getOverwriteLocalAndFileSystemPrompt(final IProjectDescription desc) { + protected IPromptCondition getOverwriteLocalAndFileSystemPrompt(final IProjectDescription[] descriptions) { return new IPromptCondition() { // prompt if resource in workspace exists or exists in local file system public boolean needsPrompt(IResource resource) { // First, check the description location + IProjectDescription desc = findDescription(descriptions, resource); if (desc != null) { File localLocation = desc.getLocation().toFile(); return localLocation.exists(); @@ -254,6 +346,7 @@ public class CheckoutAsAction extends AddToWorkspaceAction { return false; } public String promptMessage(IResource resource) { + IProjectDescription desc = findDescription(descriptions, resource); if (desc != null) { return Policy.bind("AddToWorkspaceAction.thisExternalFileExists", desc.getLocation().toString());//$NON-NLS-1$ } else if(resource.exists()) { @@ -268,4 +361,14 @@ public class CheckoutAsAction extends AddToWorkspaceAction { } }; } + + private IProjectDescription findDescription(IProjectDescription[] descriptions, IResource resource) { + IProject project = resource.getProject(); + for (int i = 0; i < descriptions.length; i++) { + IProjectDescription description = descriptions[i]; + if (description.getName().equals(project.getName())) + return description; + } + return null; + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties index d2ef15f3c..71c99c56e 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties @@ -244,7 +244,9 @@ CVSAction.refreshMultipleQuestion={0} Would you like to refresh the projects of CheckoutAsAction.checkoutFailed=Problems encountered performing checkout CheckoutAsAction.enterProjectTitle=Check Out {0} As... +CheckoutAsAction.enterLocationTitle=Check Out {0} Projects As... CheckoutAsAction.taskname=Checking out "{0}" from CVS as "{1}" +CheckoutAsAction.multiCheckout=Checking out {0} projects from CVS CommitAction.commitFailed=Problems encountered performing commit @@ -877,3 +879,15 @@ EditorsView.computer=Computer name EditorsDialog.title=Editors EditorsDialog.question=The resource has already editors. Do you want to edit? EditorsAction.classNotInitialized={0} not initialized + +TargetLocationSelectionDialog.projectNameLabel=&Project Name: +TargetLocationSelectionDialog.useDefaultLabel=Use default &workspace location +TargetLocationSelectionDialog.locationLabel=&Location: +TargetLocationSelectionDialog.parentDirectoryLabel=&Directory: +TargetLocationSelectionDialog.browseLabel=&Browse... +TargetLocationSelectionDialog.messageForSingle=Select the parent directory for project {0}. +TargetLocationSelectionDialog.messageForMulti=Select the parent directory for the {0} projects. +TagetLocationSelectionDialog.locationEmpty=Project contents directory must be specified. +TagetLocationSelectionDialog.invalidLocation=Invalid location path. +TagetLocationSelectionDialog.alreadyExists=Project {0} already exists. + |