KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > wizards > ConfigurationWizardMainPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Brock Janiczak <brockj@tpg.com.au> - Bug 185708 Provide link to open SSH/SSH2/proxy preferences from Connection wizard
11  *******************************************************************************/

12 package org.eclipse.team.internal.ccvs.ui.wizards;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Arrays JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Properties JavaDoc;
18
19 import org.eclipse.core.runtime.*;
20 import org.eclipse.jface.dialogs.*;
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.jface.preference.PreferenceDialog;
23 import org.eclipse.jface.resource.ImageDescriptor;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.events.SelectionAdapter;
26 import org.eclipse.swt.events.SelectionEvent;
27 import org.eclipse.swt.graphics.FontMetrics;
28 import org.eclipse.swt.graphics.GC;
29 import org.eclipse.swt.layout.*;
30 import org.eclipse.swt.widgets.*;
31 import org.eclipse.team.internal.ccvs.core.*;
32 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
33 import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
34 import org.eclipse.team.internal.ccvs.ui.*;
35 import org.eclipse.ui.PlatformUI;
36 import org.eclipse.ui.dialogs.PreferencesUtil;
37
38 /**
39  * Wizard page for entering information about a CVS repository location.
40  */

41 public class ConfigurationWizardMainPage extends CVSWizardPage {
42     private static final String JavaDoc ANONYMOUS_USER = "anonymous"; //$NON-NLS-1$
43

44     private boolean showValidate;
45     private boolean validate;
46     
47     // Widgets
48

49     // Connection Method
50
private Combo connectionMethodCombo;
51     // User
52
private Combo userCombo;
53     // Password
54
private Text passwordText;
55     // Port
56
private Text portText;
57     private Button useDefaultPort;
58     private Button useCustomPort;
59     // Host
60
private Combo hostCombo;
61     // Repository Path
62
private Combo repositoryPathCombo;
63     // Validation
64
private Button validateButton;
65     // Caching password
66
private Button allowCachingButton;
67     private boolean allowCaching = false;
68     
69     private static final int COMBO_HISTORY_LENGTH = 5;
70     
71     private Properties JavaDoc properties = null;
72     
73     // The previously created repository.
74
// It is recorded when asked for and
75
// nulled when the page is changed.
76
private ICVSRepositoryLocation location;
77     
78     // The previously created repository.
79
// It is recorded when fields are changed
80
private ICVSRepositoryLocation oldLocation;
81     
82     // Dialog store id constants
83
private static final String JavaDoc STORE_USERNAME_ID =
84         "ConfigurationWizardMainPage.STORE_USERNAME_ID";//$NON-NLS-1$
85
private static final String JavaDoc STORE_HOSTNAME_ID =
86         "ConfigurationWizardMainPage.STORE_HOSTNAME_ID";//$NON-NLS-1$
87
private static final String JavaDoc STORE_PATH_ID =
88         "ConfigurationWizardMainPage.STORE_PATH_ID";//$NON-NLS-1$
89
private static final String JavaDoc STORE_DONT_VALIDATE_ID =
90         "ConfigurationWizardMainPage.STORE_DONT_VALIDATE_ID";//$NON-NLS-1$
91

92     // In case the page was launched from a different wizard
93
private IDialogSettings settings;
94     
95     /**
96      * ConfigurationWizardMainPage constructor.
97      *
98      * @param pageName the name of the page
99      * @param title the title of the page
100      * @param titleImage the image for the page
101      */

102     public ConfigurationWizardMainPage(String JavaDoc pageName, String JavaDoc title, ImageDescriptor titleImage) {
103         super(pageName, title, titleImage);
104     }
105     /**
106      * Adds an entry to a history, while taking care of duplicate history items
107      * and excessively long histories. The assumption is made that all histories
108      * should be of length <code>ConfigurationWizardMainPage.COMBO_HISTORY_LENGTH</code>.
109      *
110      * @param history the current history
111      * @param newEntry the entry to add to the history
112      * @return the history with the new entry appended
113      */

114     private String JavaDoc[] addToHistory(String JavaDoc[] history, String JavaDoc newEntry) {
115         ArrayList JavaDoc l = new ArrayList JavaDoc(Arrays.asList(history));
116         addToHistory(l, newEntry);
117         String JavaDoc[] r = new String JavaDoc[l.size()];
118         l.toArray(r);
119         return r;
120     }
121     protected IDialogSettings getDialogSettings() {
122         return settings;
123     }
124     protected void setDialogSettings(IDialogSettings settings) {
125         this.settings = settings;
126     }
127     /**
128      * Adds an entry to a history, while taking care of duplicate history items
129      * and excessively long histories. The assumption is made that all histories
130      * should be of length <code>ConfigurationWizardMainPage.COMBO_HISTORY_LENGTH</code>.
131      *
132      * @param history the current history
133      * @param newEntry the entry to add to the history
134      */

135     private void addToHistory(List JavaDoc history, String JavaDoc newEntry) {
136         history.remove(newEntry);
137         history.add(0,newEntry);
138     
139         // since only one new item was added, we can be over the limit
140
// by at most one item
141
if (history.size() > COMBO_HISTORY_LENGTH)
142             history.remove(COMBO_HISTORY_LENGTH);
143     }
144     /**
145      * Creates the UI part of the page.
146      *
147      * @param parent the parent of the created widgets
148      */

149     public void createControl(Composite parent) {
150         Composite composite = createComposite(parent, 2, false);
151         // set F1 help
152
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.SHARING_NEW_REPOSITORY_PAGE);
153
154         Listener listener = new Listener() {
155             public void handleEvent(Event event) {
156                 if (location != null) {
157                     oldLocation = location;
158                     location = null;
159                 }
160                 if (event.widget == hostCombo) {
161                     String JavaDoc hostText = hostCombo.getText();
162                     if (hostText.length() > 0 && hostText.charAt(0) == ':') {
163                         try {
164                             CVSRepositoryLocation newLocation = CVSRepositoryLocation.fromString(hostText);
165                             connectionMethodCombo.setText(newLocation.getMethod().getName());
166                             repositoryPathCombo.setText(newLocation.getRootDirectory());
167                             int port = newLocation.getPort();
168                             if (port == ICVSRepositoryLocation.USE_DEFAULT_PORT) {
169                                 useDefaultPort.setSelection(true);
170                                 useCustomPort.setSelection(false);
171                             } else {
172                                 useCustomPort.setSelection(true);
173                                 useDefaultPort.setSelection(false);
174                                 portText.setText(String.valueOf(port));
175                             }
176                             
177                             userCombo.setText(newLocation.getUsername());
178                             //passwordText.setText(newLocation.xxx);
179
hostCombo.setText(newLocation.getHost());
180                         } catch (CVSException e) {
181                             CVSUIPlugin.log(e);
182                         }
183                     }
184                 }
185                 updateWidgetEnablements();
186             }
187         };
188         
189         Group g = createGroup(composite, CVSUIMessages.ConfigurationWizardMainPage_Location_1);
190         
191         // Host name
192
createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_host);
193         hostCombo = createEditableCombo(g);
194         hostCombo.addListener(SWT.Selection, listener);
195         hostCombo.addListener(SWT.Modify, listener);
196         
197         // Repository Path
198
createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_repositoryPath);
199         repositoryPathCombo = createEditableCombo(g);
200         repositoryPathCombo.addListener(SWT.Selection, listener);
201         repositoryPathCombo.addListener(SWT.Modify, listener);
202
203         g = createGroup(composite, CVSUIMessages.ConfigurationWizardMainPage_Authentication_2);
204         
205         // User name
206
createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_userName);
207         userCombo = createEditableCombo(g);
208         userCombo.addListener(SWT.Selection, listener);
209         userCombo.addListener(SWT.Modify, listener);
210         
211         // Password
212
createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_password);
213         passwordText = createPasswordField(g);
214         passwordText.addListener(SWT.Modify, listener);
215
216         g = createGroup(composite, CVSUIMessages.ConfigurationWizardMainPage_Connection_3);
217         
218         // Connection type
219
createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_connection);
220         connectionMethodCombo = createCombo(g);
221         connectionMethodCombo.addListener(SWT.Selection, listener);
222
223         // Port number
224
// create a composite to ensure the radio buttons come in the correct order
225
Composite portGroup = new Composite(g, SWT.NONE);
226         GridData data = new GridData();
227         data.horizontalSpan = 2;
228         portGroup.setLayoutData(data);
229         GridLayout layout = new GridLayout();
230         layout.numColumns = 2;
231         layout.marginHeight = 0;
232         layout.marginWidth = 0;
233         portGroup.setLayout(layout);
234         useDefaultPort = createRadioButton(portGroup, CVSUIMessages.ConfigurationWizardMainPage_useDefaultPort, 2);
235         useCustomPort = createRadioButton(portGroup, CVSUIMessages.ConfigurationWizardMainPage_usePort, 1);
236         useCustomPort.addListener(SWT.Selection, listener);
237         portText = createTextField(portGroup);
238         portText.addListener(SWT.Modify, listener);
239         
240         // create a composite to ensure the validate button is in its own tab group
241
if (showValidate) {
242             Composite validateButtonTabGroup = new Composite(composite, SWT.NONE);
243             data = new GridData();
244             data.horizontalSpan = 2;
245             validateButtonTabGroup.setLayoutData(data);
246             validateButtonTabGroup.setLayout(new FillLayout());
247
248             validateButton = new Button(validateButtonTabGroup, SWT.CHECK);
249             validateButton.setText(CVSUIMessages.ConfigurationWizardAutoconnectPage_validate);
250             validateButton.addListener(SWT.Selection, new Listener() {
251                 public void handleEvent(Event e) {
252                     validate = validateButton.getSelection();
253                 }
254             });
255         }
256         
257         allowCachingButton = new Button(composite, SWT.CHECK);
258         allowCachingButton.setText(CVSUIMessages.UserValidationDialog_6);
259         data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
260         data.horizontalSpan = 3;
261         allowCachingButton.setLayoutData(data);
262         allowCachingButton.addSelectionListener(new SelectionAdapter() {
263             public void widgetSelected(SelectionEvent e) {
264                 allowCaching = allowCachingButton.getSelection();
265             }
266         });
267     
268         Composite warningComposite = new Composite(composite, SWT.NONE);
269         layout = new GridLayout();
270         layout.numColumns = 2;
271         layout.marginHeight = 0;
272         layout.marginHeight = 0;
273         warningComposite.setLayout(layout);
274         data = new GridData(GridData.FILL_HORIZONTAL);
275         data.horizontalSpan = 3;
276         warningComposite.setLayoutData(data);
277         Label warningLabel = new Label(warningComposite, SWT.NONE);
278         warningLabel.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
279         warningLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING));
280         Label warningText = new Label(warningComposite, SWT.WRAP);
281         warningText.setText(CVSUIMessages.UserValidationDialog_7);
282         data = new GridData(GridData.FILL_HORIZONTAL);
283         data.widthHint = 300;
284         GC gc= new GC(composite);
285         gc.setFont(parent.getFont());
286         FontMetrics fontMetrics= gc.getFontMetrics();
287         gc.dispose();
288         data.heightHint= Dialog.convertHeightInCharsToPixels(fontMetrics, 3);
289         warningText.setLayoutData(data);
290         
291         Link extPrefLink = new Link(composite, SWT.NONE);
292         extPrefLink.setText(CVSUIMessages.ConfigurationWizardMainPage_7);
293         extPrefLink.addSelectionListener(new SelectionAdapter() {
294         
295             public void widgetSelected(SelectionEvent e) {
296                 PreferenceDialog prefDialog = PreferencesUtil.createPreferenceDialogOn(getShell(),
297                         "org.eclipse.team.cvs.ui.ExtMethodPreferencePage", //$NON-NLS-1$
298
new String JavaDoc[] {
299                             "org.eclipse.team.cvs.ui.cvs", //$NON-NLS-1$
300
"org.eclipse.team.cvs.ui.ExtMethodPreferencePage", //$NON-NLS-1$
301
"org.eclipse.jsch.ui.SSHPreferences", //$NON-NLS-1$
302
"org.eclipse.ui.net.NetPreferences"}, //$NON-NLS-1$
303
null);
304                 prefDialog.open();
305             }
306         
307         });
308         
309         
310         initializeValues();
311         updateWidgetEnablements();
312         hostCombo.setFocus();
313         
314         setControl(composite);
315         Dialog.applyDialogFont(parent);
316     }
317     /**
318      * Utility method to create an editable combo box
319      *
320      * @param parent the parent of the combo box
321      * @return the created combo
322      */

