1 11 package org.eclipse.pde.internal.ui.wizards.plugin; 12 13 14 import java.lang.reflect.InvocationTargetException ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.core.runtime.IExecutableExtension; 20 import org.eclipse.core.runtime.IExtension; 21 import org.eclipse.core.runtime.IExtensionPoint; 22 import org.eclipse.core.runtime.IExtensionRegistry; 23 import org.eclipse.core.runtime.IPath; 24 import org.eclipse.core.runtime.Platform; 25 import org.eclipse.jface.dialogs.IDialogSettings; 26 import org.eclipse.jface.wizard.IWizardPage; 27 import org.eclipse.pde.internal.ui.PDEPlugin; 28 import org.eclipse.pde.internal.ui.PDEPluginImages; 29 import org.eclipse.pde.internal.ui.PDEUIMessages; 30 import org.eclipse.pde.internal.ui.elements.ElementList; 31 import org.eclipse.pde.internal.ui.wizards.IProjectProvider; 32 import org.eclipse.pde.internal.ui.wizards.NewWizard; 33 import org.eclipse.pde.internal.ui.wizards.WizardElement; 34 import org.eclipse.pde.ui.IPluginContentWizard; 35 import org.eclipse.swt.graphics.Image; 36 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; 37 38 public class NewPluginProjectWizard extends NewWizard implements IExecutableExtension { 39 public static final String PLUGIN_POINT = "pluginContent"; public static final String TAG_WIZARD = "wizard"; public static final String DEF_PROJECT_NAME = "project_name"; public static final String DEF_TEMPLATE_ID = "template-id"; 44 private IConfigurationElement fConfig; 45 private PluginFieldData fPluginData; 46 private IProjectProvider fProjectProvider; 47 private NewProjectCreationPage fMainPage; 48 private PluginContentPage fContentPage; 49 private TemplateListSelectionPage fWizardListPage; 50 private boolean fPureOSGi; 51 52 public NewPluginProjectWizard() { 53 setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWPPRJ_WIZ); 54 setDialogSettings(PDEPlugin.getDefault().getDialogSettings()); 55 setWindowTitle(PDEUIMessages.NewProjectWizard_title); 56 setNeedsProgressMonitor(true); 57 PDEPlugin.getDefault().getLabelProvider().connect(this); 58 fPluginData = new PluginFieldData(); 59 } 60 61 public NewPluginProjectWizard(String osgiFramework) { 62 this(); 63 fPluginData.setOSGiFramework(osgiFramework); 64 } 65 66 69 public void addPages() { 70 fMainPage = new NewProjectCreationPage("main", fPluginData, fPureOSGi); fMainPage.setTitle(PDEUIMessages.NewProjectWizard_MainPage_title); 72 fMainPage.setDescription(PDEUIMessages.NewProjectWizard_MainPage_desc); 73 String pname = getDefaultValue(DEF_PROJECT_NAME); 74 if (pname!=null) 75 fMainPage.setInitialProjectName(pname); 76 addPage(fMainPage); 77 78 fProjectProvider = new IProjectProvider() { 79 public String getProjectName() { 80 return fMainPage.getProjectName(); 81 } 82 public IProject getProject() { 83 return fMainPage.getProjectHandle(); 84 } 85 public IPath getLocationPath() { 86 return fMainPage.getLocationPath(); 87 } 88 }; 89 90 fContentPage = new PluginContentPage("page2", fProjectProvider, fMainPage, fPluginData); 92 fWizardListPage = new TemplateListSelectionPage(getAvailableCodegenWizards(), fContentPage, PDEUIMessages.WizardListSelectionPage_templates); 93 String tid = getDefaultValue(DEF_TEMPLATE_ID); 94 if (tid!=null) 95 fWizardListPage.setInitialTemplateId(tid); 96 97 addPage(fContentPage); 98 addPage(fWizardListPage); 99 } 100 101 102 105 public boolean canFinish() { 106 IWizardPage page = getContainer().getCurrentPage(); 107 return super.canFinish() && page != fMainPage; 108 } 109 114 public boolean performFinish() { 115 try { 116 fMainPage.updateData(); 117 fContentPage.updateData(); 118 IDialogSettings settings = getDialogSettings(); 119 if (settings != null) { 120 fMainPage.saveSettings(settings); 121 fContentPage.saveSettings(settings); 122 } 123 BasicNewProjectResourceWizard.updatePerspective(fConfig); 124 IPluginContentWizard contentWizard = fWizardListPage.getSelectedWizard(); 125 getContainer().run(false, true, 126 new NewProjectCreationOperation(fPluginData, fProjectProvider, contentWizard)); 127 return true; 128 } catch (InvocationTargetException e) { 129 PDEPlugin.logException(e); 130 } catch (InterruptedException e) { 131 } 132 return false; 133 } 134 135 138 public void dispose() { 139 super.dispose(); 140 PDEPlugin.getDefault().getLabelProvider().disconnect(this); 141 } 142 143 146 public void setInitializationData(IConfigurationElement config, 147 String propertyName, Object data) throws CoreException { 148 fConfig = config; 149 } 150 151 protected WizardElement createWizardElement(IConfigurationElement config) { 152 String name = config.getAttribute(WizardElement.ATT_NAME); 153 String id = config.getAttribute(WizardElement.ATT_ID); 154 String className = config.getAttribute(WizardElement.ATT_CLASS); 155 if (name == null || id == null || className == null) 156 return null; 157 WizardElement element = new WizardElement(config); 158 String imageName = config.getAttribute(WizardElement.ATT_ICON); 159 if (imageName != null) { 160 String pluginID = config.getNamespaceIdentifier(); 161 Image image = 162 PDEPlugin.getDefault().getLabelProvider().getImageFromPlugin(pluginID, imageName); 163 element.setImage(image); 164 } 165 return element; 166 } 167 168 public ElementList getAvailableCodegenWizards() { 169 ElementList wizards = new ElementList("CodegenWizards"); IExtensionRegistry registry = Platform.getExtensionRegistry(); 171 IExtensionPoint point = registry.getExtensionPoint(PDEPlugin.getPluginId(), PLUGIN_POINT); 172 if (point == null) 173 return wizards; 174 IExtension[] extensions = point.getExtensions(); 175 for (int i = 0; i < extensions.length; i++) { 176 IConfigurationElement[] elements = 177 extensions[i].getConfigurationElements(); 178 for (int j = 0; j < elements.length; j++) { 179 if (elements[j].getName().equals(TAG_WIZARD)) { 180 WizardElement element = createWizardElement(elements[j]); 181 if (element != null) { 182 wizards.add(element); 183 } 184 } 185 } 186 } 187 return wizards; 188 } 189 190 public String getPluginId() { 191 return fPluginData.getId(); 192 } 193 194 } 195 | Popular Tags |