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.feature;
011:
012: import java.lang.reflect.InvocationTargetException;
013:
014: import org.eclipse.core.resources.IProject;
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.core.runtime.IConfigurationElement;
017: import org.eclipse.core.runtime.IExecutableExtension;
018: import org.eclipse.core.runtime.IPath;
019: import org.eclipse.debug.core.ILaunchConfiguration;
020: import org.eclipse.jface.dialogs.IDialogSettings;
021: import org.eclipse.jface.operation.IRunnableWithProgress;
022: import org.eclipse.jface.wizard.IWizardPage;
023: import org.eclipse.pde.core.plugin.IPluginBase;
024: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
025: import org.eclipse.pde.internal.ui.PDEPlugin;
026: import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
027: import org.eclipse.pde.internal.ui.wizards.NewWizard;
028: import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
029:
030: public abstract class AbstractNewFeatureWizard extends NewWizard
031: implements IExecutableExtension {
032:
033: public static final String DEF_PROJECT_NAME = "project-name"; //$NON-NLS-1$
034: public static final String DEF_FEATURE_ID = "feature-id"; //$NON-NLS-1$
035: public static final String DEF_FEATURE_NAME = "feature-name"; //$NON-NLS-1$
036:
037: protected AbstractFeatureSpecPage fSpecPage;
038: protected PluginListPage fSecondPage;
039: protected FeaturePatchProvider fProvider;
040: private IConfigurationElement fConfig;
041:
042: public class FeaturePatchProvider implements IProjectProvider {
043: public FeaturePatchProvider() {
044: super ();
045: }
046:
047: public String getProjectName() {
048: return fSpecPage.getProjectName();
049: }
050:
051: public IProject getProject() {
052: return fSpecPage.getProjectHandle();
053: }
054:
055: public IPath getLocationPath() {
056: return fSpecPage.getLocationPath();
057: }
058:
059: public IFeatureModel getFeatureToPatch() {
060: return fSpecPage.getFeatureToPatch();
061: }
062:
063: public FeatureData getFeatureData() {
064: return fSpecPage.getFeatureData();
065: }
066:
067: public String getInstallHandlerLibrary() {
068: return fSpecPage.getInstallHandlerLibrary();
069: }
070:
071: public IPluginBase[] getPluginListSelection() {
072: return fSecondPage != null ? fSecondPage
073: .getSelectedPlugins() : null;
074: }
075:
076: public ILaunchConfiguration getLaunchConfiguration() {
077: return fSecondPage != null ? fSecondPage
078: .getSelectedLaunchConfiguration() : null;
079: }
080: }
081:
082: public AbstractNewFeatureWizard() {
083: super ();
084: setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
085: setNeedsProgressMonitor(true);
086: }
087:
088: public void addPages() {
089: fSpecPage = createFirstPage();
090: String pname = getDefaultValue(DEF_PROJECT_NAME);
091: if (pname != null)
092: fSpecPage.setInitialProjectName(pname);
093:
094: fSpecPage.setInitialId(getDefaultValue(DEF_FEATURE_ID));
095: fSpecPage.setInitialName(getDefaultValue(DEF_FEATURE_NAME));
096: addPage(fSpecPage);
097:
098: fProvider = new FeaturePatchProvider();
099: }
100:
101: protected abstract AbstractFeatureSpecPage createFirstPage();
102:
103: public boolean canFinish() {
104: IWizardPage page = getContainer().getCurrentPage();
105: return ((page == fSpecPage && page.isPageComplete()) || (page == fSecondPage && page
106: .isPageComplete()));
107: }
108:
109: // get creation operation
110: protected abstract IRunnableWithProgress getOperation();
111:
112: public boolean performFinish() {
113: try {
114: IDialogSettings settings = getDialogSettings();
115: if (settings != null && fSecondPage != null)
116: fSecondPage.saveSettings(settings);
117:
118: getContainer().run(false, true, getOperation());
119: BasicNewProjectResourceWizard.updatePerspective(fConfig);
120: } catch (InvocationTargetException e) {
121: PDEPlugin.logException(e);
122: return false;
123: } catch (InterruptedException e) {
124: return false;
125: }
126: return true;
127: }
128:
129: public void setInitializationData(IConfigurationElement config,
130: String property, Object data) throws CoreException {
131: this.fConfig = config;
132: }
133:
134: }
|