KickJava   Java API By Example, From Geeks To Geeks.

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


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.jface.dialogs.Dialog;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.jface.util.IPropertyChangeListener;
16 import org.eclipse.jface.util.PropertyChangeEvent;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.*;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
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.wizards.CVSWizardPage;
24 import org.eclipse.team.internal.ui.PixelConverter;
25 import org.eclipse.team.internal.ui.SWTUtils;
26 import org.eclipse.ui.PlatformUI;
27
28 /**
29  * General tag selection page that allows the selection of a tag
30  * for a particular remote folder
31  */

32 public class TagSelectionWizardPage extends CVSWizardPage {
33
34     private CVSTag selectedTag;
35     
36     // Needed to dynamicaly create refresh buttons
37
private Composite composite;
38     
39     private int includeFlags;
40     
41     // Fields for allowing the use of the tag from the local workspace
42
boolean allowNoTag = false;
43     private Button useResourceTagButton;
44     private Button selectTagButton;
45     private boolean useResourceTag = false;
46     private String JavaDoc helpContextId;
47     private TagSelectionArea tagArea;
48     private TagSource tagSource;
49     
50     public TagSelectionWizardPage(String JavaDoc pageName, String JavaDoc title, ImageDescriptor titleImage, String JavaDoc description, TagSource tagSource, int includeFlags) {
51         super(pageName, title, titleImage, description);
52         this.tagSource = tagSource;
53         this.includeFlags = includeFlags;
54     }
55
56     /**
57      * Set the help context for the tag selection page.
58      * This method must be invoked before <code>createControl</code>
59      * @param helpContextId the help context id
60      */

61     public void setHelpContxtId(String JavaDoc helpContextId) {
62         this.helpContextId = helpContextId;
63     }
64     
65     /* (non-Javadoc)
66      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
67      */

68     public void createControl(Composite parent) {
69         
70         final PixelConverter converter= SWTUtils.createDialogPixelConverter(parent);
71         
72         composite= new Composite(parent, SWT.NONE);
73         composite.setLayout(SWTUtils.createGridLayout(1, converter, SWTUtils.MARGINS_DEFAULT));
74         composite.setLayoutData(SWTUtils.createHVFillGridData());
75         setControl(composite);
76         
77         // set F1 help
78
if (helpContextId != null)
79             PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, helpContextId);
80         
81         if (allowNoTag) {
82             SelectionListener listener = new SelectionAdapter() {
83                 public void widgetSelected(SelectionEvent e) {
84                     useResourceTag = useResourceTagButton.getSelection();
85                     updateEnablement();
86                 }
87             };
88             useResourceTag = true;
89             useResourceTagButton = createRadioButton(composite, CVSUIMessages.TagSelectionWizardPage_0, 1);
90             selectTagButton = createRadioButton(composite, CVSUIMessages.TagSelectionWizardPage_1, 1);
91             useResourceTagButton.setSelection(useResourceTag);
92             selectTagButton.setSelection(!useResourceTag);
93             useResourceTagButton.addSelectionListener(listener);
94             selectTagButton.addSelectionListener(listener);
95         }
96         
97         createTagArea();
98         updateEnablement();
99         Dialog.applyDialogFont(parent);
100     }
101     
102     private void createTagArea() {
103         tagArea = new TagSelectionArea(getShell(), tagSource, includeFlags, null);
104         tagArea.setRunnableContext(getContainer());
105         tagArea.createArea(composite);
106         tagArea.addPropertyChangeListener(new IPropertyChangeListener() {
107             public void propertyChange(PropertyChangeEvent event) {
108                 if (event.getProperty().equals(TagSelectionArea.SELECTED_TAG)) {
109                     selectedTag = tagArea.getSelection();
110                     updateEnablement();
111                 } else if (event.getProperty().equals(TagSelectionArea.OPEN_SELECTED_TAG)) {
112                     if (selectedTag != null)
113                         gotoNextPage();
114                 }
115
116             }
117         });
118         refreshTagArea();
119     }
120
121     private void refreshTagArea() {
122         if (tagArea != null) {
123             tagArea.refresh();
124             tagArea.setSelection(selectedTag);
125         }
126     }
127     
128     protected void updateEnablement() {
129         tagArea.setEnabled(!useResourceTag);
130         setPageComplete(useResourceTag || selectedTag != null);
131     }
132     
133     public CVSTag getSelectedTag() {
134         if (useResourceTag)
135             return null;
136         return selectedTag;
137     }
138     
139     protected void gotoNextPage() {
140         TagSelectionWizardPage.this.getContainer().showPage(getNextPage());
141     }
142     
143     public void setAllowNoTag(boolean b) {
144         allowNoTag = b;
145     }
146     
147     public void setVisible(boolean visible) {
148         super.setVisible(visible);
149         if (visible && tagArea != null) {
150             tagArea.setFocus();
151         }
152     }
153
154     /**
155      * Set the tag source used by this wizard page
156      * @param source the tag source
157      */

158     public void setTagSource(TagSource source) {
159         this.tagSource = source;
160         tagArea.setTagSource(tagSource);
161         setSelection(null);
162         refreshTagArea();
163     }
164
165     /**
166      * Set the selection of the page to the given tag
167      * @param selectedTag
168      */

169     public void setSelection(CVSTag selectedTag) {
170         if (selectedTag == null && (includeFlags & TagSelectionArea.INCLUDE_HEAD_TAG) > 0) {
171             this.selectedTag = CVSTag.DEFAULT;
172         } else {
173             this.selectedTag = selectedTag;
174         }
175     }
176 }
177
Popular Tags