323     protected Combo createEditableCombo(Composite parent) {
324         Combo combo = new Combo(parent, SWT.NULL);
325         GridData data = new GridData(GridData.FILL_HORIZONTAL);
326         data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
327         combo.setLayoutData(data);
328         return combo;
329     }
330     
331     protected Group createGroup(Composite parent, String JavaDoc text) {
332         Group group = new Group(parent, SWT.NULL);
333         group.setText(text);
334         GridData data = new GridData(GridData.FILL_HORIZONTAL);
335         data.horizontalSpan = 2;
336         //data.widthHint = GROUP_WIDTH;
337

338         group.setLayoutData(data);
339         GridLayout layout = new GridLayout();
340         layout.numColumns = 2;
341         group.setLayout(layout);
342         return group;
343     }
344     
345     /*
346      * Create a Proeprties node that contains everything needed to create a repository location
347      */

348     private Properties JavaDoc createProperties() {
349         Properties JavaDoc result = new Properties JavaDoc();
350         result.setProperty("connection", connectionMethodCombo.getText()); //$NON-NLS-1$
351
result.setProperty("user", userCombo.getText()); //$NON-NLS-1$
352
result.setProperty("password", passwordText.getText()); //$NON-NLS-1$
353
result.setProperty("host", hostCombo.getText()); //$NON-NLS-1$
354
if (useCustomPort.getSelection()) {
355             result.setProperty("port", portText.getText()); //$NON-NLS-1$
356
}
357         result.setProperty("root", repositoryPathCombo.getText()); //$NON-NLS-1$
358
return result;
359     }
360     
361     /**
362      * Crate a new location with the information entered on the page.
363      * The location will exists and can be sed for connecting but is not
364      * registered for persistance. This method must be called from the UI
365      * thread.
366      * @return a location or <code>null</code>
367      * @throws CVSException
368      */

