1 11 package org.eclipse.pde.internal.ui.wizards.plugin; 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.pde.internal.ui.PDEPlugin; 21 import org.eclipse.pde.internal.ui.PDEPluginImages; 22 import org.eclipse.pde.internal.ui.PDEUIMessages; 23 import org.eclipse.pde.internal.ui.wizards.IProjectProvider; 24 import org.eclipse.pde.internal.ui.wizards.NewWizard; 25 import org.eclipse.pde.internal.ui.wizards.WizardElement; 26 import org.eclipse.swt.graphics.Image; 27 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; 28 29 public class NewLibraryPluginProjectWizard extends NewWizard implements 30 IExecutableExtension { 31 public static final String DEF_PROJECT_NAME = "project_name"; 33 public static final String DEF_TEMPLATE_ID = "template-id"; 35 public static final String PLUGIN_POINT = "pluginContent"; 37 public static final String TAG_WIZARD = "wizard"; 39 private IConfigurationElement fConfig; 40 41 private LibraryPluginJarsPage fJarsPage; 42 43 private NewLibraryPluginCreationPage fMainPage; 44 45 private LibraryPluginFieldData fPluginData; 46 47 private IProjectProvider fProjectProvider; 48 49 public NewLibraryPluginProjectWizard() { 50 setDefaultPageImageDescriptor(PDEPluginImages.DESC_JAR_TO_PLUGIN_WIZ); 51 setDialogSettings(PDEPlugin.getDefault().getDialogSettings()); 52 setWindowTitle(PDEUIMessages.NewLibraryPluginProjectWizard_title); 53 setNeedsProgressMonitor(true); 54 PDEPlugin.getDefault().getLabelProvider().connect(this); 55 fPluginData = new LibraryPluginFieldData(); 56 } 57 58 63 public void addPages() { 64 fJarsPage = new LibraryPluginJarsPage("jars", fPluginData); addPage(fJarsPage); 66 fMainPage = new NewLibraryPluginCreationPage("main", fPluginData); String pname = getDefaultValue(DEF_PROJECT_NAME); 68 if (pname != null) 69 fMainPage.setInitialProjectName(pname); 70 71 fProjectProvider = new IProjectProvider() { 72 public IPath getLocationPath() { 73 return fMainPage.getLocationPath(); 74 } 75 76 public IProject getProject() { 77 return fMainPage.getProjectHandle(); 78 } 79 80 public String getProjectName() { 81 return fMainPage.getProjectName(); 82 } 83 }; 84 85 addPage(fMainPage); 86 } 87 88 protected WizardElement createWizardElement(IConfigurationElement config) { 89 String name = config.getAttribute(WizardElement.ATT_NAME); 90 String id = config.getAttribute(WizardElement.ATT_ID); 91 String className = config.getAttribute(WizardElement.ATT_CLASS); 92 if (name == null || id == null || className == null) 93 return null; 94 WizardElement element = new WizardElement(config); 95 String imageName = config.getAttribute(WizardElement.ATT_ICON); 96 if (imageName != null) { 97 String pluginID = config.getNamespaceIdentifier(); 98 Image image = PDEPlugin.getDefault().getLabelProvider() 99 .getImageFromPlugin(pluginID, imageName); 100 element.setImage(image); 101 } 102 return element; 103 } 104 105 110 public void dispose() { 111 super.dispose(); 112 PDEPlugin.getDefault().getLabelProvider().disconnect(this); 113 } 114 115 120 public boolean performFinish() { 121 try { 122 fJarsPage.updateData(); 123 fMainPage.updateData(); 124 BasicNewProjectResourceWizard.updatePerspective(fConfig); 125 getContainer().run( 126 false, 127 true, 128 new NewLibraryPluginCreationOperation(fPluginData, 129 fProjectProvider, null)); 130 return true; 131 } catch (InvocationTargetException e) { 132 PDEPlugin.logException(e); 133 } catch (InterruptedException e) { 134 } 135 return false; 136 } 137 138 144 public void setInitializationData(IConfigurationElement config, 145 String propertyName, Object data) throws CoreException { 146 fConfig = config; 147 } 148 149 } 150 | Popular Tags |