1 11 package org.eclipse.pde.ui.templates; 12 import java.util.ArrayList ; 13 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.core.runtime.SubProgressMonitor; 18 import org.eclipse.jface.wizard.Wizard; 19 import org.eclipse.pde.core.plugin.IPluginModelBase; 20 import org.eclipse.pde.core.plugin.IPluginReference; 21 import org.eclipse.pde.internal.ui.PDEPlugin; 22 import org.eclipse.pde.internal.ui.PDEPluginImages; 23 import org.eclipse.pde.internal.ui.PDEUIMessages; 24 import org.eclipse.pde.ui.IBundleContentWizard; 25 import org.eclipse.pde.ui.IFieldData; 26 34 public abstract class AbstractNewPluginTemplateWizard extends Wizard 35 implements 36 IBundleContentWizard { 37 private IFieldData data; 38 41 public AbstractNewPluginTemplateWizard() { 42 super(); 43 setDialogSettings(PDEPlugin.getDefault().getDialogSettings()); 44 setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWEXPRJ_WIZ); 45 setNeedsProgressMonitor(true); 46 } 47 50 public void init(IFieldData data) { 51 this.data = data; 52 setWindowTitle(PDEUIMessages.PluginCodeGeneratorWizard_title); 53 } 54 59 public IFieldData getData() { 60 return data; 61 } 62 66 protected abstract void addAdditionalPages(); 67 70 public final void addPages() { 71 addAdditionalPages(); 72 } 73 76 public boolean performFinish() { 77 return true; 79 } 80 94 public boolean performFinish(IProject project, IPluginModelBase model, 95 IProgressMonitor monitor) { 96 try { 97 ITemplateSection[] sections = getTemplateSections(); 98 monitor.beginTask("", sections.length); for (int i = 0; i < sections.length; i++) { 100 sections[i].execute(project, model, new SubProgressMonitor( 101 monitor, 1)); 102 } 103 } catch (CoreException e) { 106 PDEPlugin.logException(e); 107 return false; 108 } finally { 109 monitor.done(); 110 } 111 return true; 112 } 113 118 public abstract ITemplateSection[] getTemplateSections(); 119 122 public IPluginReference[] getDependencies(String schemaVersion) { 123 ArrayList result = new ArrayList (); 124 ITemplateSection[] sections = getTemplateSections(); 125 for (int i = 0; i < sections.length; i++) { 126 IPluginReference[] refs = sections[i] 127 .getDependencies(schemaVersion); 128 for (int j = 0; j < refs.length; j++) { 129 if (!result.contains(refs[j])) 130 result.add(refs[j]); 131 } 132 } 133 return (IPluginReference[]) result.toArray(new IPluginReference[result 134 .size()]); 135 } 136 139 public String [] getNewFiles() { 140 ArrayList result = new ArrayList (); 141 ITemplateSection[] sections = getTemplateSections(); 142 for (int i = 0; i < sections.length; i++) { 143 String [] newFiles = sections[i].getNewFiles(); 144 for (int j = 0; j < newFiles.length; j++) { 145 if (!result.contains(newFiles[j])) 146 result.add(newFiles[j]); 147 } 148 } 149 return (String []) result.toArray(new String [result.size()]); 150 } 151 152 155 public boolean hasPages() { 156 return getTemplateSections().length > 0; 157 } 158 159 public String [] getImportPackages() { 160 return new String [0]; 161 } 162 } 163 | Popular Tags |