@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 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 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());
  }
  @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;
  }
  void read(WizardDescriptor settings) {
    //        jsfFolder.setText((String) settings.getProperty(WizardProperties.JSF_FOLDER));

    project = Templates.getProject(settings);
    FileObject targetFolder = Templates.getTargetFolder(settings);

    projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName());

    SourceGroup[] sourceGroups = SourceGroups.getJavaSourceGroups(project);
    SourceGroupUISupport.connect(locationComboBox, sourceGroups);

    packageComboBox.setRenderer(PackageView.listRenderer());

    updateSourceGroupPackages();

    // set default source group and package cf. targetFolder
    //        if (targetFolder != null) {
    //            SourceGroup targetSourceGroup =
    // SourceGroupSupport.getFolderSourceGroup(sourceGroups, targetFolder);
    //            if (targetSourceGroup != null) {
    //                locationComboBox.setSelectedItem(targetSourceGroup);
    //                String targetPackage =
    // SourceGroupSupport.getPackageForFolder(targetSourceGroup, targetFolder);
    //                if (targetPackage != null) {
    //                    packageComboBoxEditor.setText(targetPackage);
    //                }
    //            }
    //            if (FileUtil.isParentOf(WebModule.getWebModule(
    //                    targetFolder).getDocumentBase(), targetFolder)) {
    //                Sources s = (Sources)
    // Templates.getProject(wizard).getLookup().lookup(Sources.class);
    //                SourceGroup[] groups = s.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT);
    //
    // jsfFolder.setText("/"+JSFConfigUtilities.getResourcePath(groups,targetFolder,'/',true));
    //            }
    //        }
  }
  protected WizardDescriptor.Panel<WizardDescriptor>[] createPanels() {
    if (targetChooserDescriptorPanel == null) {
      TemplateWizard wiz = getWizard();
      DataObject dobj = wiz.getTemplate();
      FileObject fobj = dobj.getPrimaryFile();
      String mimeType = fobj.getMIMEType();
      MIMEExtensions extensions = MIMEExtensions.get(mimeType);
      if (extensions != null) {
        Project project = Templates.getProject(getWizard());
        Sources sources = ProjectUtils.getSources(project);
        SourceGroup[] groups = sources.getSourceGroups(Sources.TYPE_GENERIC);
        if (MIMENames.HEADER_MIME_TYPE.equals(extensions.getMIMEType())) {
          // this is the only place where we want to differ c headers from cpp headers (creation of
          // new one)
          if (dobj.getPrimaryFile().getAttribute(C_HEADER_MIME_TYPE) != null) {
            MIMEExtensions cHeaderExtensions = MIMEExtensions.get(C_HEADER_MIME_TYPE);
            if ((cHeaderExtensions == null)
                || !C_HEADER_MIME_TYPE.equals(cHeaderExtensions.getMIMEType())) {
              System.err.println("not found extensions for C Headers"); // NOI18N
            } else {
              extensions = cHeaderExtensions;
            }
          }
        }
        String defaultExt = null; // let the chooser panel decide default extension
        if (mimeType.equals(MIMENames.SHELL_MIME_TYPE)) {
          // for shell scripts set default extension explicitly
          defaultExt = fobj.getExt();
        } else if (mimeType.equals(MIMENames.HEADER_MIME_TYPE) && fobj.getExt().length() == 0) {
          // for standard header without extension
          defaultExt = fobj.getExt();
        }

        targetChooserDescriptorPanel =
            new NewTestSimplePanel(
                project,
                groups,
                null,
                extensions,
                defaultExt,
                (String) wiz.getProperty(CND_UNITTEST_DEFAULT_NAME));
      } else {
        targetChooserDescriptorPanel = getWizard().targetChooser();
      }
    }
    @SuppressWarnings("unchecked")
    Panel<WizardDescriptor>[] panels = new WizardDescriptor.Panel[] {targetChooserDescriptorPanel};
    return panels;
  }
 void store(WizardDescriptor settings) {
   //        settings.putProperty(WizardProperties.JSF_FOLDER, jsfFolder.getText());
   String pkg = getPackage();
   settings.putProperty(WizardProperties.JPA_CONTROLLER_PACKAGE, pkg);
   //        settings.putProperty(WizardProperties.AJAXIFY_JSF_CRUD,
   // Boolean.valueOf(ajaxifyCheckbox.isSelected()));
   try {
     FileObject fo = getLocationValue().getRootFolder();
     String pkgSlashes = pkg.replace('.', '/');
     FileObject targetFolder = fo.getFileObject(pkgSlashes);
     if (targetFolder == null) {
       targetFolder = FileUtil.createFolder(fo, pkgSlashes);
     }
     Templates.setTargetFolder(settings, targetFolder);
   } catch (IOException ex) {
     Exceptions.printStackTrace(ex);
   }
 }
 @Override
 public void storeSettings(WizardDescriptor settings) {
   Object value = settings.getValue();
   if (WizardDescriptor.PREVIOUS_OPTION.equals(value)
       || WizardDescriptor.CANCEL_OPTION.equals(value)
       || WizardDescriptor.CLOSED_OPTION.equals(value)) {
     return;
   }
   settings.putProperty(
       AfterburnerFXTemplateWizardIterator.JAVA_DIR, Templates.getTargetFolder(settings));
   settings.putProperty(AfterburnerFXTemplateWizardIterator.NAME, component.getViewName());
   settings.putProperty(
       AfterburnerFXTemplateWizardIterator.GENERATE_BUNDLE, component.isBundleNeeded());
   settings.putProperty(
       AfterburnerFXTemplateWizardIterator.GENERATE_CONFIG, component.isConfigurationNeeded());
   settings.putProperty(
       AfterburnerFXTemplateWizardIterator.GENERATE_CSS, component.isCssNeeded());
   settings.putProperty("NewFileWizard_Title", null); // 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)};
 }
