KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > feature > BaseFeatureSpecPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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
12 package org.eclipse.pde.internal.ui.wizards.feature;
13
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.PluginVersionIdentifier;
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.jface.window.Window;
18 import org.eclipse.jface.wizard.WizardPage;
19 import org.eclipse.pde.internal.core.PDECore;
20 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
21 import org.eclipse.pde.internal.core.util.IdUtil;
22 import org.eclipse.pde.internal.ui.PDEUIMessages;
23 import org.eclipse.pde.internal.ui.util.SWTUtil;
24 import org.eclipse.pde.internal.ui.wizards.FeatureSelectionDialog;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.ModifyEvent;
27 import org.eclipse.swt.events.ModifyListener;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.layout.GridLayout;
32 import org.eclipse.swt.widgets.Button;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Group;
35 import org.eclipse.swt.widgets.Label;
36 import org.eclipse.swt.widgets.Text;
37 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
38
39 public abstract class BaseFeatureSpecPage extends WizardPage {
40     
41     private boolean isPatch;
42     protected WizardNewProjectCreationPage mainPage;
43     protected Text featureIdText;
44     protected Text featureNameText;
45     protected Text featureVersionText;
46     protected Text featureProviderText;
47     protected Text patchIdText;
48     protected Text patchNameText;
49     protected Text patchProviderText;
50     protected Text libraryText;
51     protected Button browseButton;
52     protected Button customChoice;
53     protected String JavaDoc initialId;
54     protected String JavaDoc initialName;
55     protected Label libraryLabel;
56     protected boolean isInitialized = false;
57     protected IFeatureModel fFeatureToPatch;
58     
59     public BaseFeatureSpecPage(WizardNewProjectCreationPage mainPage,
60             boolean isPatch) {
61         super("specPage"); //$NON-NLS-1$
62
this.isPatch = isPatch;
63         this.mainPage = mainPage;
64     }
65     
66     public void createControl(Composite parent) {
67         Composite container = new Composite(parent, SWT.NULL);
68         GridLayout layout = new GridLayout();
69         layout.numColumns = 2;
70         layout.verticalSpacing = 12;
71         layout.horizontalSpacing = 9;
72         container.setLayout(layout);
73         
74         ModifyListener listener = new ModifyListener() {
75             public void modifyText(ModifyEvent e) {
76                 verifyComplete();
77             }
78         };
79         
80         if (isPatch()) {
81             Group patchPropertiesGroup = new Group(container, SWT.NULL);
82             layout = new GridLayout(2, false);
83             patchPropertiesGroup.setLayout(layout);
84             GridData gd = new GridData(GridData.FILL_HORIZONTAL);
85             gd.horizontalSpan = 2;
86             patchPropertiesGroup.setLayoutData(gd);
87             patchPropertiesGroup.setText(PDEUIMessages.NewFeatureWizard_SpecPage_patchProperties); //$NON-NLS-1$
88
Label label = new Label(patchPropertiesGroup, SWT.NULL);
89             label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_id);
90             patchIdText = new Text(patchPropertiesGroup, SWT.BORDER);
91             gd = new GridData(GridData.FILL_HORIZONTAL);
92             patchIdText.setLayoutData(gd);
93             if (initialId != null)
94                 patchIdText.setText(initialId);
95             patchIdText.addModifyListener(listener);
96             
97             label = new Label(patchPropertiesGroup, SWT.NULL);
98             label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_name);
99             patchNameText = new Text(patchPropertiesGroup, SWT.BORDER);
100             gd = new GridData(GridData.FILL_HORIZONTAL);
101             patchNameText.setLayoutData(gd);
102             if (initialName != null)
103                 patchNameText.setText(initialName);
104             patchNameText.addModifyListener(listener);
105             
106             label = new Label(patchPropertiesGroup, SWT.NULL);
107             label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_provider);
108             patchProviderText = new Text(patchPropertiesGroup, SWT.BORDER);
109             gd = new GridData(GridData.FILL_HORIZONTAL);
110             patchProviderText.setLayoutData(gd);
111             patchProviderText.addModifyListener(listener);
112         }
113         addFeatureProperties(container, listener);
114         addCustomInstallHandlerSection(container, listener);
115         
116         setControl(container);
117         Dialog.applyDialogFont(container);
118     }
119     private void addCustomInstallHandlerSection(Composite parent, ModifyListener listener) {
120         Group customHandlerGroup = new Group(parent, SWT.NONE);
121         GridLayout layout = new GridLayout();
122         layout.numColumns = 2;
123         customHandlerGroup.setLayout(layout);
124         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
125         gd.horizontalSpan = 2;
126         customHandlerGroup.setLayoutData(gd);
127         customHandlerGroup.setText(PDEUIMessages.BaseFeatureSpecPage_customGroup); //$NON-NLS-1$
128

129         customChoice = new Button(customHandlerGroup, SWT.CHECK);
130         if (!isPatch())
131             customChoice.setText(PDEUIMessages.NewFeatureWizard_SpecPage_customProject);
132         else
133             customChoice.setText(PDEUIMessages.NewFeatureWizard_SpecPage_patch_customProject);
134         customChoice.addSelectionListener(new SelectionAdapter() {
135             public void widgetSelected(SelectionEvent e) {
136                 boolean isSelected = ((Button) e.widget).getSelection();
137                 libraryText.setEnabled(isSelected);
138                 libraryLabel.setEnabled(isSelected);
139                 verifyComplete();
140             }
141         });
142         gd = new GridData(GridData.FILL_HORIZONTAL);
143         gd.horizontalSpan = 2;
144         customChoice.setLayoutData(gd);
145         
146         libraryLabel = new Label(customHandlerGroup, SWT.NULL);
147         libraryLabel.setText(
148             PDEUIMessages.NewFeatureWizard_SpecPage_library);
149         gd = new GridData();
150         gd.horizontalIndent = 22;
151         libraryLabel.setLayoutData(gd);
152         libraryText = new Text(customHandlerGroup, SWT.SINGLE | SWT.BORDER);
153         libraryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
154         libraryText.addModifyListener(listener);
155         
156     }
157     public boolean isPatch() {
158         return isPatch;
159     }
160     
161     protected abstract void verifyComplete();
162     /**
163      * @return Returns the initialName.
164      */

