/* (non-Javadoc)
   * @see org.eclipse.jface.wizard.Wizard#addPages()
   */
  public void addPages() {
    WizardElement templateWizardElement = getTemplateWizard();
    if (templateWizardElement == null) {
      MessageDialog.openError(
          getShell(),
          PDEUIMessages.NewPluginProjectFromTemplateWizard_1,
          NLS.bind(PDEUIMessages.NewPluginProjectFromTemplateWizard_0, getTemplateID()));
      return;
    }

    fProjectPage =
        new NewProjectCreationFromTemplatePage(
            "main", fPluginData, getSelection(), templateWizardElement); // $NON-NLS-1$
    fProjectPage.setTitle(PDEUIMessages.NewProjectWizard_MainPage_title);
    fProjectPage.setDescription(PDEUIMessages.NewProjectWizard_MainPage_desc);

    String projectName = getDefaultValue(DEF_PROJECT_NAME);
    if (projectName != null) fProjectPage.setInitialProjectName(projectName);
    addPage(fProjectPage);

    fProjectProvider =
        new IProjectProvider() {
          public String getProjectName() {
            return fProjectPage.getProjectName();
          }

          public IProject getProject() {
            return fProjectPage.getProjectHandle();
          }

          public IPath getLocationPath() {
            return fProjectPage.getLocationPath();
          }
        };

    fContentPage =
        new PluginContentPage("page2", fProjectProvider, fProjectPage, fPluginData); // $NON-NLS-1$
    addPage(fContentPage);

    try {
      fTemplateWizard = (IPluginContentWizard) templateWizardElement.createExecutableExtension();
      fTemplateWizard.init(fPluginData);
      fTemplateWizard.addPages();
      IWizardPage[] pages = fTemplateWizard.getPages();
      for (int i = 0; i < pages.length; i++) {
        addPage(pages[i]);
      }
    } catch (CoreException e) {
      MessageDialog.openError(
          getShell(),
          PDEUIMessages.NewPluginProjectFromTemplateWizard_1,
          NLS.bind(PDEUIMessages.NewPluginProjectFromTemplateWizard_0, getTemplateID()));
    }
  }
  /**
   * Creates a WizardElement representing the template extension to be used by this wizard.
   *
   * @return element representing the template or <code>null</code> if the extension could not be
   *     loaded
   */
  private WizardElement getTemplateWizard() {
    String templateID = getTemplateID();
    if (templateID == null) {
      return null;
    }

    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(PDEPlugin.getPluginId(), PLUGIN_POINT);
    if (point == null) {
      return null;
    }
    IExtension[] extensions = point.getExtensions();
    for (int i = 0; i < extensions.length; i++) {
      IConfigurationElement[] elements = extensions[i].getConfigurationElements();
      for (int j = 0; j < elements.length; j++) {
        if (elements[j].getName().equals(TAG_WIZARD)) {
          if (templateID.equals(elements[j].getAttribute(WizardElement.ATT_ID))) {
            return WizardElement.create(elements[j]);
          }
        }
      }
    }
    return null;
  }