1 12 package org.eclipse.team.internal.ccvs.ui.wizards; 13 14 import java.lang.reflect.InvocationTargetException ; 15 16 import org.eclipse.core.resources.*; 17 import org.eclipse.jface.dialogs.IDialogSettings; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.wizard.IWizardPage; 20 import org.eclipse.jface.wizard.Wizard; 21 import org.eclipse.team.internal.ccvs.core.*; 22 import org.eclipse.team.internal.ccvs.ui.*; 23 import org.eclipse.team.internal.ccvs.ui.operations.*; 24 import org.eclipse.team.internal.ccvs.ui.tags.*; 25 import org.eclipse.ui.IWorkbenchPart; 26 import org.eclipse.ui.PlatformUI; 27 import org.eclipse.ui.actions.NewProjectAction; 28 29 35 public class CheckoutAsWizard extends Wizard { 36 37 private ICVSRemoteFolder[] remoteFolders; 38 private boolean allowProjectConfiguration; 39 40 private CheckoutAsMainPage mainPage; 41 private CheckoutAsProjectSelectionPage projectSelectionPage; 42 private CheckoutAsLocationSelectionPage locationSelectionPage; 43 private TagSelectionWizardPage tagSelectionPage; 44 private IWorkbenchPart part; 45 46 class NewProjectListener implements IResourceChangeListener { 47 private IProject newProject = null; 48 51 public void resourceChanged(IResourceChangeEvent event) { 52 IResourceDelta root = event.getDelta(); 53 IResourceDelta[] projectDeltas = root.getAffectedChildren(); 54 for (int i = 0; i < projectDeltas.length; i++) { 55 IResourceDelta delta = projectDeltas[i]; 56 IResource resource = delta.getResource(); 57 if (delta.getKind() == IResourceDelta.ADDED) { 58 newProject = (IProject)resource; 59 } 60 } 61 } 62 66 public IProject getNewProject() { 67 return newProject; 68 } 69 } 70 71 74 public static IDialogSettings getCheckoutAsDialogSettings() { 75 IDialogSettings workbenchSettings = CVSUIPlugin.getPlugin().getDialogSettings(); 76 IDialogSettings section = workbenchSettings.getSection("CheckoutAsWizard"); if (section == null) { 78 section = workbenchSettings.addNewSection("CheckoutAsWizard"); } 80 return section; 81 } 82 83 public CheckoutAsWizard(IWorkbenchPart part, ICVSRemoteFolder[] remoteFolders, boolean allowProjectConfiguration) { 84 this.part = part; 85 this.remoteFolders = remoteFolders; 86 setDialogSettings(getCheckoutAsDialogSettings()); 87 setWindowTitle(CVSUIMessages.CheckoutAsWizard_title); 88 this.allowProjectConfiguration = allowProjectConfiguration; 89 } 90 91 94 public void addPages() { 95 setNeedsProgressMonitor(true); 96 ImageDescriptor substImage = CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_CHECKOUT); 97 98 mainPage = new CheckoutAsMainPage(substImage, remoteFolders, allowProjectConfiguration); 99 addPage(mainPage); 100 101 projectSelectionPage = new CheckoutAsProjectSelectionPage(substImage, remoteFolders); 102 addPage(projectSelectionPage); 103 104 locationSelectionPage = new CheckoutAsLocationSelectionPage(substImage, remoteFolders); 105 addPage(locationSelectionPage); 106 107 tagSelectionPage = new TagSelectionWizardPage("tagPage", CVSUIMessages.CheckoutAsWizard_3, substImage, CVSUIMessages.CheckoutAsWizard_4, TagSource.create(remoteFolders), TagSelectionArea.INCLUDE_HEAD_TAG | 109 TagSelectionArea.INCLUDE_BRANCHES | 110 TagSelectionArea.INCLUDE_VERSIONS | 111 TagSelectionArea.INCLUDE_DATES 112 ); 113 if (remoteFolders.length > 0) { 114 try { 115 CVSTag selectedTag = remoteFolders[0].getFolderSyncInfo().getTag(); 116 tagSelectionPage.setSelection(selectedTag); 117 } catch (CVSException e) { 118 CVSUIPlugin.log(e); 119 } 120 } 121 tagSelectionPage.setHelpContxtId(IHelpContextIds.CHECKOUT_TAG_SELETION_PAGE); 122 addPage(tagSelectionPage); 123 } 124 125 128 public boolean performFinish() { 129 try { 130 if (mainPage.isPerformConfigure()) { 131 return performConfigureAndCheckout(); 132 } else if (mainPage.isPerformCheckoutAs()) { 133 if (isSingleFolder()) { 134 return performSingleCheckoutAs(); 135 } else { 136 return performMultipleCheckoutAs(); 137 } 138 } else if (mainPage.isPerformCheckoutInto()) { 139 return performCheckoutInto(); 140 } 141 } catch (InvocationTargetException e) { 142 handle(e); 143 } catch (InterruptedException e) { 145 } 147 return false; 148 } 149 150 153 private boolean isSingleFolder() { 154 return remoteFolders.length == 1; 155 } 156 157 160 public boolean canFinish() { 161 return (mainPage.isPageComplete() 162 && (mainPage.isPerformConfigure() 163 || (mainPage.isPerformCheckoutInto() && projectSelectionPage.isPageComplete()) 164 || (mainPage.isPerformCheckoutAs() && locationSelectionPage.isPageComplete()))); 165 } 166 167 170 public IWizardPage getNextPage(IWizardPage page) { 171 if (page == mainPage) { 172 if (mainPage.isPerformConfigure()) return tagSelectionPage; 173 if (mainPage.isPerformCheckoutInto()) return projectSelectionPage; 174 if (mainPage.isPerformCheckoutAs()) { 175 if (isSingleFolder()) { 176 locationSelectionPage.setProjectName(mainPage.getProjectName()); 177 } else { 178 locationSelectionPage.setProject(null); 179 } 180 return locationSelectionPage; 181 } 182 } 183 if (page != tagSelectionPage) { 185 return tagSelectionPage; 186 } 187 return null; 188 } 189 190 private void handle(Throwable e) { 191 CVSUIPlugin.openError(getShell(), CVSUIMessages.CheckoutAsWizard_error, null, e); 192 } 193 194 198 private boolean performConfigureAndCheckout() throws InvocationTargetException , InterruptedException { 199 IProject newProject = getNewProject(); 200 if (newProject == null) return false; 201 ICVSRemoteFolder folder = getRemoteFolder(); 203 new CheckoutSingleProjectOperation(part, folder, newProject, null, true).run(); 204 return true; 205 } 206 207 210 private ICVSRemoteFolder getRemoteFolder() { 211 ICVSRemoteFolder folder = remoteFolders[0]; 212 CVSTag selectedTag = getSelectedTag(); 213 if (selectedTag != null) { 214 folder = (ICVSRemoteFolder)folder.forTag(selectedTag); 215 } 216 return folder; 217 } 218 219 222 private ICVSRemoteFolder[] getRemoteFolders() { 223 ICVSRemoteFolder[] folders = (ICVSRemoteFolder[]) remoteFolders.clone(); 224 CVSTag selectedTag = getSelectedTag(); 225 if(selectedTag != null){ 227 for (int i = 0; i < remoteFolders.length; i++) { 228 folders[i] = (ICVSRemoteFolder)folders[i].forTag(getSelectedTag()); 229 } 230 } 231 return folders; 232 } 233 234 238 private ICVSRemoteFolder[] getRemoteFoldersWithProjectDescriptions() throws InvocationTargetException , InterruptedException { 239 ICVSRemoteFolder[] folders = getRemoteFolders(); 240 if (CVSUIPlugin.getPlugin().isUseProjectNameOnCheckout()) { 241 folders = ProjectMetaFileOperation.updateFoldersWithProjectName(part, folders); 242 } 243 return folders; 244 } 245 246 private CVSTag getSelectedTag() { 247 return tagSelectionPage.getSelectedTag(); 248 } 249 250 private boolean performSingleCheckoutAs() throws InvocationTargetException , InterruptedException { 251 IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(mainPage.getProjectName()); 252 String targetLocation = locationSelectionPage.getTargetLocation(); 253 ICVSRemoteFolder folder = getRemoteFolder(); 255 final boolean recurse = mainPage.isRecurse(); 256 if (mainPage.shouldAddToWorkingSet()){ 257 new CheckoutSingleProjectOperation(part, folder, newProject, targetLocation, false, mainPage.getWorkingSetName()) { 258 protected boolean isRecursive() { 259 return recurse; 260 } 261 }.run(); 262 } else { 263 new CheckoutSingleProjectOperation(part, folder, newProject, targetLocation, false) { 264 protected boolean isRecursive() { 265 return recurse; 266 } 267 }.run(); 268 } 269 return true; 270 } 271 272 276 private boolean performMultipleCheckoutAs() throws InvocationTargetException , InterruptedException { 277 String targetLocation = locationSelectionPage.getTargetLocation(); 278 if (mainPage.shouldAddToWorkingSet()){ 279 new CheckoutMultipleProjectsOperation(part, getRemoteFoldersWithProjectDescriptions(), targetLocation, mainPage.getWorkingSetName()).run(); 281 } else { 282 new CheckoutMultipleProjectsOperation(part, getRemoteFoldersWithProjectDescriptions(), targetLocation).run(); 284 } 285 return true; 286 } 287 288 private boolean performCheckoutInto() throws InvocationTargetException , InterruptedException { 289 CheckoutIntoOperation operation; 290 boolean recursive = mainPage.isRecurse(); 291 if (isSingleFolder()) { 292 ICVSRemoteFolder folder = getRemoteFolder(); 293 operation = new CheckoutIntoOperation(part, folder, projectSelectionPage.getLocalFolder(), recursive); 294 } else { 295 operation = new CheckoutIntoOperation(part, getRemoteFolders(), projectSelectionPage.getParentFolder(), recursive); 296 } 297 operation.run(); 299 return true; 300 } 301 302 306 private IProject getNewProject() { 307 NewProjectListener listener = new NewProjectListener(); 308 ResourcesPlugin.getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE); 309 (new NewProjectAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow())).run(); 310 ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener); 311 IProject project = listener.getNewProject(); 312 return project; 313 } 314 315 } 316 | Popular Tags |