1 12 package org.eclipse.team.internal.ccvs.ui.wizards; 13 14 15 import java.util.ArrayList ; 16 17 import org.eclipse.core.resources.IContainer; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.jface.dialogs.IDialogConstants; 21 import org.eclipse.jface.resource.ImageDescriptor; 22 import org.eclipse.jface.viewers.*; 23 import org.eclipse.jface.wizard.*; 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.layout.GridData; 26 import org.eclipse.swt.layout.GridLayout; 27 import org.eclipse.swt.widgets.*; 28 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder; 29 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 30 import org.eclipse.team.internal.ccvs.ui.operations.RemoteProjectFolder; 31 import org.eclipse.ui.model.WorkbenchContentProvider; 32 import org.eclipse.ui.model.WorkbenchLabelProvider; 33 import org.eclipse.ui.views.navigator.ResourceSorter; 34 35 39 public abstract class CVSWizardPage extends WizardPage { 40 41 protected static final int LABEL_WIDTH_HINT = 400; 42 protected static final int LABEL_INDENT_WIDTH = 32; 43 protected static final int LIST_HEIGHT_HINT = 100; 44 protected static final int SPACER_HEIGHT = 8; 45 46 private ICVSWizard wizard; 47 48 52 public CVSWizardPage(String pageName) { 53 super(pageName); 54 } 55 56 62 public CVSWizardPage(String pageName, String title, ImageDescriptor titleImage) { 63 super(pageName, title, titleImage); 64 } 65 72 public CVSWizardPage(String pageName, String title, ImageDescriptor titleImage, String description) { 73 super(pageName, title, titleImage); 74 setDescription(description); 75 } 76 83 protected Button createCheckBox(Composite group, String label) { 84 Button button = new Button(group, SWT.CHECK | SWT.LEFT); 85 button.setText(label); 86 GridData data = new GridData(); 87 data.horizontalSpan = 2; 88 button.setLayoutData(data); 89 return button; 90 } 91 97 protected Combo createCombo(Composite parent) { 98 Combo combo = new Combo(parent, SWT.READ_ONLY); 99 GridData data = new GridData(GridData.FILL_HORIZONTAL); 100 data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; 101 combo.setLayoutData(data); 102 return combo; 103 } 104 112 protected Composite createComposite(Composite parent, int numColumns, boolean grabExcess) { 113 final Composite composite = new Composite(parent, SWT.NULL); 114 composite.setLayout(new GridLayout(numColumns, false)); 115 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, grabExcess, grabExcess)); 116 return composite; 117 } 118 119 127 public static Label createLabel(Composite parent, String text) { 128 return createIndentedLabel(parent, text, 0); 129 } 130 139 public static Label createIndentedLabel(Composite parent, String text, int indent) { 140 Label label = new Label(parent, SWT.LEFT); 141 label.setText(text); 142 GridData data = new GridData(); 143 data.horizontalSpan = 1; 144 data.horizontalAlignment = GridData.FILL; 145 data.horizontalIndent = indent; 146 label.setLayoutData(data); 147 return label; 148 } 149 159 protected Label createWrappingLabel(Composite parent, String text, int indent) { 160 return createWrappingLabel(parent, text, indent, 1); 161 } 162 163 protected Label createWrappingLabel(Composite parent, String text, int indent, int horizontalSpan) { 164 Label label = new Label(parent, SWT.LEFT | SWT.WRAP); 165 label.setText(text); 166 GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false); 167 data.horizontalIndent = indent; 168 data.horizontalSpan = horizontalSpan; 169 data.widthHint = LABEL_WIDTH_HINT; 170 label.setLayoutData(data); 171 return label; 172 } 173 174 180 static public Text createTextField(Composite parent) { 181 Text text = new Text(parent, SWT.SINGLE | SWT.BORDER); 182 return layoutTextField(text); 183 } 184 190 static public Text createPasswordField(Composite parent) { 191 Text text = new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD); 192 return layoutTextField(text); 193 } 194 200 static public Text layoutTextField(Text text) { 201 GridData data = new GridData(GridData.FILL_HORIZONTAL); 202 data.verticalAlignment = GridData.CENTER; 203 data.grabExcessVerticalSpace = false; 204 data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; 205 text.setLayoutData(data); 206 return text; 207 } 208 209 217 protected Button createRadioButton(Composite parent, String label, int span) { 218 Button button = new Button(parent, SWT.RADIO); 219 button.setText(label); 220 GridData data = new GridData(); 221 data.horizontalSpan = span; 222 button.setLayoutData(data); 223 return button; 224 } 225 226 protected TreeViewer createResourceSelectionTree(Composite composite, int types, int span) { 227 TreeViewer tree = new TreeViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); 228 tree.setUseHashlookup(true); 229 tree.setContentProvider(getResourceProvider(types)); 230 tree.setLabelProvider( 231 new DecoratingLabelProvider( 232 new WorkbenchLabelProvider(), 233 CVSUIPlugin.getPlugin().getWorkbench().getDecoratorManager().getLabelDecorator())); 234 tree.setSorter(new ResourceSorter(ResourceSorter.NAME)); 235 236 GridData data = new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL); 237 data.heightHint = LIST_HEIGHT_HINT; 238 data.horizontalSpan = span; 239 tree.getControl().setLayoutData(data); 240 return tree; 241 } 242 243 247 protected ITreeContentProvider getResourceProvider(final int resourceType) { 248 return new WorkbenchContentProvider() { 249 public Object [] getChildren(Object o) { 250 if (o instanceof IContainer) { 251 IResource[] members = null; 252 try { 253 members = ((IContainer)o).members(); 254 } catch (CoreException e) { 255 return new Object [0]; 257 } 258 259 ArrayList results = new ArrayList (); 261 for (int i = 0; i < members.length; i++) { 262 if ((members[i].getType() & resourceType) > 0) { 264 results.add(members[i]); 265 } 266 } 267 return results.toArray(); 268 } else { 269 return super.getChildren(o); 270 } 271 } 272 }; 273 } 274 275 protected ICVSWizard getCVSWizard() { 276 if (wizard != null) { 277 return wizard; 278 } 279 IWizard wizard = getWizard(); 280 if (wizard instanceof ICVSWizard) { 281 return ((ICVSWizard)wizard); 284 } 285 return null; 286 } 287 288 public void setCVSWizard(ICVSWizard wizard) { 289 this.wizard = wizard; 290 } 291 292 295 public IWizardPage getNextPage() { 296 ICVSWizard w = getCVSWizard(); 297 if (w != null) { 298 return w.getNextPage(this, true ); 301 } 302 return super.getNextPage(); 303 } 304 305 308 public boolean canFlipToNextPage() { 309 ICVSWizard w = getCVSWizard(); 310 if (w != null) { 311 return isPageComplete() && 312 w.getNextPage(this, false ) != null; 313 } 314 return super.canFlipToNextPage(); 315 } 316 317 323 static protected String getPreferredFolderName(ICVSRemoteFolder folder) { 324 if (CVSUIPlugin.getPlugin().isUseProjectNameOnCheckout() && folder instanceof RemoteProjectFolder ) { 325 RemoteProjectFolder rpf = (RemoteProjectFolder) folder; 326 if (rpf.hasProjectName()) { 327 return rpf.getProjectName(); 328 } 329 } 330 return folder.getName(); 331 } 332 } 333 | Popular Tags |