KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > plugin > NewLibraryPluginCreationPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.pde.internal.ui.wizards.plugin;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.wizard.IWizardPage;
16 import org.eclipse.pde.internal.core.ICoreConstants;
17 import org.eclipse.pde.internal.core.TargetPlatformHelper;
18 import org.eclipse.pde.internal.core.util.IdUtil;
19 import org.eclipse.pde.internal.core.util.VersionUtil;
20 import org.eclipse.pde.internal.ui.IHelpContextIds;
21 import org.eclipse.pde.internal.ui.PDEUIMessages;
22 import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.ModifyEvent;
25 import org.eclipse.swt.events.ModifyListener;
26 import org.eclipse.swt.events.SelectionAdapter;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Combo;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Group;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.swt.widgets.Text;
36 import org.eclipse.ui.PlatformUI;
37 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
38
39 public class NewLibraryPluginCreationPage extends WizardNewProjectCreationPage {
40
41     class PropertiesListener implements ModifyListener {
42         private boolean fBlocked = false;
43
44         private boolean fChanged = false;
45
46         public boolean isChanged() {
47             return fChanged;
48         }
49
50         public void modifyText(ModifyEvent e) {
51             if (!fBlocked) {
52                 fChanged = true;
53                 setPageComplete(validatePage());
54             }
55         }
56
57         public void setBlocked(boolean blocked) {
58             this.fBlocked = blocked;
59         }
60     }
61
62     private LibraryPluginFieldData fData;
63     protected NewLibraryPluginCreationPage fMainPage;
64     protected IProjectProvider fProjectProvider;
65     protected PropertiesListener fPropertiesListener = new PropertiesListener();
66     protected Text fIdText;
67     protected Text fNameText;
68     protected Text fProviderText;
69     protected Text fVersionText;
70     private Button fEclipseButton;
71     private Button fOSGIButton;
72     private Combo fOSGiCombo;
73     private Combo fTargetCombo;
74     protected Button fJarredCheck;
75     protected Button fFindDependencies;
76
77     public NewLibraryPluginCreationPage(String JavaDoc pageName, LibraryPluginFieldData data) {
78         super(pageName);
79         fData = data;
80         setTitle(PDEUIMessages.NewLibraryPluginCreationPage_title);
81         setDescription(PDEUIMessages.NewLibraryPluginCreationPage_desc);
82     }
83
84     public void createControl(Composite parent) {
85         super.createControl(parent);
86         Composite control = (Composite) getControl();
87         GridLayout layout = new GridLayout();
88         layout.verticalSpacing = 10;
89         control.setLayout(layout);
90
91         createPluginPropertiesGroup(control);
92
93         createFormatGroup(control);
94         
95         updateRuntimeDependency();
96
97         Dialog.applyDialogFont(control);
98         PlatformUI.getWorkbench().getHelpSystem().setHelp(control,
99                 IHelpContextIds.NEW_LIBRARY_PROJECT_STRUCTURE_PAGE);
100         setControl(control);
101     }
102
103     private void createFormatGroup(Composite container) {
104         Group group = new Group(container, SWT.NONE);
105         group.setText(PDEUIMessages.NewProjectCreationPage_target);
106         group.setLayout(new GridLayout(2, false));
107         group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
108         
109         Label label = new Label(group, SWT.NONE);
110         label.setText(PDEUIMessages.NewProjectCreationPage_ptarget);
111         GridData gd = new GridData();
112         gd.horizontalSpan = 2;
113         label.setLayoutData(gd);
114             
115         fEclipseButton = createButton(group, SWT.RADIO, 1, 30);
116         fEclipseButton.setText(PDEUIMessages.NewProjectCreationPage_pDependsOnRuntime);
117         fEclipseButton.setSelection(fData.getOSGiFramework() == null);
118         fEclipseButton.addSelectionListener(new SelectionAdapter(){
119             public void widgetSelected(SelectionEvent e) {
120                 updateRuntimeDependency();
121             }
122         });
123         
124         fTargetCombo = new Combo(group, SWT.READ_ONLY|SWT.SINGLE);
125         fTargetCombo.setItems(new String JavaDoc[] {ICoreConstants.TARGET33, ICoreConstants.TARGET32, ICoreConstants.TARGET31, ICoreConstants.TARGET30});
126         fTargetCombo.setText(TargetPlatformHelper.getTargetVersionString());
127         
128         fOSGIButton = createButton(group, SWT.RADIO, 1, 30);
129         fOSGIButton.setText(PDEUIMessages.NewProjectCreationPage_pPureOSGi);
130         fOSGIButton.setSelection(fData.getOSGiFramework() != null);
131         
132         fOSGiCombo = new Combo(group, SWT.READ_ONLY|SWT.SINGLE);
133         fOSGiCombo.setItems(new String JavaDoc[] {ICoreConstants.EQUINOX, PDEUIMessages.NewProjectCreationPage_standard});
134         fOSGiCombo.setText(ICoreConstants.EQUINOX);
135         
136         fJarredCheck = new Button(group, SWT.CHECK);
137         fJarredCheck.setText(PDEUIMessages.NewLibraryPluginCreationPage_jarred);
138         gd = new GridData();
139         gd.horizontalSpan = 2;
140         fJarredCheck.setLayoutData(gd);
141         fJarredCheck.setSelection(Double.parseDouble(fTargetCombo.getText()) >= 3.1);
142     }
143     
144     private void createPluginPropertiesGroup(Composite container) {
145         Group propertiesGroup = new Group(container, SWT.NONE);
146         propertiesGroup.setLayout(new GridLayout(2, false));
147         propertiesGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
148         propertiesGroup.setText(PDEUIMessages.NewLibraryPluginCreationPage_pGroup);
149
150         Label label = new Label(propertiesGroup, SWT.NONE);
151         label.setText(PDEUIMessages.NewLibraryPluginCreationPage_pid);
152         fIdText = createText(propertiesGroup, fPropertiesListener);
153
154         label = new Label(propertiesGroup, SWT.NONE);
155         label.setText(PDEUIMessages.NewLibraryPluginCreationPage_pversion);
156         fVersionText = createText(propertiesGroup, fPropertiesListener);
157         fPropertiesListener.setBlocked(true);
158         fVersionText.setText("1.0.0"); //$NON-NLS-1$
159
fPropertiesListener.setBlocked(false);
160
161         label = new Label(propertiesGroup, SWT.NONE);
162         label.setText(PDEUIMessages.NewLibraryPluginCreationPage_pname);
163         fNameText = createText(propertiesGroup, fPropertiesListener);
164
165         label = new Label(propertiesGroup, SWT.NONE);
166         label.setText(PDEUIMessages.NewLibraryPluginCreationPage_pprovider);
167         fProviderText = createText(propertiesGroup, fPropertiesListener);
168         
169         fFindDependencies = new Button(propertiesGroup, SWT.CHECK);
170         fFindDependencies.setText(PDEUIMessages.NewLibraryPluginCreationPage_pdependencies);
171         GridData data = new GridData(GridData.FILL_HORIZONTAL);
172         data.horizontalSpan = 2;
173         fFindDependencies.setLayoutData(data);
174     }
175
176     protected Text createText(Composite parent, ModifyListener listener) {
177         Text text = new Text(parent, SWT.BORDER | SWT.SINGLE);
178         text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
179         text.addModifyListener(listener);
180         return text;
181     }
182
183     protected String JavaDoc getNameFieldQualifier() {
184         return PDEUIMessages.NewLibraryPluginCreationPage_plugin;
185     }
186
187     /*
188      * (non-Javadoc)
189      *
190      * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
191      */

192     public IWizardPage getNextPage() {
193         updateData();
194         return super.getNextPage();
195     }
196
197     protected boolean isVersionValid(String JavaDoc version) {
198         return VersionUtil.validateVersion(version).getSeverity() == IStatus.OK;
199     }
200
201     public void updateData() {
202         fData.setSimple(false);
203         fData.setSourceFolderName(null);
204         fData.setOutputFolderName(null);
205         fData.setLegacy(false);
206         fData.setTargetVersion(fTargetCombo.getText());
207
208         fData.setId(fIdText.getText().trim());
209         fData.setVersion(fVersionText.getText().trim());
210         fData.setName(fNameText.getText().trim());
211         fData.setProvider(fProviderText.getText().trim());
212         fData.setLibraryName(null);
213         fData.setHasBundleStructure(fOSGIButton.getSelection() || Double.parseDouble(fTargetCombo.getText()) >= 3.1);
214         fData.setOSGiFramework(fOSGIButton.getSelection() ? fOSGiCombo.getText() : null);
215         fData.setUnzipLibraries(fJarredCheck.isEnabled()
216                 && fJarredCheck.getSelection());
217         fData.setFindDependencies(fFindDependencies.getSelection());
218         
219         PluginFieldData data = fData;
220         data.setClassname(null);
221         data.setUIPlugin(false);
222         data.setDoGenerateClass(false);
223         data.setRCPApplicationPlugin(false);
224     }
225
226     private String JavaDoc validateId() {
227         String JavaDoc id = fIdText.getText().trim();
228         if (id.length() == 0)
229             return PDEUIMessages.NewLibraryPluginCreationPage_noid;
230
231         if (!IdUtil.isValidCompositeID(id)) {
232             return PDEUIMessages.NewLibraryPluginCreationPage_invalidId;
233         }
234         return null;
235     }
236
237     protected boolean validatePage() {
238         String JavaDoc id = IdUtil.getValidId(getProjectName());
239         // properties group
240
if (!fPropertiesListener.isChanged() && fIdText != null) {
241             fPropertiesListener.setBlocked(true);
242             fIdText.setText(id);
243             fNameText.setText(IdUtil.getValidName(id, getNameFieldQualifier()));
244             fPropertiesListener.setBlocked(false);
245         }
246
247         if (!super.validatePage())
248             return false;
249         setMessage(null);
250         String JavaDoc errorMessage = validateProperties();
251         setErrorMessage(errorMessage);
252         return errorMessage == null;
253     }
254
255     protected String JavaDoc validateProperties() {
256         String JavaDoc errorMessage = validateId();
257         if (errorMessage != null)
258             return errorMessage;
259
260         if (fVersionText.getText().trim().length() == 0) {
261             errorMessage = PDEUIMessages.NewLibraryPluginCreationPage_noversion;
262         } else if (!isVersionValid(fVersionText.getText().trim())) {
263             errorMessage = PDEUIMessages.ContentPage_badversion;
264         } else if (fNameText.getText().trim().length() == 0) {
265             errorMessage = PDEUIMessages.NewLibraryPluginCreationPage_noname;
266         }
267
268         if (errorMessage != null)
269             return errorMessage;
270
271         return errorMessage;
272     }
273     
274     private void updateRuntimeDependency() {
275         boolean depends = fEclipseButton.getSelection();
276         fTargetCombo.setEnabled(depends);
277         fOSGiCombo.setEnabled(!depends);
278     }
279     
280     private Button createButton(Composite container, int style, int span, int indent) {
281         Button button = new Button(container, style);
282         GridData gd = new GridData();
283         gd.horizontalSpan = span;
284         gd.horizontalIndent = indent;
285         button.setLayoutData(gd);
286         return button;
287     }
288 }
289
Popular Tags