001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.feature;
011:
012: import org.eclipse.core.runtime.IStatus;
013: import org.eclipse.jface.dialogs.Dialog;
014: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
015: import org.eclipse.pde.internal.core.util.IdUtil;
016: import org.eclipse.pde.internal.core.util.VersionUtil;
017: import org.eclipse.pde.internal.ui.PDEUIMessages;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.events.ModifyEvent;
020: import org.eclipse.swt.events.ModifyListener;
021: import org.eclipse.swt.layout.GridData;
022: import org.eclipse.swt.widgets.Composite;
023: import org.eclipse.swt.widgets.Label;
024: import org.eclipse.swt.widgets.Text;
025: import org.eclipse.ui.PlatformUI;
026: import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
027:
028: public abstract class AbstractFeatureSpecPage extends
029: WizardNewProjectCreationPage {
030:
031: protected Text fFeatureNameText;
032: protected Text fFeatureVersionText;
033: protected Text fLibraryText;
034: protected String fInitialId;
035: protected String fInitialName;
036: protected IFeatureModel fFeatureToPatch;
037: protected boolean fSelfModification;
038: private boolean fUpdateName = true;
039:
040: public AbstractFeatureSpecPage() {
041: super ("specPage"); //$NON-NLS-1$
042: }
043:
044: public void createControl(Composite parent) {
045: super .createControl(parent);
046: Composite comp = (Composite) getControl();
047:
048: createContents(comp);
049:
050: initialize();
051: attachListeners();
052:
053: Dialog.applyDialogFont(comp);
054: PlatformUI.getWorkbench().getHelpSystem().setHelp(comp,
055: getHelpId());
056: }
057:
058: protected abstract void createContents(Composite container);
059:
060: protected abstract void initialize();
061:
062: protected abstract void attachListeners(ModifyListener listener);
063:
064: protected abstract String getHelpId();
065:
066: protected void createCommonInput(Composite common) {
067: Label label = new Label(common, SWT.NULL);
068: label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_name);
069: fFeatureNameText = new Text(common, SWT.BORDER);
070: fFeatureNameText.setLayoutData(new GridData(
071: GridData.FILL_HORIZONTAL));
072:
073: label = new Label(common, SWT.NULL);
074: label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_version);
075: fFeatureVersionText = new Text(common, SWT.BORDER);
076: fFeatureVersionText.setLayoutData(new GridData(
077: GridData.FILL_HORIZONTAL));
078: }
079:
080: protected void createInstallHandlerText(Composite parent) {
081: Label libraryLabel = new Label(parent, SWT.NULL);
082: libraryLabel
083: .setText(PDEUIMessages.NewFeatureWizard_SpecPage_library);
084: fLibraryText = new Text(parent, SWT.SINGLE | SWT.BORDER);
085: fLibraryText.setLayoutData(new GridData(
086: GridData.FILL_HORIZONTAL));
087: }
088:
089: protected abstract void updateNameRelativeFields();
090:
091: protected boolean validatePage() {
092: boolean valid = super .validatePage();
093: if (!valid)
094: return valid;
095: if (fUpdateName)
096: updateNameRelativeFields();
097: return validateBaseContent(false);
098: }
099:
100: private boolean validateBaseContent(boolean validateSuper) {
101: if (validateSuper && !super .validatePage())
102: return false;
103: if (!setValidationMessage(verifyIdRules()))
104: return false;
105: if (!setValidationMessage(verifyVersion()))
106: return false;
107: if (!setValidationMessage(validateContent()))
108: return false;
109:
110: setPageComplete(true);
111: setErrorMessage(null);
112: return true;
113: }
114:
115: private boolean setValidationMessage(String message) {
116: if (message == null)
117: return true;
118: setPageComplete(false);
119: setErrorMessage(message);
120: return false;
121: }
122:
123: protected abstract String validateContent();
124:
125: public String getInitialName() {
126: return fInitialName;
127: }
128:
129: public void setInitialName(String initialName) {
130: fInitialName = initialName;
131: }
132:
133: public void setInitialId(String initialId) {
134: fInitialId = initialId;
135: }
136:
137: public String getInitialId() {
138: return fInitialId;
139: }
140:
141: protected String verifyVersion() {
142: String value = fFeatureVersionText.getText();
143: if (VersionUtil.validateVersion(value).getSeverity() != IStatus.OK)
144: return PDEUIMessages.NewFeatureWizard_SpecPage_versionFormat;
145: return null;
146: }
147:
148: protected abstract String getFeatureId();
149:
150: protected String verifyIdRules() {
151: String id = getFeatureId();
152: if (id == null || id.length() == 0)
153: return PDEUIMessages.NewFeatureWizard_SpecPage_missing;
154: if (!IdUtil.isValidCompositeID(id)) {
155: return PDEUIMessages.NewFeatureWizard_SpecPage_invalidId;
156: }
157: return null;
158: }
159:
160: public IFeatureModel getFeatureToPatch() {
161: return fFeatureToPatch;
162: }
163:
164: protected String getInstallHandlerLibrary() {
165: String library = fLibraryText.getText();
166: if (library == null || library.length() == 0)
167: return null;
168: if (!library.endsWith(".jar") && !library.endsWith("/") && !library.equals(".")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
169: library += "/"; //$NON-NLS-1$
170: return library;
171: }
172:
173: private void attachListeners() {
174: ModifyListener listener = new ModifyListener() {
175: public void modifyText(ModifyEvent e) {
176: if (!fSelfModification) {
177: fUpdateName = false;
178: setPageComplete(validateBaseContent(true));
179: }
180: }
181: };
182: attachListeners(listener);
183: fFeatureNameText.addModifyListener(listener);
184: fFeatureVersionText.addModifyListener(listener);
185: fLibraryText.addModifyListener(listener);
186: }
187:
188: public abstract FeatureData getFeatureData();
189: }
|