369     public ICVSRepositoryLocation getLocation() throws CVSException {
370         if (location == null) {
371             if (!isPageComplete()) return null;
372             location = CVSRepositoryLocation.fromProperties(createProperties());
373             if (location.equals(oldLocation)) {
374                 location = oldLocation;
375             }
376             location.setAllowCaching(allowCaching);
377             oldLocation = null;
378             saveWidgetValues();
379         }
380         return location;
381     }
382     
383     /**
384      * Initializes states of the controls.
385      */

386     private void initializeValues() {
387         // Set remembered values
388
IDialogSettings settings = getDialogSettings();
389         if (settings != null) {
390             String JavaDoc[] hostNames = settings.getArray(STORE_HOSTNAME_ID);
391             if (hostNames != null) {
392                 for (int i = 0; i < hostNames.length; i++) {
393                     hostCombo.add(hostNames[i]);
394                 }
395             }
396             String JavaDoc[] paths = settings.getArray(STORE_PATH_ID);
397             if (paths != null) {
398                 for (int i = 0; i < paths.length; i++) {
399                     repositoryPathCombo.add(paths[i]);
400                 }
401             }
402             String JavaDoc[] userNames = settings.getArray(STORE_USERNAME_ID);
403             if (userNames != null) {
404                 for (int i = 0; i < userNames.length; i++) {
405                     userCombo.add(userNames[i]);
406                 }
407             }
408             userCombo.add(ANONYMOUS_USER);
409             if (showValidate) {
410                 validate = !settings.getBoolean(STORE_DONT_VALIDATE_ID);
411                 validateButton.setSelection(validate);
412             }
413         }
414         
415         // Initialize other values and widget states
416
IConnectionMethod[] methods = CVSRepositoryLocation.getPluggedInConnectionMethods();
417         for (int i = 0; i < methods.length; i++) {
418             connectionMethodCombo.add(methods[i].getName());
419         }
420         
421         connectionMethodCombo.select(0);
422         useDefaultPort.setSelection(true);
423         
424         if(properties != null) {
425             String JavaDoc method = properties.getProperty("connection"); //$NON-NLS-1$
426
if (method == null) {
427                 connectionMethodCombo.select(0);
428             } else {
429                 connectionMethodCombo.select(connectionMethodCombo.indexOf(method));
430             }
431     
432             String JavaDoc user = properties.getProperty("user"); //$NON-NLS-1$
433
if (user != null) {
434                 userCombo.setText(user);
435             }
436     
437             String JavaDoc password = properties.getProperty("password"); //$NON-NLS-1$
438
if (password != null) {
439                 passwordText.setText(password);
440             }
441     
442             String JavaDoc host = properties.getProperty("host"); //$NON-NLS-1$
443
if (host != null) {
444                 hostCombo.setText(host);
445             }
446     
447             String JavaDoc port = properties.getProperty("port"); //$NON-NLS-1$
448
if (port != null) {
449                 useCustomPort.setSelection(true);
450                 portText.setText(port);
451             }
452     
453             String JavaDoc repositoryPath = properties.getProperty("root"); //$NON-NLS-1$
454
if (repositoryPath != null) {
455                 repositoryPathCombo.setText(repositoryPath);
456             }
457         }
458     }
459     /**
460      * Saves the widget values
461      */