Exemplo n.º 11
0
  @Override
  public Set<DataObject> instantiate(TemplateWizard wiz) throws IOException {
    UIGesturesSupport.submit(
        "USG_CND_UNIT_TESTS_SIMPLE_"
            + wiz.getTemplate().getPrimaryFile().getExt().toUpperCase()); // NOI18N

    Project project = Templates.getProject(wiz);

    Set<DataObject> dataObjects = new HashSet<DataObject>();

    if (getTestFileName() == null || getTestName() == null) {
      return dataObjects;
    }

    DataFolder targetFolder = wiz.getTargetFolder();

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(CreateFromTemplateHandler.FREE_FILE_EXTENSION, true);

    List<CsmFunction> fs = new ArrayList<CsmFunction>();
    Object listObj = wiz.getProperty(CND_UNITTEST_FUNCTIONS);
    if (listObj instanceof List<?>) {
      List<?> list = (List<?>) listObj;
      for (Object obj : list) {
        if (obj instanceof CsmFunction) {
          fs.add((CsmFunction) obj);
        }
      }
    }
    FileObject rootFolder = getRootFolder();
    FSPath rootFolderFilePath = FSPath.toFSPath(rootFolder);
    params.putAll(
        CodeGenerator.generateTemplateParamsForFunctions(
            getTestFileName().replaceFirst("[.].*", ""), // NOI18N
            rootFolderFilePath,
            fs,
            ("cpp".equals(wiz.getTemplate().getPrimaryFile().getExt())
                ? CodeGenerator.Language.CPP
                : CodeGenerator.Language.C))); // NOI18N

    DataObject formDataObject =
        NewTestSimplePanel.getTemplateDataObject(
            "simpletestfile." + wiz.getTemplate().getPrimaryFile().getExt()); // NOI18N

    DataObject dataObject =
        formDataObject.createFromTemplate(targetFolder, getTestFileName(), params);

    Folder folder = null;
    Folder testsRoot = getTestsRootFolder(project);
    if (testsRoot == null) {
      testsRoot = createTestsRootFolder(project);
      MakefileUtils.createTestTargets(project);
    }
    if (testsRoot != null) {
      Folder newFolder = testsRoot.addNewFolder(true, Folder.Kind.TEST);
      newFolder.setDisplayName(getTestName());
      folder = newFolder;
    }

    if (folder == null) {
      return dataObjects;
    }

    setOptions(project, folder);

    addItemToLogicalFolder(project, folder, dataObject);

    dataObjects.add(dataObject);
    return dataObjects;
  }
Exemplo n.º 12
0
 void read(WizardDescriptor settings) {
   project = (CacheProject) Templates.getProject(settings);
   //        CacheFileObject dir = (CacheFileObject) project.getProjectDirectory();
 }
  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;
  }