예제 #1
0
  @Override
  @SuppressWarnings("unchecked")
  public TopComponent getTopComponent() {
    // Loading the multiview windows:
    FileObject multiviewsFolder = FileUtil.getConfigFile("skitmultiviews");
    FileObject[] kids = multiviewsFolder.getChildren();
    MultiViewDescription[] descriptionArray = new MultiViewDescription[kids.length];
    ArrayList<MultiViewDescription> listOfDescs = new ArrayList<MultiViewDescription>();

    for (FileObject kid : FileUtil.getOrder(Arrays.asList(kids), true)) {
      MultiViewDescription attribute = (MultiViewDescription) kid.getAttribute("multiview");

      if (attribute instanceof ContextAwareInstance) {
        Lookup lu = Lookups.fixed(this);
        attribute =
            ((ContextAwareInstance<MultiViewDescription>) attribute).createContextAwareInstance(lu);
      }

      listOfDescs.add(attribute);
    }

    for (int i = 0; i < listOfDescs.size(); i++) {
      descriptionArray[i] = listOfDescs.get(i);
    }

    CloneableTopComponent ctc =
        MultiViewFactory.createCloneableMultiView(descriptionArray, descriptionArray[0]);

    return ctc;
  }
 private boolean acceptSave() {
   Object storing = providerFO.getAttribute(EA_PREVENT_STORING);
   if (storing == null) return true;
   if (storing instanceof Boolean) return !((Boolean) storing).booleanValue();
   if (storing instanceof String) return !Boolean.valueOf((String) storing).booleanValue();
   return true;
 }
  public void write(java.io.Writer w, Object inst) throws IOException {
    w.write(
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
            + XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
    w.write("<!DOCTYPE properties PUBLIC \""); // NOI18N

    FileObject foEntity = Env.findEntityRegistration(providerFO);
    if (foEntity == null) foEntity = providerFO;
    Object publicId = foEntity.getAttribute(Env.EA_PUBLICID);
    if (publicId == null || !(publicId instanceof String)) {
      throw new IOException(
          "missing or invalid attribute: "
              + // NOI18N
              Env.EA_PUBLICID
              + ", provider: "
              + foEntity); // NOI18N
    }

    w.write((String) publicId);
    w.write(
        "\" \"http://www.netbeans.org/dtds/properties-1_0.dtd\">"
            + XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
    w.write("<properties>" + XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
    Properties p = getProperties(inst);
    if (p != null && !p.isEmpty()) writeProperties(w, p);
    w.write("</properties>" + XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
  }
  @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;
  }
  /** filtering of Property Change Events */
  private boolean ignoreChange(java.beans.PropertyChangeEvent pce) {
    if (pce == null || pce.getPropertyName() == null) return true;

    if (ignoreProperites == null) {
      ignoreProperites = Env.parseAttribute(providerFO.getAttribute(EA_IGNORE_CHANGES));
    }
    if (ignoreProperites.contains(pce.getPropertyName())) return true;

    return ignoreProperites.contains("all"); // NOI18N
  }
 private Class getInstanceClass() throws IOException, ClassNotFoundException {
   if (instanceClass == null) {
     Object name = providerFO.getAttribute(Env.EA_INSTANCE_CLASS_NAME);
     if (name == null || !(name instanceof String)) {
       throw new IllegalStateException(
           "missing or invalid ea attribute: " + Env.EA_INSTANCE_CLASS_NAME); // NOI18N
     }
     instanceClass = (String) name;
   }
   return ((ClassLoader) Lookup.getDefault().lookup(ClassLoader.class)).loadClass(instanceClass);
 }
  private Object defaultInstanceCreate() throws IOException, ClassNotFoundException {
    Object instanceCreate = providerFO.getAttribute(Env.EA_INSTANCE_CREATE);
    if (instanceCreate != null) return instanceCreate;

    Class c = getInstanceClass();
    try {
      return c.newInstance();
    } catch (Exception ex) { // IllegalAccessException, InstantiationException
      IOException ioe = new IOException("Cannot create instance of " + c.getName()); // NOI18N
      ioe.initCause(ex);
      throw ioe;
    }
  }
  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());
  }
예제 #9
0
  private void loadFromDefaultFileSystem() {
    FileObject f = FileUtil.getConfigFile("SaaSServices"); // NOI18N

    if (f != null && f.isFolder()) {
      Enumeration<? extends FileObject> en = f.getFolders(false);
      while (en.hasMoreElements()) {
        FileObject groupFolder = en.nextElement();
        for (FileObject fo : groupFolder.getChildren()) {
          if (fo.isFolder()) {
            continue;
          }
          if (PROFILE_PROPERTIES_FILE.equals(fo.getNameExt())) {
            continue;
          }
          loadSaasServiceFile(fo, false);
        }
        SaasGroup g = rootGroup.getChildGroup(groupFolder.getName());
        if (g != null) {
          g.setIcon16Path((String) groupFolder.getAttribute("icon16"));
          g.setIcon32Path((String) groupFolder.getAttribute("icon32"));
        }
      }
    }
  }
예제 #10
0
  /** Creates a new instance of TomcatProperties */
  public TomcatProperties(TomcatManager tm) throws IllegalArgumentException {
    this.tm = tm;
    this.ip = tm.getInstanceProperties();
    String catalinaHome = null;
    String catalinaBase = null;
    String uri = ip.getProperty(PROP_URL); // NOI18N
    final String home = "home="; // NOI18N
    final String base = ":base="; // NOI18N
    final String uriString = "http://"; // NOI18N
    int uriOffset = uri.indexOf(uriString);
    int homeOffset = uri.indexOf(home) + home.length();
    int baseOffset = uri.indexOf(base, homeOffset);
    if (homeOffset >= home.length()) {
      int homeEnd = baseOffset > 0 ? baseOffset : (uriOffset > 0 ? uriOffset - 1 : uri.length());
      int baseEnd = uriOffset > 0 ? uriOffset - 1 : uri.length();
      catalinaHome = uri.substring(homeOffset, homeEnd);
      if (baseOffset > 0) {
        catalinaBase = uri.substring(baseOffset + base.length(), baseEnd);
      }
      // Bundled Tomcat home and base dirs can be specified as attributes
      // specified in BUNDLED_TOMCAT_SETTING file. Tomcat manager URL can
      // then look like "tomcat:home=$bundled_home:base=$bundled_base" and
      // therefore remains valid even if Tomcat version changes. (issue# 40659)
      if (catalinaHome.length() > 0 && catalinaHome.charAt(0) == '$') {
        FileObject fo = FileUtil.getConfigFile(BUNDLED_TOMCAT_SETTING);
        if (fo != null) {
          catalinaHome = fo.getAttribute(catalinaHome.substring(1)).toString();
          if (catalinaBase != null && catalinaBase.length() > 0 && catalinaBase.charAt(0) == '$') {
            catalinaBase = fo.getAttribute(catalinaBase.substring(1)).toString();
          }
        }
      }
    }
    if (catalinaHome == null) {
      throw new IllegalArgumentException("CATALINA_HOME must not be null."); // NOI18N
    }
    homeDir = new File(catalinaHome);
    if (!homeDir.isAbsolute()) {
      InstalledFileLocator ifl = InstalledFileLocator.getDefault();
      homeDir = ifl.locate(catalinaHome, null, false);
    }
    if (!homeDir.exists()) {
      throw new IllegalArgumentException("CATALINA_HOME directory does not exist."); // NOI18N
    }
    if (catalinaBase != null) {
      baseDir = new File(catalinaBase);
      if (!baseDir.isAbsolute()) {
        InstalledFileLocator ifl = InstalledFileLocator.getDefault();
        baseDir = ifl.locate(catalinaBase, null, false);
        if (baseDir == null) {
          baseDir = new File(System.getProperty("netbeans.user"), catalinaBase); // NOI18N
        }
      }
    }

    //        //parse the old format for backward compatibility
    //        if (uriOffset > 0) {
    //            String theUri = uri.substring (uriOffset + uriString.length ());
    //            int portIndex = theUri.indexOf (':');
    //            String host = theUri.substring (0, portIndex - 1);
    //            setHost (host);
    //            //System.out.println("host:"+host);
    //            int portEnd = theUri.indexOf ('/');
    //            portEnd = portEnd > 0 ? portEnd : theUri.length ();
    //            String port = theUri.substring (portIndex, portEnd - 1);
    //            //System.out.println("port:"+port);
    //            try {
    //                setServerPort (Integer.valueOf (port));
    //            } catch (NumberFormatException nef) {
    //                org.openide.ErrorManager.getDefault ().log (nef.getLocalizedMessage ());
    //            }
    //        }
    ip.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (PROP_SERVER_PORT.equals(name)
                || PROP_USERNAME.equals(name)
                || PROP_PASSWORD.equals(name)) {
              // update Ant deployment properties file if it exists
              try {
                storeAntDeploymentProperties(getAntDeploymentPropertiesFile(), false);
              } catch (IOException ioe) {
                Logger.getLogger(TomcatProperties.class.getName()).log(Level.INFO, null, ioe);
              }
            }
          }
        });
  }
  public void initValues(
      final Project project, final FileObject template, final FileObject preselectedFolder) {
    this.project = project;
    this.helper = project.getLookup().lookup(AntProjectHelper.class);
    final Object obj = template.getAttribute(IS_MIDLET_TEMPLATE_ATTRIBUTE);
    isMIDlet = false;
    if (obj instanceof Boolean) isMIDlet = ((Boolean) obj).booleanValue();

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

    final Sources sources = ProjectUtils.getSources(project);
    final SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    final SourceGroup preselectedGroup = getPreselectedGroup(groups, preselectedFolder);
    if (preselectedGroup != null) {
      final ModelItem groupItem = new ModelItem(preselectedGroup);
      final ModelItem[] nodes = groupItem.getChildren();
      packageComboBox.setModel(new DefaultComboBoxModel(nodes));
      final Object folderItem = getPreselectedPackage(groupItem, preselectedFolder);
      if (folderItem != null) packageComboBox.setSelectedItem(folderItem);
    } else {
      packageComboBox.setModel(new DefaultComboBoxModel());
    }

    // Determine the extension
    final String ext = template == null ? "" : template.getExt(); // NOI18N
    expectedExtension = ext.length() == 0 ? "" : "." + ext; // NOI18N

    lName.setVisible(isMIDlet);
    tName.setVisible(isMIDlet);
    lIcon.setVisible(isMIDlet);
    cIcon.setVisible(isMIDlet);
    lNote.setVisible(isMIDlet);
    org.openide.awt.Mnemonics.setLocalizedText(
        lClassName,
        NbBundle.getMessage(
            MIDPTargetChooserPanelGUI.class,
            isMIDlet ? "LBL_File_MIDletClassName" : "LBL_File_MIDPClassName")); // NOI18N

    // Show name of the project
    if (isMIDlet) {
      tName.getDocument().removeDocumentListener(this);
      tName.setText(template.getName());
      updateClassNameAndIcon();
      if (testIfFileNameExists(preselectedGroup) && updateClassName) {
        String name = tName.getText();
        int i = 1;
        for (; ; ) {
          tName.setText(name + "_" + i); // NOI18N
          updateClassNameAndIcon();
          if (!testIfFileNameExists(preselectedGroup) || !updateClassName) break;
          i++;
        }
      }
      tName.getDocument().addDocumentListener(this);
    } else {
      tClassName.setText(template.getName());
      if (testIfFileNameExists(preselectedGroup)) {
        String name = tClassName.getText();
        int i = 1;
        for (; ; ) {
          tClassName.setText(name + "_" + i); // NOI18N
          if (!testIfFileNameExists(preselectedGroup)) break;
          i++;
        }
      }
      tClassName.getDocument().addDocumentListener(this);
    }
    updateText();

    // Find all icons
    if (loadIcons) {
      loadIcons = false;
      final DefaultComboBoxModel icons = new DefaultComboBoxModel();
      cIcon.setModel(icons);
      cIcon.setSelectedItem(""); // NOI18N
      RequestProcessor.getDefault()
          .post(
              new Runnable() {
                public void run() {
                  final ArrayList<FileObject> roots = new ArrayList<FileObject>();
                  roots.add(
                      helper.resolveFileObject(
                          helper.getStandardPropertyEvaluator().getProperty("src.dir"))); // NOI18N
                  final String libs =
                      J2MEProjectUtils.evaluateProperty(
                          helper, DefaultPropertiesDescriptor.LIBS_CLASSPATH);
                  if (libs != null) {
                    final String elements[] = PropertyUtils.tokenizePath(helper.resolvePath(libs));
                    for (int i = 0; i < elements.length; i++)
                      try {
                        final FileObject root =
                            FileUtil.toFileObject(FileUtil.normalizeFile(new File(elements[i])));
                        if (root != null)
                          roots.add(
                              FileUtil.isArchiveFile(root) ? FileUtil.getArchiveRoot(root) : root);
                      } catch (Exception e) {
                      }
                  }
                  for (FileObject root : roots) {
                    if (root != null) {
                      final int rootLength = root.getPath().length();
                      final Enumeration en = root.getChildren(true);
                      while (en.hasMoreElements()) {
                        final FileObject fo = (FileObject) en.nextElement();
                        if (fo.isData()) {
                          final String ext = fo.getExt().toLowerCase();
                          if ("png".equals(ext)) { // NOI18N
                            String name = fo.getPath().substring(rootLength);
                            if (!name.startsWith("/")) name = "/" + name; // NOI18N
                            if (icons.getIndexOf(name) < 0) icons.addElement(name);
                          }
                        }
                      }
                    }
                  }
                }
              });
    }
  }