KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > feature > AbstractNewFeatureWizard


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.feature;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IExecutableExtension;
19 import org.eclipse.core.runtime.IPath;
20 import org.eclipse.debug.core.ILaunchConfiguration;
21 import org.eclipse.jface.dialogs.IDialogSettings;
22 import org.eclipse.jface.operation.IRunnableWithProgress;
23 import org.eclipse.jface.wizard.IWizardPage;
24 import org.eclipse.pde.core.plugin.IPluginBase;
25 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
26 import org.eclipse.pde.internal.ui.PDEPlugin;
27 import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
28 import org.eclipse.pde.internal.ui.wizards.NewWizard;
29 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
30
31 public abstract class AbstractNewFeatureWizard extends NewWizard implements IExecutableExtension {
32
33     public static final String JavaDoc DEF_PROJECT_NAME = "project-name"; //$NON-NLS-1$
34
public static final String JavaDoc DEF_FEATURE_ID = "feature-id"; //$NON-NLS-1$
35
public static final String JavaDoc DEF_FEATURE_NAME = "feature-name"; //$NON-NLS-1$
36

37     protected AbstractFeatureSpecPage fSpecPage;
38     protected PluginListPage fSecondPage;
39     protected FeaturePatchProvider fProvider;
40     private IConfigurationElement fConfig;
41     
42     public class FeaturePatchProvider implements IProjectProvider {
43         public FeaturePatchProvider() {
44             super();
45         }
46         public String JavaDoc getProjectName() {
47             return fSpecPage.getProjectName();
48         }
49         public IProject getProject() {
50             return fSpecPage.getProjectHandle();
51         }
52         public IPath getLocationPath() {
53             return fSpecPage.getLocationPath();
54         }
55         public IFeatureModel getFeatureToPatch() {
56             return fSpecPage.getFeatureToPatch();
57         }
58         public FeatureData getFeatureData() {
59             return fSpecPage.getFeatureData();
60         }
61         public String JavaDoc getInstallHandlerLibrary() {
62             return fSpecPage.getInstallHandlerLibrary();
63         }
64         public IPluginBase[] getPluginListSelection() {
65             return fSecondPage != null ?
66                     fSecondPage.getSelectedPlugins() : null;
67         }
68         public ILaunchConfiguration getLaunchConfiguration() {
69             return fSecondPage != null ?
70                     fSecondPage.getSelectedLaunchConfiguration() : null;
71         }
72     }
73
74     public AbstractNewFeatureWizard() {
75         super();
76         setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
77         setNeedsProgressMonitor(true);
78     }
79
80     public void addPages() {
81         fSpecPage = createFirstPage();
82         String JavaDoc pname = getDefaultValue(DEF_PROJECT_NAME);
83         if (pname != null)
84             fSpecPage.setInitialProjectName(pname);
85         
86         fSpecPage.setInitialId(getDefaultValue(DEF_FEATURE_ID));
87         fSpecPage.setInitialName(getDefaultValue(DEF_FEATURE_NAME));
88         addPage(fSpecPage);
89         
90         fProvider = new FeaturePatchProvider();
91     }
92
93     protected abstract AbstractFeatureSpecPage createFirstPage();
94     
95     public boolean canFinish() {
96         IWizardPage page = getContainer().getCurrentPage();
97         return ((page == fSpecPage && page.isPageComplete())
98                 || (page == fSecondPage && page.isPageComplete()));
99     }
100     
101     // get creation operation
102
protected abstract IRunnableWithProgress getOperation();
103     
104     public boolean performFinish() {
105         try {
106             IDialogSettings settings = getDialogSettings();
107             if (settings != null && fSecondPage != null)
108                 fSecondPage.saveSettings(settings);
109             
110             getContainer().run(false, true, getOperation());
111             BasicNewProjectResourceWizard.updatePerspective(fConfig);
112         } catch (InvocationTargetException JavaDoc e) {
113             PDEPlugin.logException(e);
114             return false;
115         } catch (InterruptedException JavaDoc e) {
116             return false;
117         }
118         return true;
119     }
120
121     public void setInitializationData(IConfigurationElement config, String JavaDoc property,
122             Object JavaDoc data) throws CoreException {
123         this.fConfig = config;
124     }
125
126 }
127
Popular Tags