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.jface.dialogs.IMessageProvider;
013: import org.eclipse.jface.window.Window;
014: import org.eclipse.jface.wizard.IWizardPage;
015: import org.eclipse.osgi.util.NLS;
016: import org.eclipse.pde.internal.core.PDECore;
017: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
018: import org.eclipse.pde.internal.core.util.IdUtil;
019: import org.eclipse.pde.internal.ui.IHelpContextIds;
020: import org.eclipse.pde.internal.ui.PDEUIMessages;
021: import org.eclipse.pde.internal.ui.util.SWTUtil;
022: import org.eclipse.pde.internal.ui.wizards.FeatureSelectionDialog;
023: import org.eclipse.swt.SWT;
024: import org.eclipse.swt.events.ModifyListener;
025: import org.eclipse.swt.events.SelectionAdapter;
026: import org.eclipse.swt.events.SelectionEvent;
027: import org.eclipse.swt.layout.GridData;
028: import org.eclipse.swt.layout.GridLayout;
029: import org.eclipse.swt.widgets.Button;
030: import org.eclipse.swt.widgets.Composite;
031: import org.eclipse.swt.widgets.Group;
032: import org.eclipse.swt.widgets.Label;
033: import org.eclipse.swt.widgets.Text;
034:
035: public class PatchSpecPage extends AbstractFeatureSpecPage {
036:
037: private Text fPatchProviderText;
038: private Button fBrowseButton;
039: private Text fPatchIdText;
040: private Text fPatchNameText;
041: private Text fFeatureIdText;
042:
043: public PatchSpecPage() {
044: super ();
045: setTitle(PDEUIMessages.PatchSpec_title);
046: setDescription(PDEUIMessages.NewFeatureWizard_SpecPage_desc);
047: }
048:
049: protected void initialize() {
050: String projectName = getProjectName();
051: if (fInitialId == null)
052: fPatchIdText.setText(IdUtil.getValidId(projectName));
053: if (fInitialName == null)
054: fPatchNameText.setText(projectName);
055: setMessage(PDEUIMessages.FeaturePatch_MainPage_desc);
056: }
057:
058: protected String validateContent() {
059: fFeatureToPatch = PDECore.getDefault().getFeatureModelManager()
060: .findFeatureModel(fFeatureIdText.getText(),
061: fFeatureVersionText.getText());
062: if (fFeatureToPatch != null) {
063: setMessage(null);
064: return null;
065: }
066:
067: setMessage(NLS
068: .bind(PDEUIMessages.NewFeaturePatch_SpecPage_notFound,
069: fFeatureIdText.getText(), fFeatureVersionText
070: .getText()), IMessageProvider.WARNING);
071: getContainer().updateButtons();
072: return null;
073: }
074:
075: /* (non-Javadoc)
076: * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
077: */
078: public IWizardPage getNextPage() {
079: if (fFeatureToPatch == null)
080: return null;
081: return super .getNextPage();
082: }
083:
084: private String getPatchId() {
085: if (fPatchIdText == null)
086: return ""; //$NON-NLS-1$
087: return fPatchIdText.getText();
088: }
089:
090: private String getPatchName() {
091: if (fPatchNameText == null)
092: return ""; //$NON-NLS-1$
093: return fPatchNameText.getText();
094: }
095:
096: private String getPatchProvider() {
097: if (fPatchProviderText == null)
098: return ""; //$NON-NLS-1$
099: return fPatchProviderText.getText();
100: }
101:
102: public FeatureData getFeatureData() {
103: FeatureData data = new FeatureData();
104: data.id = getPatchId();
105: data.version = "1.0.0"; //$NON-NLS-1$
106: data.provider = getPatchProvider();
107: data.name = getPatchName();
108: data.library = getInstallHandlerLibrary();
109: data.isPatch = true;
110: data.featureToPatchId = fFeatureIdText.getText();
111: data.featureToPatchVersion = fFeatureVersionText.getText();
112: return data;
113: }
114:
115: protected String verifyIdRules() {
116: String id = fPatchIdText.getText();
117: if (id == null || id.length() == 0)
118: return PDEUIMessages.NewFeatureWizard_SpecPage_pmissing;
119: if (!IdUtil.isValidCompositeID(id)) {
120: return PDEUIMessages.NewFeatureWizard_SpecPage_invalidId;
121: }
122: return super .verifyIdRules();
123: }
124:
125: protected String getHelpId() {
126: return IHelpContextIds.NEW_PATCH_REQUIRED_DATA;
127: }
128:
129: protected void createTopGroup(Composite container) {
130: Group patchGroup = new Group(container, SWT.NULL);
131: patchGroup.setLayout(new GridLayout(2, false));
132: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
133: gd.verticalIndent = 10;
134: patchGroup.setLayoutData(gd);
135: patchGroup
136: .setText(PDEUIMessages.NewFeatureWizard_SpecPage_patchProperties);
137: Label label = new Label(patchGroup, SWT.NULL);
138: label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_id);
139: fPatchIdText = new Text(patchGroup, SWT.BORDER);
140: fPatchIdText.setLayoutData(new GridData(
141: GridData.FILL_HORIZONTAL));
142:
143: label = new Label(patchGroup, SWT.NULL);
144: label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_name);
145: fPatchNameText = new Text(patchGroup, SWT.BORDER);
146: fPatchNameText.setLayoutData(new GridData(
147: GridData.FILL_HORIZONTAL));
148:
149: label = new Label(patchGroup, SWT.NULL);
150: label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_provider);
151: fPatchProviderText = new Text(patchGroup, SWT.BORDER);
152: fPatchProviderText.setLayoutData(new GridData(
153: GridData.FILL_HORIZONTAL));
154:
155: createInstallHandlerText(patchGroup);
156: }
157:
158: protected void createContents(Composite container) {
159:
160: createTopGroup(container);
161:
162: Group group = new Group(container, SWT.NULL);
163: group.setLayout(new GridLayout(2, false));
164: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
165: gd.verticalIndent = 10;
166: group.setLayoutData(gd);
167: group
168: .setText(PDEUIMessages.BaseFeatureSpecPage_patchGroup_title);
169:
170: Label label = new Label(group, SWT.NULL);
171: label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_id);
172:
173: Composite patchcontainer = new Composite(group, SWT.NULL);
174: GridLayout layout = new GridLayout(2, false);
175: layout.marginHeight = layout.marginWidth = 0;
176: layout.horizontalSpacing = 5;
177: patchcontainer.setLayout(layout);
178: patchcontainer.setLayoutData(new GridData(
179: GridData.FILL_HORIZONTAL));
180:
181: fFeatureIdText = new Text(patchcontainer, SWT.BORDER);
182: fFeatureIdText.setLayoutData(new GridData(
183: GridData.FILL_HORIZONTAL));
184:
185: fBrowseButton = new Button(patchcontainer, SWT.PUSH);
186: fBrowseButton.setText(PDEUIMessages.BaseFeatureSpecPage_browse);
187: fBrowseButton.setLayoutData(new GridData(
188: GridData.HORIZONTAL_ALIGN_END));
189: fBrowseButton.addSelectionListener(new SelectionAdapter() {
190:
191: public void widgetSelected(SelectionEvent e) {
192: FeatureSelectionDialog dialog = new FeatureSelectionDialog(
193: getShell(), PDECore.getDefault()
194: .getFeatureModelManager().getModels(),
195: false);
196: dialog.create();
197: if (dialog.open() == Window.OK) {
198: Object[] result = dialog.getResult();
199: IFeatureModel selectedModel = (IFeatureModel) result[0];
200:
201: // block auto validation till last setText
202: fSelfModification = true;
203: fFeatureIdText.setText(selectedModel.getFeature()
204: .getId());
205: fFeatureNameText.setText(selectedModel.getFeature()
206: .getLabel());
207: fSelfModification = false;
208: fFeatureVersionText.setText(selectedModel
209: .getFeature().getVersion());
210:
211: fFeatureToPatch = selectedModel;
212: }
213: }
214: });
215: SWTUtil.setButtonDimensionHint(fBrowseButton);
216:
217: createCommonInput(group);
218: }
219:
220: protected void attachListeners(ModifyListener listener) {
221: fPatchIdText.addModifyListener(listener);
222: fPatchNameText.addModifyListener(listener);
223: fPatchProviderText.addModifyListener(listener);
224: fFeatureIdText.addModifyListener(listener);
225: }
226:
227: protected String getFeatureId() {
228: return fFeatureIdText.getText();
229: }
230:
231: protected void updateNameRelativeFields() {
232: if (fPatchIdText == null || fPatchNameText == null)
233: return;
234: fSelfModification = true;
235: String id = IdUtil.getValidId(getProjectName());
236: fPatchIdText.setText(id);
237: fPatchNameText.setText(IdUtil.getValidName(id,
238: PDEUIMessages.PatchSpecPage_feature));
239: fPatchProviderText.setText(IdUtil.getValidProvider(id));
240: fSelfModification = false;
241: }
242: }
|