KickJava   Java API By Example, From Geeks To Geeks.

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


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.wizards;
12
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.jface.window.Window;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.ModifyEvent;
18 import org.eclipse.swt.events.ModifyListener;
19 import org.eclipse.swt.events.SelectionAdapter;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.widgets.Button;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Text;
25 import org.eclipse.team.internal.ccvs.core.CVSTag;
26 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
27 import org.eclipse.team.internal.ccvs.ui.IHelpContextIds;
28 import org.eclipse.team.internal.ccvs.ui.tags.TagContentAssistProcessor;
29 import org.eclipse.team.internal.ccvs.ui.tags.TagRefreshButtonArea;
30 import org.eclipse.team.internal.ccvs.ui.tags.TagSelectionArea;
31 import org.eclipse.team.internal.ccvs.ui.tags.TagSelectionDialog;
32 import org.eclipse.team.internal.ccvs.ui.tags.TagSource;
33 import org.eclipse.team.internal.ui.PixelConverter;
34 import org.eclipse.team.internal.ui.SWTUtils;
35 import org.eclipse.ui.PlatformUI;
36
37 public class MergeWizardPage extends CVSWizardPage {
38
39     private Text endTagField;
40     private Button endTagBrowseButton;
41     private TagSource tagSource;
42     private Text startTagField;
43     private Button startTagBrowseButton;
44     private TagRefreshButtonArea tagRefreshArea;
45     private CVSTag startTag;
46     private CVSTag endTag;
47     private Button previewButton;
48     private Button noPreviewButton;
49     protected boolean preview = true;
50     private Button onlyPreviewConflicts;
51     private boolean isOnlyPreviewConflicts = false;
52
53     public MergeWizardPage(String JavaDoc pageName, String JavaDoc title, ImageDescriptor titleImage, String JavaDoc description, TagSource tagSource) {
54         super(pageName, title, titleImage, description);
55         this.tagSource = tagSource;
56     }
57
58     /* (non-Javadoc)
59      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
60      */

61     public void createControl(Composite parent) {
62         
63         final PixelConverter converter= SWTUtils.createDialogPixelConverter(parent);
64         
65         final Composite composite = new Composite(parent, SWT.NONE);
66         composite.setLayout(SWTUtils.createGridLayout(1, converter, SWTUtils.MARGINS_DEFAULT));
67         // set F1 help
68
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.MERGE_WIZARD_PAGE);
69         
70         final Composite mainArea = new Composite(composite, SWT.NONE);
71         mainArea.setLayoutData(SWTUtils.createHFillGridData());
72         mainArea.setLayout(SWTUtils.createGridLayout(2, converter, SWTUtils.MARGINS_NONE));
73         
74         createEndTagArea(mainArea);
75         createStartTagArea(mainArea);
76         SWTUtils.equalizeControls(converter, new Button [] { endTagBrowseButton, startTagBrowseButton } );
77         
78         createPreviewOptionArea(composite, converter);
79         createTagRefreshArea(composite);
80
81         Dialog.applyDialogFont(composite);
82         setControl(composite);
83     }
84
85     private void createPreviewOptionArea(Composite parent, PixelConverter converter) {
86         
87         final Composite composite= new Composite(parent, SWT.NONE);
88         composite.setLayoutData(SWTUtils.createHFillGridData());
89         composite.setLayout(SWTUtils.createGridLayout(1, converter, SWTUtils.MARGINS_NONE));
90         
91         previewButton = SWTUtils.createRadioButton(composite, CVSUIMessages.MergeWizardPage_0);
92         if (MergeWizard.isShowModelSync()) {
93             onlyPreviewConflicts = SWTUtils.createCheckBox(composite, CVSUIMessages.MergeWizardPage_14);
94             GridData data = SWTUtils.createHFillGridData(1);
95             data.horizontalIndent = 10;
96             onlyPreviewConflicts.setLayoutData(data);
97         }
98         noPreviewButton = SWTUtils.createRadioButton(composite, CVSUIMessages.MergeWizardPage_1);
99         SelectionAdapter selectionAdapter = new SelectionAdapter() {
100             public void widgetSelected(SelectionEvent e) {
101                 preview = previewButton.getSelection();
102                 updateEnablements();
103             }
104         };
105         previewButton.setSelection(preview);
106         noPreviewButton.setSelection(!preview);
107         previewButton.addSelectionListener(selectionAdapter);
108         noPreviewButton.addSelectionListener(selectionAdapter);
109         if (onlyPreviewConflicts != null) {
110             onlyPreviewConflicts.setEnabled(preview);
111             onlyPreviewConflicts.setSelection(isOnlyPreviewConflicts);
112             onlyPreviewConflicts.addSelectionListener(new SelectionAdapter() {
113                 public void widgetSelected(SelectionEvent e) {
114                     isOnlyPreviewConflicts = onlyPreviewConflicts.getSelection();
115                 }
116             });
117         }
118     }
119     private void createTagRefreshArea(Composite composite) {
120         tagRefreshArea = new TagRefreshButtonArea(getShell(), getTagSource(), null);
121         tagRefreshArea.setRunnableContext(getContainer());
122         tagRefreshArea.createArea(composite);
123     }
124
125     private void createEndTagArea(Composite parent) {
126         SWTUtils.createLabel(parent, CVSUIMessages.MergeWizardPage_2, 2);
127         
128         endTagField = SWTUtils.createText(parent);
129         endTagField.addModifyListener(new ModifyListener() {
130             public void modifyText(ModifyEvent e) {
131                 updateEndTag(endTagField.getText());
132             }
133         });
134         final int endTagIncludeFlags = TagSelectionArea.INCLUDE_VERSIONS | TagSelectionArea.INCLUDE_BRANCHES | TagSelectionArea.INCLUDE_HEAD_TAG;
135         TagContentAssistProcessor.createContentAssistant(endTagField, tagSource, endTagIncludeFlags);
136         endTagBrowseButton = createPushButton(parent, CVSUIMessages.MergeWizardPage_3);
137         
138         endTagBrowseButton.addSelectionListener(new SelectionAdapter() {
139             public void widgetSelected(SelectionEvent e) {
140                 TagSelectionDialog dialog = new TagSelectionDialog(getShell(), getTagSource(),
141                         CVSUIMessages.MergeWizardPage_4,
142                         CVSUIMessages.MergeWizardPage_5,
143                         endTagIncludeFlags,
144                         false, IHelpContextIds.MERGE_END_PAGE);
145                 if (dialog.open() == Window.OK) {
146                     CVSTag selectedTag = dialog.getResult();
147                     setEndTag(selectedTag);
148                 }
149             }
150         });
151     }
152     
153     private void createStartTagArea(Composite parent) {
154         
155         SWTUtils.createLabel(parent, CVSUIMessages.MergeWizardPage_6, 2);
156
157         startTagField = SWTUtils.createText(parent);
158         startTagField.addModifyListener(new ModifyListener() {
159             public void modifyText(ModifyEvent e) {
160                 updateStartTag(startTagField.getText());
161             }
162         });
163         TagContentAssistProcessor.createContentAssistant(startTagField, tagSource, TagSelectionArea.INCLUDE_VERSIONS);
164
165         startTagBrowseButton = createPushButton(parent, CVSUIMessages.MergeWizardPage_7);
166         startTagBrowseButton.addSelectionListener(new SelectionAdapter() {
167             public void widgetSelected(SelectionEvent e) {
168                 TagSelectionDialog dialog = new TagSelectionDialog(getShell(), getTagSource(),
169                         CVSUIMessages.MergeWizardPage_8,
170                         CVSUIMessages.MergeWizardPage_9,
171                         TagSelectionDialog.INCLUDE_VERSIONS | TagSelectionDialog.INCLUDE_DATES,
172                         false, IHelpContextIds.MERGE_START_PAGE);
173                 if (dialog.open() == Window.OK) {
174                     CVSTag selectedTag = dialog.getResult();
175                     setStartTag(selectedTag);
176                 }
177             }
178         });
179     }
180
181     protected void updateEndTag(String JavaDoc text) {
182         if (endTag == null || !endTag.getName().equals(text)) {
183             CVSTag tag = getTagFor(text, false);
184             setEndTag(tag);
185         }
186         updateEnablements();
187     }
188     
189     protected void updateStartTag(String JavaDoc text) {
190         if (startTag == null || !startTag.getName().equals(text)) {
191             CVSTag tag = getTagFor(text, true);
192             setStartTag(tag);
193         }
194         updateEnablements();
195     }
196
197     private CVSTag getTagFor(String JavaDoc text, boolean versionsOnly) {
198         if (text.equals(CVSTag.DEFAULT.getName())) {
199             if (versionsOnly) return null;
200             return CVSTag.DEFAULT;
201         }
202         if (text.equals(CVSTag.BASE.getName())) {
203             if (versionsOnly) return null;
204             return CVSTag.BASE;
205         }
206         CVSTag[] tags;
207         if (versionsOnly) {
208             tags = tagSource.getTags(new int[] { CVSTag.VERSION, CVSTag.DATE });
209         } else {
210             tags = tagSource.getTags(new int[] { CVSTag.VERSION, CVSTag.BRANCH, CVSTag.DATE });
211         }
212         for (int i = 0; i < tags.length; i++) {
213             CVSTag tag = tags[i];
214             if (tag.getName().equals(text)) {
215                 return tag;
216             }
217         }
218         return null;
219     }
220
221     protected void setEndTag(CVSTag selectedTag) {
222         if (selectedTag == null || endTag == null || !endTag.equals(selectedTag)) {
223             endTag = selectedTag;
224             if (endTagField != null) {
225                 String JavaDoc name = endTagField.getText();
226                 if (endTag != null)
227                     name = endTag.getName();
228                 if (!endTagField.getText().equals(name))
229                     endTagField.setText(name);
230                 if (startTag == null && endTag != null && endTag.getType() == CVSTag.BRANCH) {
231                     CVSTag tag = findCommonBaseTag(endTag);
232                     if (tag != null) {
233                         setStartTag(tag);
234                     }
235                 }
236             }
237             updateEnablements();
238         }
239     }
240
241     protected void setStartTag(CVSTag selectedTag) {
242         if (selectedTag == null || startTag != null || endTag == null || !endTag.equals(selectedTag)) {
243             startTag = selectedTag;
244             if (startTagField != null) {
245                 String JavaDoc name = startTagField.getText();
246                 if (startTag != null)
247                     name = startTag.getName();
248                 if (!startTagField.getText().equals(name))
249                     startTagField.setText(name);
250             }
251             updateEnablements();
252         }
253     }
254     
255     private CVSTag findCommonBaseTag(CVSTag tag) {
256         CVSTag[] tags = tagSource.getTags(CVSTag.VERSION);
257         for (int i = 0; i < tags.length; i++) {
258             CVSTag potentialMatch = tags[i];
259             if (potentialMatch.getName().indexOf(tag.getName()) != -1) {
260                 return potentialMatch;
261             }
262         }
263         return null;
264     }
265
266     private void updateEnablements() {
267         if (onlyPreviewConflicts != null)
268             onlyPreviewConflicts.setEnabled(preview);
269         if (endTag == null && endTagField.getText().length() > 0) {
270             setErrorMessage(CVSUIMessages.MergeWizardPage_10);
271         } else if (startTag == null && startTagField.getText().length() > 0) {
272             setErrorMessage(CVSUIMessages.MergeWizardPage_11);
273         } else if (endTag != null && startTag != null && startTag.equals(endTag)) {
274             setErrorMessage(CVSUIMessages.MergeWizardPage_12);
275         } else if (startTag == null && endTag != null && preview) {
276             setErrorMessage(CVSUIMessages.MergeWizardPage_13);
277         } else {
278             setErrorMessage(null);
279         }
280         setPageComplete((startTag != null || !preview) && endTag != null && (startTag == null || !startTag.equals(endTag)));
281     }
282
283     protected TagSource getTagSource() {
284          return tagSource;
285     }
286
287     private Button createPushButton(Composite parent, String JavaDoc label) {
288         final Button button = new Button(parent, SWT.PUSH);
289         button.setText(label);
290         button.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
291         return button;
292     }
293
294     public CVSTag getStartTag() {
295         return startTag;
296     }
297     
298     public CVSTag getEndTag() {
299         return endTag;
300     }
301
302     public boolean isPreview() {
303         return preview;
304     }
305     
306     public boolean isOnlyPreviewConflicts() {
307         return isOnlyPreviewConflicts;
308     }
309 }
310
Popular Tags