462     private void saveWidgetValues() {
463         // Update history
464
IDialogSettings settings = getDialogSettings();
465         if (settings != null) {
466             String JavaDoc userName = userCombo.getText();
467             if (!userName.equals(ANONYMOUS_USER)) {
468                 String JavaDoc[] userNames = settings.getArray(STORE_USERNAME_ID);
469                 if (userNames == null) userNames = new String JavaDoc[0];
470                 userNames = addToHistory(userNames, userName);
471                 settings.put(STORE_USERNAME_ID, userNames);
472             }
473             String JavaDoc[] hostNames = settings.getArray(STORE_HOSTNAME_ID);
474             if (hostNames == null) hostNames = new String JavaDoc[0];
475             hostNames = addToHistory(hostNames, hostCombo.getText());
476             settings.put(STORE_HOSTNAME_ID, hostNames);
477
478             String JavaDoc[] paths = settings.getArray(STORE_PATH_ID);
479             if (paths == null) paths = new String JavaDoc[0];
480             paths = addToHistory(paths, repositoryPathCombo.getText());
481             settings.put(STORE_PATH_ID, paths);
482
483             if (showValidate) {
484                 settings.put(STORE_DONT_VALIDATE_ID, !validate);
485             }
486         }
487     }
488
489     public void setShowValidate(boolean showValidate) {
490         this.showValidate = showValidate;
491     }
492     
493     /**
494      * Sets the properties for the repository connection
495      *
496      * @param properties the properties or null
497      */