165     public String JavaDoc getInitialName() {
166         return initialName;
167     }
168     
169     /**
170      * @param initialName
171      * The initialName to set.
172      */

173     public void setInitialName(String JavaDoc initialName) {
174         this.initialName = initialName;
175     }
176     
177     /**
178      *
179      * @param initialId
180      */

181     public void setInitialId(String JavaDoc initialId) {
182         this.initialId = initialId;
183     }
184     
185     /**
186      * @return Returns the initialId.
187      */

188     public String JavaDoc getInitialId() {
189         return initialId;
190     }
191     
192     protected void initialize(){
193         customChoice.setSelection(false);
194         libraryText.setEnabled(false);
195         libraryLabel.setEnabled(false);
196     }
197     
198     private void addFeatureProperties(Composite container, ModifyListener listener){
199         Group featurePropertiesGroup = new Group(container, SWT.NULL);
200         GridLayout layout = new GridLayout(2, false);
201         featurePropertiesGroup.setLayout(layout);
202         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
203         gd.horizontalSpan = 2;
204         featurePropertiesGroup.setLayoutData(gd);
205         
206         if (isPatch()){
207             featurePropertiesGroup.setText(PDEUIMessages.BaseFeatureSpecPage_patchGroup_title); //$NON-NLS-1$
208

209             Label label = new Label(featurePropertiesGroup, SWT.NULL);
210             label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_id);
211             
212             Composite patchcontainer = new Composite(featurePropertiesGroup, SWT.NULL);
213             layout = new GridLayout(2, false);
214             layout.marginHeight = layout.marginWidth =0;
215             layout.horizontalSpacing = 5;
216             patchcontainer.setLayout(layout);
217             gd = new GridData(GridData.FILL_HORIZONTAL);
218             gd.horizontalSpan = 1;
219             patchcontainer.setLayoutData(gd);
220             
221             featureIdText = new Text(patchcontainer, SWT.BORDER);
222             gd = new GridData(GridData.FILL_HORIZONTAL);
223             featureIdText.setLayoutData(gd);
224             if (initialId != null)
225                 featureIdText.setText(initialId);
226             featureIdText.addModifyListener(listener);
227             
228             browseButton = new Button(patchcontainer, SWT.PUSH);
229             browseButton.setText(PDEUIMessages.BaseFeatureSpecPage_browse); //$NON-NLS-1$
230
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
231             browseButton.setLayoutData(gd);
232             browseButton.addSelectionListener(new SelectionAdapter() {
233                 
234                 public void widgetSelected(SelectionEvent e) {
235                     FeatureSelectionDialog dialog = new FeatureSelectionDialog(
236                             getShell(), PDECore.getDefault()
237                                     .getFeatureModelManager().getModels(),
238                             false);
239                     dialog.create();
240                     if (dialog.open() == Window.OK) {
241                         Object JavaDoc[] result = dialog.getResult();
242                         IFeatureModel selectedModel = (IFeatureModel) result[0];
243                         featureIdText.setText(selectedModel.getFeature().getId());
244                         featureNameText.setText(selectedModel.getFeature().getLabel());
245                         featureVersionText.setText(selectedModel.getFeature().getVersion());
246                         fFeatureToPatch = selectedModel;
247                     }
248                 }
249             });
250             SWTUtil.setButtonDimensionHint(browseButton);
251         } else {
252             featurePropertiesGroup.setText(PDEUIMessages.BaseFeatureSpecPage_featurePropertiesGroup_title); //$NON-NLS-1$
253

254             Label label = new Label(featurePropertiesGroup, SWT.NULL);
255             label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_id);
256             featureIdText = new Text(featurePropertiesGroup, SWT.BORDER);
257             gd = new GridData(GridData.FILL_HORIZONTAL);
258             featureIdText.setLayoutData(gd);
259             if (initialId != null)
260                 featureIdText.setText(initialId);
261             featureIdText.addModifyListener(listener);
262             
263         }
264         
265         Label label = new Label(featurePropertiesGroup, SWT.NULL);
266         label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_name);
267         featureNameText = new Text(featurePropertiesGroup, SWT.BORDER);
268         gd = new GridData(GridData.FILL_HORIZONTAL);
269         featureNameText.setLayoutData(gd);
270         if (initialName != null)
271             featureNameText.setText(initialName);
272         featureNameText.addModifyListener(listener);
273         
274         label = new Label(featurePropertiesGroup, SWT.NULL);
275         label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_version);
276         featureVersionText = new Text(featurePropertiesGroup, SWT.BORDER);
277         gd = new GridData(GridData.FILL_HORIZONTAL);
278         featureVersionText.setLayoutData(gd);
279         featureVersionText.addModifyListener(listener);
280         if (!isPatch()) {
281             label = new Label(featurePropertiesGroup, SWT.NULL);
282             label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_provider);
283             featureProviderText = new Text(featurePropertiesGroup, SWT.BORDER);
284             gd = new GridData(GridData.FILL_HORIZONTAL);
285             featureProviderText.setLayoutData(gd);
286             featureProviderText.addModifyListener(listener);
287         }
288     }
289     protected String JavaDoc computeInitialId(String JavaDoc projectName) {
290         return projectName.replaceAll("[^a-zA-Z0-9\\._]", "_"); //$NON-NLS-1$ //$NON-NLS-2$
291
}
292     
293     protected String JavaDoc verifyVersion() {
294         String JavaDoc problemText = PDEUIMessages.NewFeatureWizard_SpecPage_versionFormat;
295         String JavaDoc value = featureVersionText.getText();
296         if (PluginVersionIdentifier.validateVersion(value).getSeverity() != IStatus.OK)
297             return problemText;
298         return null;
299     }
300     
301     protected String JavaDoc verifyIdRules() {
302         String JavaDoc id = featureIdText.getText();
303         if (id == null || id.length() == 0)
304             return PDEUIMessages.NewFeatureWizard_SpecPage_missing;
305         if (!IdUtil.isValidPluginId(id)) {
306             return PDEUIMessages.NewFeatureWizard_SpecPage_invalidId;
307         }
308         return null;
309     }
310     
311     public IFeatureModel getFeatureToPatch(){
312         return fFeatureToPatch;
313     }
314         
315     protected String JavaDoc getInstallHandlerLibrary() {
316         if (!customChoice.getSelection())
317             return null;
318         String JavaDoc library = libraryText.getText();
319         if (!library.endsWith(".jar") && !library.endsWith("/") && !library.equals(".")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
320
library += "/"; //$NON-NLS-1$
321
return library;
322     }
323 }
324
Popular Tags