KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.viewers.ISelectionChangedListener;
17 import org.eclipse.jface.viewers.SelectionChangedEvent;
18 import org.eclipse.jface.viewers.TreeViewer;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Button;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Event;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Listener;
27 import org.eclipse.swt.widgets.Shell;
28 import org.eclipse.swt.widgets.Text;
29 import org.eclipse.swt.widgets.Tree;
30 import org.eclipse.team.internal.ccvs.core.CVSTag;
31 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
32 import org.eclipse.team.internal.ccvs.ui.merge.ProjectElement;
33 import org.eclipse.team.internal.ccvs.ui.repo.RepositorySorter;
34 import org.eclipse.team.internal.ccvs.ui.wizards.CVSWizardPage;
35 import org.eclipse.team.internal.ui.dialogs.DetailsDialog;
36 import org.eclipse.ui.help.WorkbenchHelp;
37 import org.eclipse.ui.model.WorkbenchContentProvider;
38 import org.eclipse.ui.model.WorkbenchLabelProvider;
39
40 public class BranchPromptDialog extends DetailsDialog {
41
42     private ICVSFolder folder;
43     private String JavaDoc branchTag = ""; //$NON-NLS-1$
44
private String JavaDoc versionTag= ""; //$NON-NLS-1$
45
private String JavaDoc versionName= ""; //$NON-NLS-1$
46

47     private boolean allStickyResources;
48     private boolean update;
49         
50     private Text versionText;
51     private Text branchText;
52     
53     private static final int TABLE_HEIGHT_HINT = 150;
54     
55     // widgets;
56
private TreeViewer tagTree;
57     
58     public BranchPromptDialog(Shell parentShell, String JavaDoc title, ICVSFolder folder, boolean allResourcesSticky, String JavaDoc versionName) {
59         super(parentShell, title);
60         this.folder = folder;
61         this.allStickyResources = allResourcesSticky;
62         this.versionName = versionName;
63     }
64
65     /**
66      * @see DetailsDialog#createMainDialogArea(Composite)
67      */

68     protected void createMainDialogArea(Composite composite) {
69         // create message
70
Label label = new Label(composite, SWT.WRAP);
71         String JavaDoc message;
72         if(allStickyResources) {
73             message = Policy.bind("BranchWizardPage.pageDescriptionVersion"); //$NON-NLS-1$
74
} else {
75             message = Policy.bind("BranchWizardPage.pageDescription"); //$NON-NLS-1$
76
}
77         label.setText(message);
78         GridData data = new GridData(
79             GridData.GRAB_HORIZONTAL |
80             GridData.GRAB_VERTICAL |
81             GridData.HORIZONTAL_ALIGN_FILL |
82             GridData.VERTICAL_ALIGN_CENTER);
83         data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);;
84         label.setLayoutData(data);
85         
86         CVSWizardPage.createLabel(composite, Policy.bind("BranchWizardPage.branchName")); //$NON-NLS-1$
87
branchText = CVSWizardPage.createTextField(composite);
88         branchText.addListener(SWT.Modify, new Listener() {
89             public void handleEvent(Event event) {
90                 branchTag = branchText.getText();
91                 updateEnablements();
92                 updateVersionName(branchTag);
93             }
94         });
95
96         final Button check = new Button(composite, SWT.CHECK);
97         data = new GridData();
98         data.horizontalSpan = 2;
99         check.setLayoutData(data);
100         check.setText(Policy.bind("BranchWizardPage.startWorking")); //$NON-NLS-1$
101
check.addListener(SWT.Selection, new Listener() {
102             public void handleEvent(Event event) {
103                 update = check.getSelection();
104             }
105         });
106         check.setSelection(true);
107         update = true;
108         
109         label = new Label(composite, SWT.WRAP);
110         label.setText(Policy.bind("BranchWizardPage.specifyVersion")); //$NON-NLS-1$
111
data = new GridData();
112         data.horizontalSpan = 2;
113         data.widthHint = 350;
114         label.setLayoutData(data);
115             
116         CVSWizardPage.createLabel(composite, Policy.bind("BranchWizardPage.versionName")); //$NON-NLS-1$
117
versionText = CVSWizardPage.createTextField(composite);
118         versionText.addListener(SWT.Modify, new Listener() {
119             public void handleEvent(Event event) {
120                 versionTag = versionText.getText();
121                 updateEnablements();
122             }
123         });
124         
125         if(allStickyResources) {
126             versionText.setEditable(false);
127             versionText.setText(versionName);
128         }
129
130         // F1 Help
131
WorkbenchHelp.setHelp(composite, IHelpContextIds.BRANCH_DIALOG);
132         Dialog.applyDialogFont(composite);
133         branchText.setFocus();
134     }
135
136     /**
137      * Updates version name
138      */

