1 12 package org.eclipse.team.internal.ccvs.ui.wizards; 13 14 import org.eclipse.core.resources.*; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.Path; 17 import org.eclipse.jface.dialogs.Dialog; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.window.Window; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.events.*; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.widgets.*; 26 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder; 27 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 28 import org.eclipse.team.internal.ccvs.ui.IHelpContextIds; 29 import org.eclipse.team.internal.ui.wizards.WorkingSetsDialog; 30 import org.eclipse.ui.PlatformUI; 31 32 38 public class CheckoutAsMainPage extends CVSWizardPage { 39 40 private String newProjectName; 41 private boolean allowProjectConfiguration; 42 private Button intoProjectButton; 43 private Button simpleProjectButton; 44 private Button configuredProjectButton; 45 private Text projectNameField; 46 private ICVSRemoteFolder[] folders; 47 48 private Button recurseCheck; 49 private boolean recurse = true; 50 51 private Button addToWorkingSet; 52 private Button browseButton; 53 Text workingSetField; 54 private boolean haveBrowsed; 55 56 public static final String NAME = "CheckoutAsMainPage"; 58 64 public CheckoutAsMainPage(ImageDescriptor titleImage, ICVSRemoteFolder[] folders, boolean allowProjectConfiguration) { 65 super(NAME, CVSUIMessages.CheckoutAsMainPage_title, titleImage, CVSUIMessages.CheckoutAsMainPage_description); this.folders = folders; 67 this.allowProjectConfiguration = allowProjectConfiguration; 68 } 69 70 73 public void createControl(Composite parent) { 74 75 Composite composite = createComposite(parent, 1, false); 76 setControl(composite); 77 78 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.CHECKOUT_CONFIGURATION_PAGE); 79 80 if (isSingleFolder()) { 81 createSingleFolderArea(composite); 82 } else { 83 createMultipleFoldersArea(composite); 84 } 85 86 updateEnablements(); 87 Dialog.applyDialogFont(parent); 88 } 89 90 93 private boolean isSingleFolder() { 94 return folders.length == 1; 95 } 96 97 100 private String getFolderName() { 101 String name = getPreferredFolderName(folders[0]); 102 if (name .equals(".")) { name = new Path(null, folders[0].getRepository().getRootDirectory()).lastSegment(); 104 } 105 return name; 106 } 107 108 111 private void createSingleFolderArea(Composite composite) { 112 createLabel(composite, NLS.bind(CVSUIMessages.CheckoutAsMainPage_singleFolder, new String [] { getFolderName() })); 113 configuredProjectButton = createRadioButton(composite, CVSUIMessages.CheckoutAsMainPage_asConfiguredProject, 1); 114 if (!allowProjectConfiguration) { 115 configuredProjectButton.setEnabled(false); 116 Label configuredLabel = createWrappingLabel(composite, CVSUIMessages.CheckoutAsMainPage_10, 5); 117 configuredLabel.setEnabled(false); 118 } 119 createCheckoutAsProjectRadioArea(composite); 120 createCheckoutIntoRadioArea(composite); 121 if (allowProjectConfiguration) { 122 configuredProjectButton.setSelection(true); 123 } else { 124 simpleProjectButton.setSelection(true); 125 } 126 127 new Label(composite, SWT.NONE); 128 129 recurseCheck = createCheckBox(composite, CVSUIMessages.CheckoutAsProjectSelectionPage_recurse); 131 recurseCheck.addListener(SWT.Selection, new Listener() { 132 public void handleEvent(Event event) { 133 recurse = recurseCheck.getSelection(); 134 } 135 }); 136 recurseCheck.setSelection(recurse); 137 138 addWorkingSetSection(composite, CVSUIMessages.CheckoutAsMainPage_WorkingSetSingle); 139 } 140 141 144 private void createMultipleFoldersArea(Composite composite) { 145 createLabel(composite, NLS.bind(CVSUIMessages.CheckoutAsMainPage_multipleFolders, new String [] { new Integer (folders.length).toString() })); 146 createCheckoutAsProjectRadioArea(composite); 147 createCheckoutIntoRadioArea(composite); 148 simpleProjectButton.setSelection(true); 149 addWorkingSetSection(composite, CVSUIMessages.CheckoutAsMainPage_WorkingSetMultiple); 150 } 151 152 155 private void createCheckoutAsProjectRadioArea(Composite composite) { 156 if (isSingleFolder()) { 157 simpleProjectButton = createRadioButton(composite, CVSUIMessages.CheckoutAsMainPage_asSimpleProject, 1); 158 createProjectNameGroup(composite); 159 } else { 160 simpleProjectButton = createRadioButton(composite, CVSUIMessages.CheckoutAsMainPage_asProjects, 1); 161 } 162 } 163 164 167 private void createCheckoutIntoRadioArea(Composite composite) { 168 intoProjectButton = createRadioButton(composite, CVSUIMessages.CheckoutAsMainPage_intoProject, 1); 169 } 170 171 176 private void createProjectNameGroup(Composite parent) { 177 Composite projectGroup = new Composite(parent,SWT.NONE); 179 GridLayout layout = new GridLayout(); 180 layout.numColumns = 2; 181 projectGroup.setLayout(layout); 182 projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 183 184 Label projectLabel = new Label(projectGroup,SWT.NONE); 186 projectLabel.setText(CVSUIMessages.CheckoutAsMainPage_projectNameLabel); 187 188 projectNameField = new Text(projectGroup, SWT.BORDER); 190 GridData data = new GridData(GridData.FILL_HORIZONTAL); 191 projectNameField.setLayoutData(data); 192 193 newProjectName = getFolderName(); 196 projectNameField.setText(newProjectName); 197 projectNameField.selectAll(); 198 199 projectNameField.addModifyListener(new ModifyListener() { 201 public void modifyText(ModifyEvent e) { 202 updateEnablements(); 203 } 204 }); 205 } 206 207 211 void updateEnablements() { 212 213 if (projectNameField != null) { 214 projectNameField.setEnabled(simpleProjectButton.getSelection()); 215 if (projectNameField.isEnabled()) { 216 newProjectName = this.projectNameField.getText(); 217 IWorkspace workspace = ResourcesPlugin.getWorkspace(); 218 IStatus nameStatus = workspace.validateName(newProjectName, IResource.PROJECT); 219 if (!nameStatus.isOK()) { 220 setErrorMessage(nameStatus.getMessage()); 221 setPageComplete(false); 222 return; 223 } 224 } 225 } 226 227 workingSetField.setEnabled(addToWorkingSet.getSelection()); 228 browseButton.setEnabled(addToWorkingSet.getSelection()); 229 if (addToWorkingSet.getSelection() && !haveBrowsed){ 232 setPageComplete(false); 233 return; 234 } 235 236 if (!validateWorkingSetName()){ 237 setPageComplete(false); 238 return; 239 } 240 241 242 setErrorMessage(null); 243 setPageComplete(true); 244 } 245 246 public String getProjectName() { 247 if (isSingleFolder() && simpleProjectButton.getSelection()) return newProjectName; 248 return null; 249 } 250 251 public boolean isPerformConfigure() { 252 if (configuredProjectButton == null) return false; 253 return configuredProjectButton.getSelection(); 254 } 255 256 public boolean isPerformCheckoutInto() { 257 return intoProjectButton.getSelection(); 258 } 259 260 public boolean isPerformCheckoutAs() { 261 return simpleProjectButton.getSelection(); 262 } 263 266 protected Button createRadioButton(Composite parent, String label, int span) { 267 Button radio = super.createRadioButton(parent, label, span); 268 radio.addSelectionListener(new SelectionAdapter() { 269 public void widgetSelected(SelectionEvent e) { 270 updateEnablements(); 271 } 272 }); 273 return radio; 274 } 275 276 280 public boolean isRecurse() { 281 return recurse; 282 } 283 284 288 public String getWorkingSetName(){ 289 return workingSetField.getText(); 290 } 291 292 296 public boolean shouldAddToWorkingSet(){ 297 return addToWorkingSet.getSelection(); 298 } 299 300 private void addWorkingSetSection(Composite composite, String label) { 301 302 addToWorkingSet = createCheckBox(composite, label); 303 addToWorkingSet.setSelection(false); 304 addToWorkingSet.addSelectionListener(new SelectionAdapter() { 305 public void widgetSelected(SelectionEvent e) { 306 updateEnablements(); 307 } 308 }); 309 310 Composite inner = new Composite(composite, SWT.NULL); 311 inner.setLayoutData(new GridData(GridData.FILL_BOTH)); 312 GridLayout layout = new GridLayout(); 313 layout.numColumns = 2; 314 layout.marginHeight = 0; 315 layout.marginWidth = 0; 316 inner.setLayout(layout); 317 318 workingSetField = createTextField(inner); 319 workingSetField.setEditable(false); 320 browseButton = new Button(inner, SWT.PUSH); 321 browseButton.setText(CVSUIMessages.CheckoutAsMainPage_Browse); 322 haveBrowsed = false; 324 browseButton.addSelectionListener(new SelectionAdapter() { 325 public void widgetSelected(SelectionEvent e) { 326 final WorkingSetsDialog dialog = new WorkingSetsDialog(getShell()); 328 haveBrowsed = true; 329 if (dialog.open() == Window.OK) 330 workingSetField.setText(dialog.getSelectedWorkingSet()); 331 332 updateEnablements(); 333 } 334 }); 335 updateEnablements(); 336 337 } 338 339 private boolean validateWorkingSetName() { 340 if (addToWorkingSet.getSelection()) { 341 String workingSetName = workingSetField.getText(); 342 if (workingSetName.length() == 0) { 343 setMessage(CVSUIMessages.CheckoutAsMainPage_EmptyWorkingSetErrorMessage, ERROR); 344 return false; 345 } 346 } 347 setMessage(null); 348 return true; 349 } 350 351 352 353 } 354 | Popular Tags |