@Override
  public void initialize(WizardDescriptor wiz) {
    this.wiz = wiz;
    index = 0;
    panels = createPanels();
    // Make sure list of steps is accurate.
    String[] steps = createSteps();
    for (int i = 0; i < panels.length; i++) {
      Component c = panels[i].getComponent();
      if (steps[i] == null) {
        // Default step name to component name of panel.
        // Mainly useful for getting the name of the target
        // chooser to appear in the list of steps.
        steps[i] = c.getName();
      }
      if (c instanceof JComponent) { // assume Swing components
        JComponent jc = (JComponent) c;
        // Step #.
        jc.putClientProperty(WizardProperties.SELECTED_INDEX, new Integer(i));
        // Step name (actually the whole list for reference).
        jc.putClientProperty(WizardProperties.CONTENT_DATA, steps);
      }
    }

    FileObject template = Templates.getTemplate(wiz);

    wiz.putProperty(WizardProperties.NAME, template.getName());
  }
  public Set /*<FileObject>*/ instantiate(/*ProgressHandle handle*/ ) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
      FileObject subfolder = e.nextElement();
      if (ProjectManager.getDefault().isProject(subfolder)) {
        resultSet.add(subfolder);
      }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
      ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
  }
  @Override
  public Set instantiate(ProgressHandle handle) throws IOException {
    handle.start(2);
    handle.progress(
        NbBundle.getMessage(
            JavaEESamplesWizardIterator.class,
            "LBL_NewSampleProjectWizardIterator_WizardProgress_CreatingProject"),
        1);

    Set resultSet = new LinkedHashSet();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty(WizardProperties.PROJ_DIR));
    String name = (String) wiz.getProperty(WizardProperties.NAME);
    FileObject template = Templates.getTemplate(wiz);

    FileObject dir = null;
    if ("web".equals(template.getAttribute("prjType"))) {
      // Use generator from web.examples to create project with specified name
      dir = WebSampleProjectGenerator.createProjectFromTemplate(template, dirF, name);
    } else {
      // Unzip prepared project only (no way to change name of the project)
      // FIXME: should be modified to create projects with specified name (project.xml files in
      // sub-projects should be modified too)
      // FIXME: web.examples and j2ee.samples modules may be merged into one module
      createFolder(dirF);
      dir = FileUtil.toFileObject(dirF);
      unZipFile(template.getInputStream(), dir);
      WebSampleProjectGenerator.configureServer(dir);
      for (FileObject child : dir.getChildren()) {
        WebSampleProjectGenerator.configureServer(child);
      }
    }

    ProjectManager.getDefault().clearNonProjectCache();
    handle.progress(
        NbBundle.getMessage(
            JavaEESamplesWizardIterator.class,
            "LBL_NewSampleProjectWizardIterator_WizardProgress_PreparingToOpen"),
        2);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration e = dir.getFolders(true);
    while (e.hasMoreElements()) {
      FileObject subfolder = (FileObject) e.nextElement();
      if (ProjectManager.getDefault().isProject(subfolder)) {
        resultSet.add(subfolder);
      }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
      ProjectChooser.setProjectsFolder(parent);
    }

    handle.finish();
    return resultSet;
  }
    @Override
    public void readSettings(WizardDescriptor settings) {
      this.settings = settings;
      // Try to preselect a folder
      FileObject preselectedFolder = Templates.getTargetFolder(settings);
      // Init values
      component.initValues(Templates.getTemplate(settings), preselectedFolder);

      // XXX hack, TemplateWizard in final setTemplateImpl() forces new wizard's title
      // this name is used in NewFileWizard to modify the title
      Object substitute = component.getClientProperty("NewFileWizard_Title"); // NOI18N
      if (substitute != null) {
        settings.putProperty("NewFileWizard_Title", substitute); // NOI18N
      }
    }
  public void initialize(WizardDescriptor wiz) {
    this.wiz = wiz;
    FileObject template = Templates.getTemplate(wiz);
    preferredName = template.getName();
    this.wiz.putProperty("name", preferredName);
    platform = (String) template.getAttribute("platform");

    this.wiz = wiz;
    index = 0;
    panels = createPanels();
    // Make sure list of steps is accurate.
    String[] steps = createSteps();
    for (int i = 0; i < panels.length; i++) {
      Component c = panels[i].getComponent();
      if (steps[i] == null) {
        // Default step name to component name of panel.
        // Mainly useful for getting the name of the target
        // chooser to appear in the list of steps.
        steps[i] = c.getName();
      }
      if (c instanceof JComponent) { // assume Swing components
        JComponent jc = (JComponent) c;
        // Step #.
        jc.putClientProperty(
            WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, new Integer(i)); // NOI18N
        // Step name (actually the whole list for reference).
        jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); // NOI18N
        /*
         * Fix for #147260 - Wrong title in Ricoh samples wizard
         */
        jc.putClientProperty(
            "NewProjectWizard_Title",
            NbBundle.getMessage(NewProjectIterator.class, "TXT_SampleProject")); // NOI18N
      }
    }
    this.wiz.putProperty("additionalProperties", new Properties());
  }
 protected WizardDescriptor.Panel[] createPanels() {
   boolean specifyPrjName = "web".equals(Templates.getTemplate(wiz).getAttribute("prjType"));
   return new WizardDescriptor.Panel[] {new JavaEESamplesWizardPanel(false, specifyPrjName)};
 }
  public Set /*<FileObject>*/ instantiate() throws IOException {

    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirPr = (File) wiz.getProperty("projdir"); // NOI18N
    if (dirPr != null) {
      dirPr = FileUtil.normalizeFile(dirPr);
    }

    String name = (String) wiz.getProperty("name"); // NOI18N

    final String activePlatform = (String) wiz.getProperty("activePlatform"); // NOI18N
    final String activeDevice = (String) wiz.getProperty("activeDevice"); // NOI18N
    final String activeProfile = (String) wiz.getProperty("activeProfile"); // NOI18N
    Properties props = (Properties) wiz.getProperty("additionalProperties"); // NOI18N
    final FileObject template = Templates.getTemplate(wiz);
    PlatformSelectionPanel.PlatformDescription pd =
        (PlatformSelectionPanel.PlatformDescription)
            wiz.getProperty(PlatformSelectionPanel.PLATFORM_DESCRIPTION);
    AntProjectHelper h =
        J2MEProjectGenerator.createProject(
            dirPr,
            name,
            pd,
            new J2MEProjectGenerator.ProjectGeneratorCallback() {
              public void doPostGeneration(
                  Project p,
                  final AntProjectHelper h,
                  FileObject dir,
                  File projectLocationFile,
                  ArrayList<String> configurations)
                  throws IOException {

                createManifest(dir, MANIFEST_FILE);
                unZipFile(template.getInputStream(), dir);

                final FileObject lib = dir.getFileObject("lib");
                if (lib != null) {
                  final ReferenceHelper refHelper =
                      (ReferenceHelper) p.getLookup().lookup(ReferenceHelper.class);
                  try {
                    ProjectManager.mutex()
                        .writeAccess(
                            new Mutex.ExceptionAction() {
                              public Object run() throws Exception {
                                final List<String> entries = new ArrayList<String>();
                                final FileObject[] libs = lib.getChildren();
                                for (int i = 0; i < libs.length; i++) {
                                  String ref =
                                      refHelper.createForeignFileReference(
                                          FileUtil.normalizeFile(FileUtil.toFile(libs[i])), null);
                                  entries.add(ref + ((i < libs.length - 1) ? ";" : ""));
                                }

                                EditableProperties editableProps =
                                    h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                                editableProps.setProperty(
                                    "extra.classpath", entries.toArray(new String[entries.size()]));
                                editableProps.setProperty(
                                    "libs.classpath", entries.toArray(new String[entries.size()]));
                                h.putProperties(
                                    AntProjectHelper.PROJECT_PROPERTIES_PATH,
                                    editableProps); // #47609
                                return null;
                              }
                            });
                  } catch (MutexException me) {
                    ErrorManager.getDefault().notify(me);
                  }
                }

                final FileObject res = dir.getFileObject("resources");
                if (res != null) {
                  final ReferenceHelper refHelper =
                      (ReferenceHelper) p.getLookup().lookup(ReferenceHelper.class);
                  try {
                    ProjectManager.mutex()
                        .writeAccess(
                            new Mutex.ExceptionAction() {
                              public Object run() throws Exception {
                                String ref =
                                    ";"
                                        + refHelper.createForeignFileReference(
                                            FileUtil.normalizeFile(FileUtil.toFile(res)), null);

                                EditableProperties editableProps =
                                    h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                                editableProps.setProperty(
                                    "libs.classpath",
                                    editableProps.getProperty("libs.classpath") + ref);
                                h.putProperties(
                                    AntProjectHelper.PROJECT_PROPERTIES_PATH,
                                    editableProps); // #47609
                                return null;
                              }
                            });
                  } catch (MutexException me) {
                    ErrorManager.getDefault().notify(me);
                  }
                }

                Properties parsed = parseRicohAdditionalResources(dir);
                if (parsed != null) {
                  Iterator entries = parsed.entrySet().iterator();
                  while (entries.hasNext()) {
                    final Map.Entry elem = (Map.Entry) entries.next();
                    final Object value = elem.getValue();
                    if (value instanceof File) {
                      final ReferenceHelper refHelper =
                          (ReferenceHelper) p.getLookup().lookup(ReferenceHelper.class);
                      if (value != null && ((File) value).exists()) {
                        try {
                          ProjectManager.mutex()
                              .writeAccess(
                                  new Mutex.ExceptionAction() {
                                    public Object run() throws Exception {
                                      String ref =
                                          refHelper.createForeignFileReference(
                                              FileUtil.normalizeFile((File) value), null);
                                      EditableProperties props =
                                          h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                                      props.put((String) elem.getKey(), ref);
                                      h.putProperties(
                                          AntProjectHelper.PROJECT_PROPERTIES_PATH,
                                          props); // #47609
                                      return null;
                                    }
                                  });
                        } catch (MutexException me) {
                          ErrorManager.getDefault().notify(me);
                        }
                      }
                    } else {
                      EditableProperties editableProps =
                          h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                      editableProps.setProperty(
                          (String) elem.getKey(), String.valueOf(elem.getValue()));
                      h.putProperties(
                          AntProjectHelper.PROJECT_PROPERTIES_PATH, editableProps); // #47609
                    }
                  }
                }

                JavaPlatform[] platforms =
                    JavaPlatformManager.getDefault()
                        .getPlatforms(
                            activePlatform,
                            new Specification(CDCPlatform.PLATFORM_CDC, null)); // NOI18N
                if (platforms.length != 0) {
                  CDCPlatform cdcplatform = (CDCPlatform) platforms[0];
                  final EditableProperties ep =
                      h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                  ep.setProperty(
                      CDCPropertiesDescriptor.APPLICATION_NAME,
                      p.getProjectDirectory().getNameExt());
                  ep.setProperty(
                      DefaultPropertiesDescriptor.PLATFORM_ACTIVE,
                      cdcplatform.getAntName()); // NOI18N
                  ep.setProperty(
                      DefaultPropertiesDescriptor.PLATFORM_ACTIVE_DESCRIPTION,
                      cdcplatform.getDisplayName()); // NOI18N
                  ep.setProperty(DefaultPropertiesDescriptor.PLATFORM_TRIGGER, "CDC"); // NOI18N
                  ep.setProperty(
                      DefaultPropertiesDescriptor.PLATFORM_TYPE, cdcplatform.getType()); // NOI18N
                  String classVersion = cdcplatform.getClassVersion();
                  ep.setProperty(
                      DefaultPropertiesDescriptor.PLATFORM_DEVICE, activeDevice); // NOI18N
                  ep.setProperty(
                      DefaultPropertiesDescriptor.PLATFORM_PROFILE, activeProfile); // NOI18N
                  // add bootclasspath
                  NewCDCProjectWizardIterator.generatePlatformProperties(
                      cdcplatform, activeDevice, activeProfile, ep); // NOI18N
                  ep.setProperty(
                      DefaultPropertiesDescriptor.JAVAC_SOURCE,
                      classVersion != null ? classVersion : "1.2"); // NOI18N
                  ep.setProperty(
                      DefaultPropertiesDescriptor.JAVAC_TARGET,
                      classVersion != null ? classVersion : "1.2"); // NOI18N
                  h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
                } else {
                  throw new IllegalArgumentException("No CDC platform installed"); // NOI18N
                }
              }
            });

    resultSet.add(h.getProjectDirectory());
    dirPr = (dirPr != null) ? dirPr.getParentFile() : null;
    if (dirPr != null && dirPr.exists()) {
      ProjectChooser.setProjectsFolder(dirPr);
    }
    return resultSet;
  }