KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Philippe Ombredanne - bug 84808
11  *******************************************************************************/

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 /**
33  * This is the main page of the Check Out As wizard. It allows the user to specify
34  * whether they want to check out the remote folder(s) as project(s) or into an
35  * existing project. For single project checkout, the page will also allow the user to
36  * choose whether to configure the new project (if it is missing a .project file).
37  */

38 public class CheckoutAsMainPage extends CVSWizardPage {
39
40     private String JavaDoc 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 JavaDoc NAME = "CheckoutAsMainPage"; //$NON-NLS-1$
57

58     /**
59      * @param pageName
60      * @param title
61      * @param titleImage
62      * @param description
63      */

64     public CheckoutAsMainPage(ImageDescriptor titleImage, ICVSRemoteFolder[] folders, boolean allowProjectConfiguration) {
65         super(NAME, CVSUIMessages.CheckoutAsMainPage_title, titleImage, CVSUIMessages.CheckoutAsMainPage_description); //
66
this.folders = folders;
67         this.allowProjectConfiguration = allowProjectConfiguration;
68     }
69     
70     /* (non-Javadoc)
71      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
72      */

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     /*
91      * Is the input to the wizard a single folder or multiple folders
92      */

93     private boolean isSingleFolder() {
94         return folders.length == 1;
95     }
96
97     /*
98      * For the single folder case, return the name of the folder
99      */

100     private String JavaDoc getFolderName() {
101         String JavaDoc name = getPreferredFolderName(folders[0]);
102         if (name .equals(".")) { //$NON-NLS-1$
103
name = new Path(null, folders[0].getRepository().getRootDirectory()).lastSegment();
104         }
105         return name;
106     }
107     
108     /*
109      * Create the page contents for a single folder checkout
110      */

111     private void createSingleFolderArea(Composite composite) {
112         createLabel(composite, NLS.bind(CVSUIMessages.CheckoutAsMainPage_singleFolder, new String JavaDoc[] { 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         // Should sub-folders of the folder be checked out?
130
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     /*
142      * Create the page contents for a multiple folder checkout
143      */

144     private void createMultipleFoldersArea(Composite composite) {
145         createLabel(composite, NLS.bind(CVSUIMessages.CheckoutAsMainPage_multipleFolders, new String JavaDoc[] { new Integer JavaDoc(folders.length).toString() }));
146         createCheckoutAsProjectRadioArea(composite);
147         createCheckoutIntoRadioArea(composite);
148         simpleProjectButton.setSelection(true);
149         addWorkingSetSection(composite, CVSUIMessages.CheckoutAsMainPage_WorkingSetMultiple);
150     }
151
152     /**
153      * @param composite
154      */

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     /**
165      * @param composite
166      */

167     private void createCheckoutIntoRadioArea(Composite composite) {
168         intoProjectButton = createRadioButton(composite, CVSUIMessages.CheckoutAsMainPage_intoProject, 1);
169     }
170
171     /**
172      * Creates the project name specification controls.
173      *
174      * @param parent the parent composite
175      */

176     private void createProjectNameGroup(Composite parent) {
177         // project specification group
178
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         // new project label
185
Label projectLabel = new Label(projectGroup,SWT.NONE);
186         projectLabel.setText(CVSUIMessages.CheckoutAsMainPage_projectNameLabel);
187
188         // new project name entry field
189
projectNameField = new Text(projectGroup, SWT.BORDER);
190         GridData data = new GridData(GridData.FILL_HORIZONTAL);
191         projectNameField.setLayoutData(data);
192     
193         // Set the initial value first before listener
194
// to avoid handling an event during the creation.
195
newProjectName = getFolderName();
196         projectNameField.setText(newProjectName);
197         projectNameField.selectAll();
198     
199         // Set the listener to capture modify events
200
projectNameField.addModifyListener(new ModifyListener() {
201             public void modifyText(ModifyEvent e) {
202                 updateEnablements();
203             }
204         });
205     }
206     
207     /**
208      * Check if the entries in the widget are valid. If they are return null otherwise
209      * return a string that indicates the problem.
210      */

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 add to working set checkbox selected and the user has not selected
230
//a working set, mark page incomplete
231
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 JavaDoc 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     /* (non-Javadoc)
264      * @see org.eclipse.team.internal.ccvs.ui.wizards.CVSWizardPage#createRadioButton(org.eclipse.swt.widgets.Composite, java.lang.String, int)
265      */

266     protected Button createRadioButton(Composite parent, String JavaDoc 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     /**
277      * Returns the recurse.
278      * @return boolean
279      */

280     public boolean isRecurse() {
281         return recurse;
282     }
283     
284     /**
285      * Returns the name of the chosen working set
286      * @return String a string representing the working set or an empty string if no working set has been selected
287      */

288     public String JavaDoc getWorkingSetName(){
289         return workingSetField.getText();
290     }
291     
292     /**
293      * Returns whether the checkout should add the project(s) to a working set
294      * @return boolean true if it should add it to a working set, false otherwise
295      */

296     public boolean shouldAddToWorkingSet(){
297         return addToWorkingSet.getSelection();
298     }
299     
300     private void addWorkingSetSection(Composite composite, String JavaDoc 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         //keep track if the user has browsed for working sets; don't show any error message until then
323
haveBrowsed = false;
324         browseButton.addSelectionListener(new SelectionAdapter() {
325             public void widgetSelected(SelectionEvent e) {
326                 //open workspace selection dialog
327
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 JavaDoc 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