498     public void setProperties(Properties JavaDoc properties) {
499         this.properties = properties;
500     }
501     
502     /**
503      * Updates widget enablements and sets error message if appropriate.
504      */

505     protected void updateWidgetEnablements() {
506         if (useDefaultPort.getSelection()) {
507             portText.setEnabled(false);
508         } else {
509             portText.setEnabled(true);
510         }
511
512         validateFields();
513     }
514     /**
515      * Validates the contents of the editable fields and set page completion
516      * and error messages appropriately.
517      */

518     private void validateFields() {
519         String JavaDoc user = userCombo.getText();
520         IStatus status = validateUserName(user);
521         if (!isStatusOK(status)) {
522             return;
523         }
524
525         String JavaDoc host = hostCombo.getText();
526         status = validateHost(host);
527         if (!isStatusOK(status)) {
528             return;
529         }
530
531         if (portText.isEnabled()) {
532             String JavaDoc port = portText.getText();
533             status = validatePort(port);
534             if (!isStatusOK(status)) {
535                 return;
536             }
537         }
538
539         String JavaDoc pathString = repositoryPathCombo.getText();
540         status = validatePath(pathString);
541         if (!isStatusOK(status)) {
542             return;
543         }
544
545         try {
546             CVSRepositoryLocation l = CVSRepositoryLocation.fromProperties(createProperties());
547             if (!l.equals(oldLocation) && KnownRepositories.getInstance().isKnownRepository(l.getLocation())) {
548                 setErrorMessage(CVSUIMessages.ConfigurationWizardMainPage_0);
549                 setPageComplete(false);
550                 return;
551             }
552         } catch (CVSException e) {
553             CVSUIPlugin.log(e);
554             // Let it pass. Creation should fail
555
}
556         
557         // Everything passed so we're good to go
558
setErrorMessage(null);
559         setPageComplete(true);
560     }
561     
562     private boolean isStatusOK(IStatus status) {
563         if (!status.isOK()) {
564             if (status.getCode() == REQUIRED_FIELD) {
565                 // Don't set the message for an empty field
566
setErrorMessage(null);
567             } else {
568                 setErrorMessage(status.getMessage());
569             }
570             setPageComplete(false);
571             return false;
572         }
573         return true;
574     }
575     
576     public boolean getValidate() {
577         return validate;
578     }
579     public void setVisible(boolean visible) {
580         super.setVisible(visible);
581         if (visible) {
582             hostCombo.setFocus();
583         }
584     }
585     
586     public static final int REQUIRED_FIELD = 1;
587     public static final int INVALID_FIELD_CONTENTS = 2;
588     public static final IStatus validateUserName(String JavaDoc user) {
589         if (user.length() == 0) {
590             return new Status(IStatus.ERROR, CVSUIPlugin.ID, REQUIRED_FIELD, CVSUIMessages.ConfigurationWizardMainPage_1, null);
591         }
592         if ((user.indexOf('@') != -1) || (user.indexOf(':') != -1)) {
593             return new Status(IStatus.ERROR, CVSUIPlugin.ID, INVALID_FIELD_CONTENTS,
594                     CVSUIMessages.ConfigurationWizardMainPage_invalidUserName, null);
595         }
596         if (user.startsWith(" ") || user.endsWith(" ")) { //$NON-NLS-1$ //$NON-NLS-2$
597
return new Status(IStatus.ERROR, CVSUIPlugin.ID, INVALID_FIELD_CONTENTS,
598                     CVSUIMessages.ConfigurationWizardMainPage_6, null);
599         }
600         return Status.OK_STATUS;
601     }
602     public static final IStatus validateHost(String JavaDoc host) {
603         if (host.length() == 0) {
604             return new Status(IStatus.ERROR, CVSUIPlugin.ID, REQUIRED_FIELD, CVSUIMessages.ConfigurationWizardMainPage_2, null);
605         }
606         if (host.indexOf(':') != -1) {
607             return new Status(IStatus.ERROR, CVSUIPlugin.ID, INVALID_FIELD_CONTENTS,
608                     CVSUIMessages.ConfigurationWizardMainPage_invalidHostName, null);
609         }
610         if (host.startsWith(" ") || host.endsWith(" ")) { //$NON-NLS-1$ //$NON-NLS-2$
611
return new Status(IStatus.ERROR, CVSUIPlugin.ID, INVALID_FIELD_CONTENTS,
612                     CVSUIMessages.ConfigurationWizardMainPage_5, null);
613         }
614         return Status.OK_STATUS;
615     }
616     public static final IStatus validatePort(String JavaDoc port) {
617         if (port.length() == 0) {
618             return new Status(IStatus.ERROR, CVSUIPlugin.ID, REQUIRED_FIELD, CVSUIMessages.ConfigurationWizardMainPage_3, null);
619         }
620         try {
621             Integer.parseInt(port);
622         } catch (NumberFormatException JavaDoc e) {
623             return new Status(IStatus.ERROR, CVSUIPlugin.ID, INVALID_FIELD_CONTENTS,
624                 CVSUIMessages.ConfigurationWizardMainPage_invalidPort, null);
625         }
626         return Status.OK_STATUS;
627     }
628     public static final IStatus validatePath(String JavaDoc pathString) {
629         if (pathString.length() == 0) {
630             return new Status(IStatus.ERROR, CVSUIPlugin.ID, REQUIRED_FIELD, CVSUIMessages.ConfigurationWizardMainPage_4, null);
631         }
632         IPath path = new Path(null, pathString);
633         String JavaDoc[] segments = path.segments();
634         for (int i = 0; i < segments.length; i++) {
635             String JavaDoc string = segments[i];
636             if (string.charAt(0) == ' ' || string.charAt(string.length() -1) == ' ') {
637                 return new Status(IStatus.ERROR, CVSUIPlugin.ID, INVALID_FIELD_CONTENTS,
638                     CVSUIMessages.ConfigurationWizardMainPage_invalidPathWithSpaces, null);
639             }
640         }
641         // look for // and inform the user that we support use of C:\cvs\root instead of /c//cvs/root
642
if (pathString.indexOf("//") != -1) { //$NON-NLS-1$
643
if (pathString.indexOf("//") == 2) { //$NON-NLS-1$
644
// The user is probably trying to specify a CVSNT path
645
return new Status(IStatus.ERROR, CVSUIPlugin.ID, INVALID_FIELD_CONTENTS,
646                     CVSUIMessages.ConfigurationWizardMainPage_useNTFormat, null);
647             } else {
648                 return new Status(IStatus.ERROR, CVSUIPlugin.ID, INVALID_FIELD_CONTENTS,
649                     CVSUIMessages.ConfigurationWizardMainPage_invalidPathWithSlashes, null);
650             }
651         }
652         if (pathString.endsWith("/")) { //$NON-NLS-1$
653
return new Status(IStatus.ERROR, CVSUIPlugin.ID, INVALID_FIELD_CONTENTS,
654                     CVSUIMessages.ConfigurationWizardMainPage_invalidPathWithTrailingSlash, null);
655         }
656         return Status.OK_STATUS;
657     }
658 }
659
Popular Tags