1 11 package org.eclipse.pde.internal.ui.wizards.feature; 12 13 import java.lang.reflect.InvocationTargetException ; 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 DEF_PROJECT_NAME = "project-name"; public static final String DEF_FEATURE_ID = "feature-id"; public static final String DEF_FEATURE_NAME = "feature-name"; 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 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 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 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 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 e) { 113 PDEPlugin.logException(e); 114 return false; 115 } catch (InterruptedException e) { 116 return false; 117 } 118 return true; 119 } 120 121 public void setInitializationData(IConfigurationElement config, String property, 122 Object data) throws CoreException { 123 this.fConfig = config; 124 } 125 126 } 127 | Popular Tags |