KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > tags > BranchPromptDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui.tags;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.widgets.*;
21 import org.eclipse.team.internal.ccvs.core.CVSTag;
22 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
23 import org.eclipse.team.internal.ccvs.ui.IHelpContextIds;
24 import org.eclipse.team.internal.ccvs.ui.wizards.CVSWizardPage;
25 import org.eclipse.team.internal.ui.PixelConverter;
26 import org.eclipse.team.internal.ui.SWTUtils;
27 import org.eclipse.team.internal.ui.dialogs.DetailsDialog;
28
29 public class BranchPromptDialog extends DetailsDialog {
30
31     private String JavaDoc branchTag = ""; //$NON-NLS-1$
32
private String JavaDoc versionTag= ""; //$NON-NLS-1$
33
private String JavaDoc versionName= ""; //$NON-NLS-1$
34

35     private boolean allStickyResources;
36     private boolean update;
37         
38     private Text versionText;
39     private Text branchText;
40     
41     private static final int TAG_AREA_HEIGHT_HINT = 200;
42     
43     // widgets;
44
private TagSource tagSource;
45     private TagSelectionArea tagArea;
46     private final IResource[] resources;
47     
48     public BranchPromptDialog(Shell parentShell, String JavaDoc title, IResource[] resources, boolean allResourcesSticky, String JavaDoc versionName) {
49         super(parentShell, title);
50         this.resources = resources;
51         this.tagSource = TagSource.create(resources);
52         this.allStickyResources = allResourcesSticky;
53         this.versionName = versionName;
54     }
55
56     /**
57      * @see DetailsDialog#createMainDialogArea(Composite)
58      */

59     protected void createMainDialogArea(Composite composite) {
60         
61         applyDialogFont(composite);
62         initializeDialogUnits(composite);
63         
64         final int areaWidth= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
65         
66         final Label description= SWTUtils.createLabel(composite, allStickyResources ? CVSUIMessages.BranchWizardPage_pageDescriptionVersion : CVSUIMessages.BranchWizardPage_pageDescription);
67         description.setLayoutData(SWTUtils.createGridData(areaWidth, SWT.DEFAULT, true, false));
68         
69         final Label name= SWTUtils.createLabel(composite, CVSUIMessages.BranchWizardPage_branchName);
70         name.setLayoutData(SWTUtils.createGridData(areaWidth, SWT.DEFAULT, true, false));
71         
72         branchText = CVSWizardPage.createTextField(composite);
73         branchText.addListener(SWT.Modify, new Listener() {
74             public void handleEvent(Event event) {
75                 branchTag = branchText.getText();
76                 updateEnablements();
77                 updateVersionName(branchTag);
78             }
79         });
80         addBranchContentAssist();
81
82         final Button check = SWTUtils.createCheckBox(composite, CVSUIMessages.BranchWizardPage_startWorking);
83         check.addListener(SWT.Selection, new Listener() {
84             public void handleEvent(Event event) {
85                 update = check.getSelection();
86             }
87         });
88         check.setSelection(true);
89         update = true;
90         
91         final Label versionLabel1= SWTUtils.createLabel(composite, CVSUIMessages.BranchWizardPage_specifyVersion);
92         versionLabel1.setLayoutData(SWTUtils.createGridData(areaWidth, SWT.DEFAULT, true, false));
93
94         final Label versionLabel2= SWTUtils.createLabel(composite, CVSUIMessages.BranchWizardPage_versionName);
95         versionLabel2.setLayoutData(SWTUtils.createGridData(areaWidth, SWT.DEFAULT, true, false));
96         
97         versionText = CVSWizardPage.createTextField(composite);
98         versionText.addListener(SWT.Modify, new Listener() {
99             public void handleEvent(Event event) {
100                 versionTag = versionText.getText();
101                 updateEnablements();
102             }
103         });
104         
105         if(allStickyResources) {
106             versionText.setEditable(false);
107             versionText.setText(versionName);
108         }
109
110         applyDialogFont(composite);
111         branchText.setFocus();
112     }
113
114     /* (non-Javadoc)
115      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#getHelpContextId()
116      */

117     protected String JavaDoc getHelpContextId() {
118         return IHelpContextIds.BRANCH_DIALOG;
119     }
120     private void addBranchContentAssist() {
121         TagSource projectTagSource = LocalProjectTagSource.create(getSeedProject());
122         if (projectTagSource != null)
123             TagContentAssistProcessor.createContentAssistant(branchText, projectTagSource, TagSelectionArea.INCLUDE_BRANCHES);
124     }
125
126     private IProject getSeedProject() {
127         return resources[0].getProject();
128     }
129
130     /**
131      * Updates version name
132      */

133     protected void updateVersionName(String JavaDoc branchName) {
134         if(versionText!=null && !allStickyResources) {
135             versionText.setText(CVSUIMessages.BranchWizardPage_versionPrefix + branchName);
136         }
137     }
138     
139     /**
140      * @see DetailsDialog#createDropDownDialogArea(Composite)
141      */

142     protected Composite createDropDownDialogArea(Composite parent) {
143         
144         applyDialogFont(parent);
145         final PixelConverter converter= new PixelConverter(parent);
146         
147         final Composite composite = new Composite(parent, SWT.NONE);
148         composite.setLayout(SWTUtils.createGridLayout(1, converter, SWTUtils.MARGINS_DIALOG));
149         final GridData gridData = new GridData(GridData.FILL_BOTH);
150         gridData.heightHint = TAG_AREA_HEIGHT_HINT;
151         composite.setLayoutData(gridData);
152         
153         tagArea = new TagSelectionArea(getShell(), tagSource, TagSelectionArea.INCLUDE_VERSIONS | TagSelectionArea.INCLUDE_BRANCHES, null);
154         tagArea.setTagAreaLabel(CVSUIMessages.BranchWizardPage_existingVersionsAndBranches);
155         tagArea.setIncludeFilterInputArea(false);
156         tagArea.createArea(composite);
157
158         return composite;
159     }
160     
161     /**
162      * Validates branch and version names
163      */

164     protected void updateEnablements() {
165         String JavaDoc message = null;
166         
167         if (branchTag.length() == 0) {
168             message = ""; //$NON-NLS-1$
169
} else {
170             IStatus status = CVSTag.validateTagName(branchTag);
171             if (!status.isOK()) {
172                 message = NLS.bind(CVSUIMessages.BranchWizard_branchNameWarning, new String JavaDoc[] { status.getMessage() });
173             } else {
174                 if(versionText!=null) {
175                     status = CVSTag.validateTagName(versionText.getText());
176                     if (!status.isOK()) {
177                         message = NLS.bind(CVSUIMessages.BranchWizard_versionNameWarning, new String JavaDoc[] { status.getMessage() });
178                     } else {
179                         if(versionTag.length() != 0 && versionTag.equals(branchTag)) {
180                             message = CVSUIMessages.BranchWizard_branchAndVersionMustBeDifferent;
181                         }
182                     }
183                 }
184             }
185         }
186         setPageComplete(message == null);
187         setErrorMessage(message);
188     }
189     
190     /**
191      * Returns the branch tag name
192      */

193     public String JavaDoc getBranchTagName() {
194         return branchTag;
195     }
196     
197     /**
198      * Returns the version tag name
199      */

200     public String JavaDoc getVersionTagName() {
201         return versionTag;
202     }
203     
204     /**
205      * Returns the state of the update checkbox
206      */

207     public boolean getUpdate() {
208         return update;
209     }
210     
211     /* (non-Javadoc)
212      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#isMainGrabVertical()
213      */

214     protected boolean isMainGrabVertical() {
215         return false;
216     }
217
218 }
219
Popular Tags