001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.plugin;
011:
012: import org.eclipse.core.runtime.IStatus;
013: import org.eclipse.jface.dialogs.Dialog;
014: import org.eclipse.jface.viewers.IStructuredSelection;
015: import org.eclipse.jface.wizard.IWizardPage;
016: import org.eclipse.pde.internal.core.ICoreConstants;
017: import org.eclipse.pde.internal.core.TargetPlatformHelper;
018: import org.eclipse.pde.internal.core.util.IdUtil;
019: import org.eclipse.pde.internal.core.util.VersionUtil;
020: import org.eclipse.pde.internal.ui.IHelpContextIds;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022: import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
023: import org.eclipse.swt.SWT;
024: import org.eclipse.swt.events.ModifyEvent;
025: import org.eclipse.swt.events.ModifyListener;
026: import org.eclipse.swt.events.SelectionAdapter;
027: import org.eclipse.swt.events.SelectionEvent;
028: import org.eclipse.swt.layout.GridData;
029: import org.eclipse.swt.layout.GridLayout;
030: import org.eclipse.swt.widgets.Button;
031: import org.eclipse.swt.widgets.Combo;
032: import org.eclipse.swt.widgets.Composite;
033: import org.eclipse.swt.widgets.Group;
034: import org.eclipse.swt.widgets.Label;
035: import org.eclipse.swt.widgets.Text;
036: import org.eclipse.ui.PlatformUI;
037: import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
038:
039: public class NewLibraryPluginCreationPage extends
040: WizardNewProjectCreationPage {
041:
042: class PropertiesListener implements ModifyListener {
043: private boolean fBlocked = false;
044:
045: private boolean fChanged = false;
046:
047: public boolean isChanged() {
048: return fChanged;
049: }
050:
051: public void modifyText(ModifyEvent e) {
052: if (!fBlocked) {
053: fChanged = true;
054: setPageComplete(validatePage());
055: }
056: }
057:
058: public void setBlocked(boolean blocked) {
059: this .fBlocked = blocked;
060: }
061: }
062:
063: private LibraryPluginFieldData fData;
064: protected NewLibraryPluginCreationPage fMainPage;
065: protected IProjectProvider fProjectProvider;
066: protected PropertiesListener fPropertiesListener = new PropertiesListener();
067: protected Text fIdText;
068: protected Text fNameText;
069: protected Text fProviderText;
070: protected Text fVersionText;
071: private Button fEclipseButton;
072: private Button fOSGIButton;
073: private Combo fOSGiCombo;
074: private Combo fTargetCombo;
075: protected Button fJarredCheck;
076: protected Button fFindDependencies;
077: private IStructuredSelection fSelection;
078:
079: public NewLibraryPluginCreationPage(String pageName,
080: LibraryPluginFieldData data, IStructuredSelection selection) {
081: super (pageName);
082: fData = data;
083: fSelection = selection;
084: setTitle(PDEUIMessages.NewLibraryPluginCreationPage_title);
085: setDescription(PDEUIMessages.NewLibraryPluginCreationPage_desc);
086: }
087:
088: public void createControl(Composite parent) {
089: super .createControl(parent);
090: Composite control = (Composite) getControl();
091: GridLayout layout = new GridLayout();
092: layout.verticalSpacing = 10;
093: control.setLayout(layout);
094:
095: createPluginPropertiesGroup(control);
096:
097: createFormatGroup(control);
098:
099: createWorkingSetGroup(control, fSelection, new String[] {
100: "org.eclipse.jdt.ui.JavaWorkingSetPage", //$NON-NLS-1$
101: "org.eclipse.pde.ui.pluginWorkingSet", //$NON-NLS-1$
102: "org.eclipse.ui.resourceWorkingSetPage" }); //$NON-NLS-1$
103:
104: updateRuntimeDependency();
105:
106: Dialog.applyDialogFont(control);
107: PlatformUI.getWorkbench().getHelpSystem().setHelp(control,
108: IHelpContextIds.NEW_LIBRARY_PROJECT_STRUCTURE_PAGE);
109: setControl(control);
110: }
111:
112: private void createFormatGroup(Composite container) {
113: Group group = new Group(container, SWT.NONE);
114: group.setText(PDEUIMessages.NewProjectCreationPage_target);
115: group.setLayout(new GridLayout(2, false));
116: group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
117:
118: Label label = new Label(group, SWT.NONE);
119: label.setText(PDEUIMessages.NewProjectCreationPage_ptarget);
120: GridData gd = new GridData();
121: gd.horizontalSpan = 2;
122: label.setLayoutData(gd);
123:
124: fEclipseButton = createButton(group, SWT.RADIO, 1, 30);
125: fEclipseButton
126: .setText(PDEUIMessages.NewProjectCreationPage_pDependsOnRuntime);
127: fEclipseButton.setSelection(fData.getOSGiFramework() == null);
128: fEclipseButton.addSelectionListener(new SelectionAdapter() {
129: public void widgetSelected(SelectionEvent e) {
130: updateRuntimeDependency();
131: }
132: });
133:
134: fTargetCombo = new Combo(group, SWT.READ_ONLY | SWT.SINGLE);
135: fTargetCombo.setItems(new String[] { ICoreConstants.TARGET33,
136: ICoreConstants.TARGET32, ICoreConstants.TARGET31,
137: ICoreConstants.TARGET30 });
138: fTargetCombo.setText(TargetPlatformHelper
139: .getTargetVersionString());
140:
141: fOSGIButton = createButton(group, SWT.RADIO, 1, 30);
142: fOSGIButton
143: .setText(PDEUIMessages.NewProjectCreationPage_pPureOSGi);
144: fOSGIButton.setSelection(fData.getOSGiFramework() != null);
145:
146: fOSGiCombo = new Combo(group, SWT.READ_ONLY | SWT.SINGLE);
147: fOSGiCombo.setItems(new String[] { ICoreConstants.EQUINOX,
148: PDEUIMessages.NewProjectCreationPage_standard });
149: fOSGiCombo.setText(ICoreConstants.EQUINOX);
150:
151: fJarredCheck = new Button(group, SWT.CHECK);
152: fJarredCheck
153: .setText(PDEUIMessages.NewLibraryPluginCreationPage_jarred);
154: gd = new GridData();
155: gd.horizontalSpan = 2;
156: fJarredCheck.setLayoutData(gd);
157: fJarredCheck.setSelection(Double.parseDouble(fTargetCombo
158: .getText()) >= 3.1);
159: }
160:
161: private void createPluginPropertiesGroup(Composite container) {
162: Group propertiesGroup = new Group(container, SWT.NONE);
163: propertiesGroup.setLayout(new GridLayout(2, false));
164: propertiesGroup.setLayoutData(new GridData(
165: GridData.FILL_HORIZONTAL));
166: propertiesGroup
167: .setText(PDEUIMessages.NewLibraryPluginCreationPage_pGroup);
168:
169: Label label = new Label(propertiesGroup, SWT.NONE);
170: label.setText(PDEUIMessages.NewLibraryPluginCreationPage_pid);
171: fIdText = createText(propertiesGroup, fPropertiesListener);
172:
173: label = new Label(propertiesGroup, SWT.NONE);
174: label
175: .setText(PDEUIMessages.NewLibraryPluginCreationPage_pversion);
176: fVersionText = createText(propertiesGroup, fPropertiesListener);
177: fPropertiesListener.setBlocked(true);
178: fVersionText.setText("1.0.0"); //$NON-NLS-1$
179: fPropertiesListener.setBlocked(false);
180:
181: label = new Label(propertiesGroup, SWT.NONE);
182: label.setText(PDEUIMessages.NewLibraryPluginCreationPage_pname);
183: fNameText = createText(propertiesGroup, fPropertiesListener);
184:
185: label = new Label(propertiesGroup, SWT.NONE);
186: label
187: .setText(PDEUIMessages.NewLibraryPluginCreationPage_pprovider);
188: fProviderText = createText(propertiesGroup, fPropertiesListener);
189:
190: fFindDependencies = new Button(propertiesGroup, SWT.CHECK);
191: fFindDependencies
192: .setText(PDEUIMessages.NewLibraryPluginCreationPage_pdependencies);
193: GridData data = new GridData(GridData.FILL_HORIZONTAL);
194: data.horizontalSpan = 2;
195: fFindDependencies.setLayoutData(data);
196: }
197:
198: protected Text createText(Composite parent, ModifyListener listener) {
199: Text text = new Text(parent, SWT.BORDER | SWT.SINGLE);
200: text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
201: text.addModifyListener(listener);
202: return text;
203: }
204:
205: protected String getNameFieldQualifier() {
206: return PDEUIMessages.NewLibraryPluginCreationPage_plugin;
207: }
208:
209: /*
210: * (non-Javadoc)
211: *
212: * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
213: */
214: public IWizardPage getNextPage() {
215: updateData();
216: return super .getNextPage();
217: }
218:
219: protected boolean isVersionValid(String version) {
220: return VersionUtil.validateVersion(version).getSeverity() == IStatus.OK;
221: }
222:
223: public void updateData() {
224: fData.setSimple(false);
225: fData.setSourceFolderName(null);
226: fData.setOutputFolderName(null);
227: fData.setLegacy(false);
228: fData.setTargetVersion(fTargetCombo.getText());
229:
230: fData.setId(fIdText.getText().trim());
231: fData.setVersion(fVersionText.getText().trim());
232: fData.setName(fNameText.getText().trim());
233: fData.setProvider(fProviderText.getText().trim());
234: fData.setLibraryName(null);
235: fData.setHasBundleStructure(fOSGIButton.getSelection()
236: || Double.parseDouble(fTargetCombo.getText()) >= 3.1);
237: fData.setOSGiFramework(fOSGIButton.getSelection() ? fOSGiCombo
238: .getText() : null);
239: fData.setUnzipLibraries(fJarredCheck.isEnabled()
240: && fJarredCheck.getSelection());
241: fData.setFindDependencies(fFindDependencies.getSelection());
242: fData.setWorkingSets(getSelectedWorkingSets());
243:
244: PluginFieldData data = fData;
245: data.setClassname(null);
246: data.setUIPlugin(false);
247: data.setDoGenerateClass(false);
248: data.setRCPApplicationPlugin(false);
249: }
250:
251: private String validateId() {
252: String id = fIdText.getText().trim();
253: if (id.length() == 0)
254: return PDEUIMessages.NewLibraryPluginCreationPage_noid;
255:
256: if (!IdUtil.isValidCompositeID(id)) {
257: return PDEUIMessages.NewLibraryPluginCreationPage_invalidId;
258: }
259: return null;
260: }
261:
262: protected boolean validatePage() {
263: String id = IdUtil.getValidId(getProjectName());
264: // properties group
265: if (!fPropertiesListener.isChanged() && fIdText != null) {
266: fPropertiesListener.setBlocked(true);
267: fIdText.setText(id);
268: fNameText.setText(IdUtil.getValidName(id,
269: getNameFieldQualifier()));
270: fPropertiesListener.setBlocked(false);
271: }
272:
273: if (!super .validatePage())
274: return false;
275: setMessage(null);
276: String errorMessage = validateProperties();
277: setErrorMessage(errorMessage);
278: return errorMessage == null;
279: }
280:
281: protected String validateProperties() {
282: String errorMessage = validateId();
283: if (errorMessage != null)
284: return errorMessage;
285:
286: if (fVersionText.getText().trim().length() == 0) {
287: errorMessage = PDEUIMessages.NewLibraryPluginCreationPage_noversion;
288: } else if (!isVersionValid(fVersionText.getText().trim())) {
289: errorMessage = PDEUIMessages.ContentPage_badversion;
290: } else if (fNameText.getText().trim().length() == 0) {
291: errorMessage = PDEUIMessages.NewLibraryPluginCreationPage_noname;
292: }
293:
294: if (errorMessage != null)
295: return errorMessage;
296:
297: return errorMessage;
298: }
299:
300: private void updateRuntimeDependency() {
301: boolean depends = fEclipseButton.getSelection();
302: fTargetCombo.setEnabled(depends);
303: fOSGiCombo.setEnabled(!depends);
304: }
305:
306: private Button createButton(Composite container, int style,
307: int span, int indent) {
308: Button button = new Button(container, style);
309: GridData gd = new GridData();
310: gd.horizontalSpan = span;
311: gd.horizontalIndent = indent;
312: button.setLayoutData(gd);
313: return button;
314: }
315: }
|