1 12 package org.eclipse.team.internal.ccvs.ui.wizards; 13 14 import java.lang.reflect.InvocationTargetException ; 15 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.jface.operation.IRunnableWithProgress; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.viewers.IStructuredSelection; 20 import org.eclipse.jface.wizard.IWizardPage; 21 import org.eclipse.jface.wizard.Wizard; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.team.core.TeamException; 24 import org.eclipse.team.internal.ccvs.core.*; 25 import org.eclipse.team.internal.ccvs.core.util.KnownRepositories; 26 import org.eclipse.team.internal.ccvs.ui.*; 27 import org.eclipse.team.internal.ccvs.ui.operations.CheckoutMultipleProjectsOperation; 28 import org.eclipse.team.internal.ccvs.ui.operations.ProjectMetaFileOperation; 29 import org.eclipse.ui.*; 30 31 34 public class CheckoutWizard extends Wizard implements ICVSWizard, INewWizard { 35 36 private RepositorySelectionPage locationPage; 37 private ConfigurationWizardMainPage createLocationPage; 38 private ModuleSelectionPage modulePage; 39 private CheckoutAsWizard wizard; 40 private ICVSRepositoryLocation location; 41 private boolean isNewLocation; 42 private CVSWizardPage dummyPage; 43 44 public CheckoutWizard() { 45 setWindowTitle(CVSUIMessages.CheckoutWizard_0); 46 } 47 48 51 public void addPages() { 52 setNeedsProgressMonitor(true); 53 54 ImageDescriptor substImage = getBannerImageDescriptor(); 55 56 ICVSRepositoryLocation[] locations = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownRepositoryLocations(); 57 if (locations.length > 0) { 58 locationPage = new RepositorySelectionPage("locationSelection", CVSUIMessages.CheckoutWizard_7, substImage); locationPage.setDescription(CVSUIMessages.SharingWizard_importTitleDescription); 60 locationPage.setExtendedDescription(CVSUIMessages.CheckoutWizard_8); 61 addPage(locationPage); 62 } 63 64 createLocationPage = new ConfigurationWizardMainPage("createLocationPage", CVSUIMessages.SharingWizard_enterInformation, substImage); createLocationPage.setDescription(CVSUIMessages.SharingWizard_enterInformationDescription); 66 addPage(createLocationPage); 67 createLocationPage.setDialogSettings(NewLocationWizard.getLocationDialogSettings()); 68 69 modulePage = new ModuleSelectionPage("moduleSelection", CVSUIMessages.CheckoutWizard_10, substImage); modulePage.setDescription(CVSUIMessages.CheckoutWizard_11); 71 modulePage.setHelpContxtId(IHelpContextIds.CHECKOUT_MODULE_SELECTION_PAGE); 72 modulePage.setSupportsMultiSelection(true); 73 addPage(modulePage); 74 75 dummyPage = new CVSWizardPage("dummyPage") { public void createControl(Composite parent) { 78 Composite composite = createComposite(parent, 1, false); 79 setControl(composite); 80 } 81 }; 82 addPage(dummyPage); 83 } 84 85 protected ImageDescriptor getBannerImageDescriptor() { 86 return CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_CHECKOUT); 87 } 88 89 92 public boolean canFinish() { 93 return (wizard == null && getSelectedModules().length > 0) || 94 (wizard != null && wizard.canFinish()); 95 } 96 97 100 public boolean performFinish() { 101 if (wizard != null) { 102 if (isNewLocation) { 105 KnownRepositories.getInstance().addRepository(location, true ); 106 } 107 return true; 108 } else { 109 try { 110 new CheckoutMultipleProjectsOperation(getPart(), getSelectedModules(), null) 111 .run(); 112 if (isNewLocation) { 113 KnownRepositories.getInstance().addRepository(location, true ); 114 } 115 return true; 116 } catch (InvocationTargetException e) { 117 CVSUIPlugin.openError(getShell(), null, null, e); 118 } catch (InterruptedException e) { 119 } 121 return false; 122 } 123 } 124 125 private IWorkbenchPart getPart() { 126 return null; 128 } 129 130 133 public boolean performCancel() { 134 if (location != null && isNewLocation) { 135 KnownRepositories.getInstance().disposeRepository(location); 136 location = null; 137 } 138 return wizard == null || wizard.performCancel(); 139 } 140 141 144 public IWizardPage getNextPage(IWizardPage page) { 145 return getNextPage(page, true ); 148 } 149 150 153 public IWizardPage getNextPage(IWizardPage page, boolean aboutToShow) { 154 if (page == locationPage) { 155 if (locationPage.getLocation() == null) { 156 return createLocationPage; 157 } else { 158 if (aboutToShow) { 159 try { 160 modulePage.setLocation(getLocation()); 161 } catch (TeamException e1) { 162 CVSUIPlugin.log(e1); 163 } 164 } 165 return modulePage; 166 } 167 } 168 if (page == createLocationPage) { 169 if (aboutToShow) { 170 try { 171 ICVSRepositoryLocation l = getLocation(); 172 if (l != null) { 173 modulePage.setLocation(l); 174 } 175 } catch (TeamException e1) { 176 CVSUIPlugin.log(e1); 177 } 178 } 179 return modulePage; 180 } 181 if (page == modulePage) { 182 ICVSRemoteFolder[] selectedModules = getSelectedModules(); 183 if (selectedModules.length == 0) return null; 184 for (int i = 0; i < selectedModules.length; i++) { 185 ICVSRemoteFolder folder = selectedModules[i]; 186 if (folder.isDefinedModule()) { 187 return null; 189 } 190 } 191 if (aboutToShow) { 192 try { 193 boolean hasMetafile = true; 194 if (selectedModules.length == 1) { 195 final ICVSRemoteFolder[] folders = new ICVSRemoteFolder[] {selectedModules[0]}; 197 final boolean withName = CVSUIPlugin.getPlugin().isUseProjectNameOnCheckout(); 198 199 final ICVSRemoteFolder[] folderResult = new ICVSRemoteFolder [1]; 202 final boolean[] booleanResult = new boolean[] { true }; 203 204 getContainer().run(true, true, new IRunnableWithProgress() { 205 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 206 ProjectMetaFileOperation op = new ProjectMetaFileOperation(getPart(), new ICVSRemoteFolder[] {folders[0]}, withName); 207 op.run(monitor); 208 folderResult[0] = op.getUpdatedFolders()[0]; 209 booleanResult[0] = op.metaFileExists(); 210 } 211 }); 212 hasMetafile = booleanResult[0]; 213 if (withName && hasMetafile) 214 selectedModules[0] = folderResult[0]; 215 } 216 resetSubwizard(); 217 wizard = new CheckoutAsWizard(getPart(), selectedModules, ! hasMetafile ); 218 wizard.addPages(); 219 return wizard.getStartingPage(); 220 } catch (InvocationTargetException e) { 221 CVSUIPlugin.openError(getShell(), null, null, e); 223 } catch (InterruptedException e) { 224 } 226 return null; 227 } else { 228 if (wizard == null) { 229 return dummyPage; 230 } else { 231 return wizard.getStartingPage(); 232 } 233 } 234 } 235 if (wizard != null) { 236 return wizard.getNextPage(page); 237 } 238 return null; 239 } 240 241 private ICVSRemoteFolder[] getSelectedModules() { 242 if (modulePage == null) return null; 243 return modulePage.getSelectedModules(); 244 } 245 246 249 private ICVSRepositoryLocation getLocation() throws TeamException { 250 if (locationPage != null) { 252 ICVSRepositoryLocation newLocation = locationPage.getLocation(); 253 if (newLocation != null) { 254 return recordLocation(newLocation); 255 } 256 } 257 258 final ICVSRepositoryLocation[] locations = new ICVSRepositoryLocation[] { null }; 260 final CVSException[] exception = new CVSException[] { null }; 261 getShell().getDisplay().syncExec(new Runnable () { 262 public void run() { 263 try { 264 locations[0] = createLocationPage.getLocation(); 265 } catch (CVSException e) { 266 exception[0] = e; 267 } 268 } 269 }); 270 if (exception[0] != null) { 271 throw exception[0]; 272 } 273 return recordLocation(locations[0]); 274 } 275 276 private ICVSRepositoryLocation recordLocation(ICVSRepositoryLocation newLocation) { 277 if (newLocation == null) return location; 278 if (location == null || !newLocation.equals(location)) { 279 if (location != null && isNewLocation) { 280 KnownRepositories.getInstance().disposeRepository(location); 282 } 283 location = newLocation; 284 isNewLocation = !KnownRepositories.getInstance().isKnownRepository(newLocation.getLocation(false)); 285 if (isNewLocation) { 286 location = KnownRepositories.getInstance().addRepository(location, false ); 288 } 289 } 290 return location; 291 } 292 293 296 public void init(IWorkbench workbench, IStructuredSelection selection) { 297 } 298 299 302 void resetSubwizard() { 303 if (wizard != null) { 304 wizard.dispose(); 305 wizard = null; 306 } 307 } 308 } 309 | Popular Tags |