139     protected void updateVersionName(String JavaDoc branchName) {
140         if(versionText!=null && !allStickyResources) {
141             versionText.setText(Policy.bind("BranchWizardPage.versionPrefix") + branchName); //$NON-NLS-1$
142
}
143     }
144     
145     /**
146      * @see DetailsDialog#createDropDownDialogArea(Composite)
147      */

148     protected Composite createDropDownDialogArea(Composite parent) {
149         
150         // create a composite with standard margins and spacing
151
Composite composite = new Composite(parent, SWT.NONE);
152         GridLayout layout = new GridLayout();
153         layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
154         layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
155         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
156         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
157         composite.setLayout(layout);
158         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
159         
160         Label label = new Label(composite, SWT.WRAP);
161         label.setText(Policy.bind("BranchWizardPage.existingVersionsAndBranches")); //$NON-NLS-1$
162
GridData data = new GridData(
163             GridData.GRAB_HORIZONTAL |
164             GridData.GRAB_VERTICAL |
165             GridData.HORIZONTAL_ALIGN_FILL |
166             GridData.VERTICAL_ALIGN_CENTER);
167         data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);;
168         label.setLayoutData(data);
169         
170         tagTree = createTree(composite);
171         tagTree.setInput(new ProjectElement(folder, ProjectElement.INCLUDE_BRANCHES | ProjectElement.INCLUDE_VERSIONS));
172         Runnable JavaDoc refresh = new Runnable JavaDoc() {
173             public void run() {
174                 getShell().getDisplay().syncExec(new Runnable JavaDoc() {
175                     public void run() {
176                         tagTree.refresh();
177                     }
178                 });
179             }
180         };
181         TagConfigurationDialog.createTagDefinitionButtons(getShell(), composite, new ICVSFolder[] {folder},
182                                                           convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT),
183                                                           convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH),
184                                                           refresh, refresh);
185         Dialog.applyDialogFont(parent);
186         return composite;
187     }
188     
189     /**
190      * Creates the existing branch and version tree viewer in the details pane
191      */

192     protected TreeViewer createTree(Composite parent) {
193         Tree tree = new Tree(parent, SWT.SINGLE | SWT.BORDER);
194         GridData data = new GridData(GridData.FILL_BOTH);
195         data.heightHint = TABLE_HEIGHT_HINT;
196         tree.setLayoutData(data);
197         TreeViewer result = new TreeViewer(tree);
198         result.setContentProvider(new WorkbenchContentProvider());
199         result.setLabelProvider(new WorkbenchLabelProvider());
200         result.addSelectionChangedListener(new ISelectionChangedListener() {
201             public void selectionChanged(SelectionChangedEvent event) {
202             }
203         });
204         result.setSorter(new RepositorySorter());
205         return result;
206     }
207     
208     /**
209      * Validates branch and version names
210      */

211     protected void updateEnablements() {
212         String JavaDoc message = null;
213         boolean complete = false;
214         
215         if (branchTag.length() == 0) {
216             message = ""; //$NON-NLS-1$
217
} else {
218             IStatus status = CVSTag.validateTagName(branchTag);
219             if (!status.isOK()) {
220                 message = Policy.bind("BranchWizard.branchNameWarning", status.getMessage()); //$NON-NLS-1$
221
} else {
222                 if(versionText!=null) {
223                     status = CVSTag.validateTagName(versionText.getText());
224                     if (!status.isOK()) {
225                         message = Policy.bind("BranchWizard.versionNameWarning", status.getMessage()); //$NON-NLS-1$
226
} else {
227                         if(versionTag.length() != 0 && versionTag.equals(branchTag)) {
228                             message = Policy.bind("BranchWizard.branchAndVersionMustBeDifferent"); //$NON-NLS-1$
229
}
230                     }
231                 }
232             }
233         }
234         setPageComplete(message == null);
235         setErrorMessage(message);
236     }
237     
238     /**
239      * Returns the branch tag name
240      */

241     public String JavaDoc getBranchTagName() {
242         return branchTag;
243     }
244     
245     /**
246      * Returns the version tag name
247      */

248     public String JavaDoc getVersionTagName() {
249         return versionTag;
250     }
251     
252     /**
253      * Returns the state of the update checkbox
254      */

255     public boolean getUpdate() {
256         return update;
257     }
258 }
259
Popular Tags