1 11 package org.eclipse.pde.internal.ui.wizards.templates; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExtensionRegistry; 18 import org.eclipse.core.runtime.Platform; 19 import org.eclipse.jface.wizard.IWizardPage; 20 import org.eclipse.jface.wizard.WizardPage; 21 import org.eclipse.pde.internal.ui.PDEPlugin; 22 import org.eclipse.pde.ui.templates.AbstractNewPluginTemplateWizard; 23 import org.eclipse.pde.ui.templates.ITemplateSection; 24 import org.eclipse.swt.widgets.Composite; 25 26 public class NewPluginTemplateChoiceWizard 27 extends AbstractNewPluginTemplateWizard { 28 private TemplateSelectionPage fSelectionPage; 29 private ITemplateSection[] fCandiates; 30 31 public NewPluginTemplateChoiceWizard() { 32 } 33 34 public ITemplateSection[] getTemplateSections() { 35 if (fSelectionPage != null) { 36 return fSelectionPage.getSelectedTemplates(); 37 } 38 return getCandidates(); 39 } 40 41 public void addAdditionalPages() { 42 fSelectionPage = new TemplateSelectionPage(getCandidates()); 43 addPage(fSelectionPage); 44 } 45 46 public IWizardPage getNextPage(IWizardPage page) { 47 if (fSelectionPage == null) 48 return null; 49 return fSelectionPage.getNextVisiblePage(page); 50 } 51 public IWizardPage getPreviousPage(IWizardPage page) { 52 return null; 53 } 54 private ITemplateSection[] getCandidates() { 55 if (fCandiates == null) { 56 createCandidates(); 57 } 58 return fCandiates; 59 60 } 61 62 public boolean canFinish() { 64 ITemplateSection[] sections = fSelectionPage.getSelectedTemplates(); 65 for (int i = 0; i < sections.length; i++) { 66 int pageCount = sections[i].getPageCount(); 67 for (int j =0; j < pageCount; j++) { 68 WizardPage page = sections[i].getPage(j); 69 if (page != null && !page.isPageComplete()) 70 return false; 71 } 72 } 73 return true; 74 } 75 76 private void createCandidates() { 77 ArrayList candidates; 78 candidates = new ArrayList (); 79 IExtensionRegistry registry = Platform.getExtensionRegistry(); 80 IConfigurationElement[] elements = registry 81 .getConfigurationElementsFor(PDEPlugin.getPluginId(), 82 "templates"); for (int i = 0; i < elements.length; i++) { 84 IConfigurationElement element = elements[i]; 85 addTemplate(element, candidates); 86 } 87 fCandiates = (ITemplateSection[]) candidates 88 .toArray(new ITemplateSection[candidates.size()]); 89 } 90 91 private void addTemplate(IConfigurationElement config, ArrayList result) { 92 if (config.getName().equalsIgnoreCase("template") == false) return; 94 95 try { 96 Object template = config.createExecutableExtension("class"); if (template instanceof ITemplateSection) { 98 result.add(template); 99 } 100 } catch (CoreException e) { 101 PDEPlugin.log(e); 102 } 103 } 104 105 public void createPageControls(Composite pageContainer) { 108 fSelectionPage.createControl(pageContainer); 109 } 110 } 111 | Popular Tags |