KickJava   Java API By Example, From Geeks To Geeks.

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


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
12 package org.eclipse.pde.internal.ui.wizards.feature;
13
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
17 import org.eclipse.pde.internal.core.util.IdUtil;
18 import org.eclipse.pde.internal.core.util.VersionUtil;
19 import org.eclipse.pde.internal.ui.PDEUIMessages;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.ModifyEvent;
22 import org.eclipse.swt.events.ModifyListener;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Text;
27 import org.eclipse.ui.PlatformUI;
28 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
29
30 public abstract class AbstractFeatureSpecPage extends WizardNewProjectCreationPage {
31     
32     protected Text fFeatureNameText;
33     protected Text fFeatureVersionText;
34     protected Text fLibraryText;
35     protected String JavaDoc fInitialId;
36     protected String JavaDoc fInitialName;
37     protected IFeatureModel fFeatureToPatch;
38     protected boolean fSelfModification;
39     private boolean fUpdateName = true;
40     
41     public AbstractFeatureSpecPage() {
42         super("specPage"); //$NON-NLS-1$
43
}
44     
45     public void createControl(Composite parent) {
46         super.createControl(parent);
47         Composite comp = (Composite)getControl();
48         
49         createContents(comp);
50         
51         initialize();
52         attachListeners();
53         
54         Dialog.applyDialogFont(comp);
55         PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, getHelpId());
56     }
57
58     protected abstract void createContents(Composite container);
59     
60     protected abstract void initialize();
61     
62     protected abstract void attachListeners(ModifyListener listener);
63     
64     protected abstract String JavaDoc getHelpId();
65     
66     protected void createCommonInput(Composite common) {
67         Label label = new Label(common, SWT.NULL);
68         label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_name);
69         fFeatureNameText = new Text(common, SWT.BORDER);
70         fFeatureNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
71         
72         label = new Label(common, SWT.NULL);
73         label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_version);
74         fFeatureVersionText = new Text(common, SWT.BORDER);
75         fFeatureVersionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
76     }
77     
78     protected void createInstallHandlerText(Composite parent) {
79         Label libraryLabel = new Label(parent, SWT.NULL);
80         libraryLabel.setText(PDEUIMessages.NewFeatureWizard_SpecPage_library);
81         fLibraryText = new Text(parent, SWT.SINGLE | SWT.BORDER);
82         fLibraryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
83     }
84     
85     protected abstract void updateNameRelativeFields();
86     
87     protected boolean validatePage() {
88         boolean valid = super.validatePage();
89         if (!valid)
90             return valid;
91         if (fUpdateName)
92             updateNameRelativeFields();
93         return validateBaseContent(false);
94     }
95     
96     private boolean validateBaseContent(boolean validateSuper) {
97         if (validateSuper && !super.validatePage())
98             return false;
99         if (!setValidationMessage(verifyIdRules()))
100             return false;
101         if (!setValidationMessage(verifyVersion()))
102             return false;
103         if (!setValidationMessage(validateContent()))
104             return false;
105
106         setPageComplete(true);
107         setErrorMessage(null);
108         return true;
109     }
110     
111     private boolean setValidationMessage(String JavaDoc message) {
112         if (message == null)
113             return true;
114         setPageComplete(false);
115         setErrorMessage(message);
116         return false;
117     }
118     
119     protected abstract String JavaDoc validateContent();
120     
121     public String JavaDoc getInitialName() {
122         return fInitialName;
123     }
124     
125     public void setInitialName(String JavaDoc initialName) {
126         fInitialName = initialName;
127     }
128     
129     public void setInitialId(String JavaDoc initialId) {
130         fInitialId = initialId;
131     }
132     
133     public String JavaDoc getInitialId() {
134         return fInitialId;
135     }
136     
137     protected String JavaDoc verifyVersion() {
138         String JavaDoc value = fFeatureVersionText.getText();
139         if (VersionUtil.validateVersion(value).getSeverity() != IStatus.OK)
140             return PDEUIMessages.NewFeatureWizard_SpecPage_versionFormat;
141         return null;
142     }
143
144     protected abstract String JavaDoc getFeatureId();
145     
146     protected String JavaDoc verifyIdRules() {
147         String JavaDoc id = getFeatureId();
148         if (id == null || id.length() == 0)
149             return PDEUIMessages.NewFeatureWizard_SpecPage_missing;
150         if (!IdUtil.isValidCompositeID(id)) {
151             return PDEUIMessages.NewFeatureWizard_SpecPage_invalidId;
152         }
153         return null;
154     }
155
156     public IFeatureModel getFeatureToPatch(){
157         return fFeatureToPatch;
158     }
159         
160     protected String JavaDoc getInstallHandlerLibrary() {
161         String JavaDoc library = fLibraryText.getText();
162         if (library == null || library.length() == 0)
163             return null;
164         if (!library.endsWith(".jar") && !library.endsWith("/") && !library.equals(".")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
165
library += "/"; //$NON-NLS-1$
166
return library;
167     }
168     
169     private void attachListeners() {
170         ModifyListener listener = new ModifyListener() {
171             public void modifyText(ModifyEvent e) {
172                 if (!fSelfModification) {
173                     fUpdateName = false;
174                     setPageComplete(validateBaseContent(true));
175                 }
176             }
177         };
178         attachListeners(listener);
179         fFeatureNameText.addModifyListener(listener);
180         fFeatureVersionText.addModifyListener(listener);
181         fLibraryText.addModifyListener(listener);
182     }
183     
184     public abstract FeatureData getFeatureData();
185 }
186
Popular Tags