Пример #1
0
    public void destroy() throws IOException {
      FileObject parent = dataFolder.getPrimaryFile().getParent();
      // First; delete all files except packages
      DataObject ch[] = dataFolder.getChildren();
      boolean empty = true;
      for (int i = 0; ch != null && i < ch.length; i++) {
        if (!ch[i].getPrimaryFile().isFolder()) {
          ch[i].delete();
        } else {
          empty = false;
        }
      }

      // If empty delete itself
      if (empty) {
        super.destroy();
      }

      // Second; delete empty super packages
      while (!parent.equals(root) && parent.getChildren().length == 0) {
        FileObject newParent = parent.getParent();
        parent.delete();
        parent = newParent;
      }
    }
Пример #2
0
 /**
  * Constructs a new instance of PackageNode.
  *
  * <p>
  *
  * @param root root of the package.
  * @param folder a package within root.
  */
 public PackageNode(FileObject root, DataFolder folder) {
   // DataFolder children are loaded on demand.
   super(
       folder.getNodeDelegate(),
       isEmpty(folder) ? Children.LEAF : folder.createNodeChildren(FILTER));
   sourcePkg = folder.getPrimaryFile();
   String path = FileUtil.getRelativePath(root, sourcePkg);
   displayName = path.replace('/', '.');
 }
Пример #3
0
 public void updateChildren() {
   boolean leaf = isLeaf();
   DataFolder df = getDataFolder();
   boolean empty = isEmpty(df);
   if (leaf != empty) {
     setChildren(empty ? Children.LEAF : df.createNodeChildren(NO_FOLDERS_FILTER));
     update();
   }
 }
Пример #4
0
  private void addTasks(DataObject obj, List<RenameTask> tasks, RenameClient[] clients) {
    for (RenameClient client : clients) tasks.addAll(client.renamed(obj));

    if (obj instanceof DataFolder) {
      DataFolder folder = (DataFolder) obj;
      Enumeration<DataObject> children = folder.children(true);
      while (children.hasMoreElements()) {
        DataObject child = children.nextElement();
        for (RenameClient client : clients) tasks.addAll(client.renamed(child));
      }
    }
  }
Пример #5
0
 @Override
 protected DataObject handleCopyRename(DataFolder df, String name, String ext) throws IOException {
   FileObject fo = getPrimaryEntry().copyRename(df.getPrimaryFile(), name, ext);
   DataObject dob = DataObject.find(fo);
   // TODO invoke refactoring here (if needed)
   return dob;
 }
Пример #6
0
  /**
   * Scans the directory structure starting at root, looking for folders that are either empty or
   * contain files, adding them to the set.
   *
   * <p>
   *
   * @param children set to which nodes are added.
   * @param fo file object to examine.
   * @param root root of the package hierarchy.
   * @param query true to query for visibility of files.
   */
  private static void findVisiblePackages(
      Set<Node> children, FileObject fo, FileObject root, boolean query) {

    VisibilityQuery vq = VisibilityQuery.getDefault();
    if (query && !vq.isVisible(fo)) {
      return;
    }

    FileObject[] kids = fo.getChildren();
    boolean hasSubfolders = false;
    boolean hasFiles = false;
    for (int ii = 0; ii < kids.length; ii++) {
      if (!query || vq.isVisible(kids[ii])) {
        if (kids[ii].isFolder()) {
          findVisiblePackages(children, kids[ii], root, query);
          hasSubfolders = true;
        } else {
          hasFiles = true;
        }
      }
    }
    if (hasFiles || !hasSubfolders) {
      DataFolder df = DataFolder.findFolder(fo);
      PackageNode pn = new PackageNode(root, df);
      children.add(pn);
    }
  }
Пример #7
0
 private DataFolder getFolder(String propName) {
   FileObject fo = helper.resolveFileObject(evaluator.getProperty(propName));
   if (fo != null) {
     DataFolder df = DataFolder.findFolder(fo);
     return df;
   }
   return null;
 }
Пример #8
0
      public ZipNode(FileObject key) throws DataObjectNotFoundException {
        super(
            DataFolder.find(key).getNodeDelegate(),
            new FilterNode.Children(DataFolder.find(key).getNodeDelegate()),
            new AbstractLookup(instanceContent = new InstanceContent()));
        setDisplayName(key.getName() + ".zip");
        key.addRecursiveListener(
            new FileChangeListener() {
              @Override
              public void fileFolderCreated(FileEvent fe) {
                modify(fe.getFile());
              }

              @Override
              public void fileDataCreated(FileEvent fe) {
                modify(fe.getFile());
              }

              @Override
              public void fileChanged(FileEvent fe) {
                modify(fe.getFile());
              }

              @Override
              public void fileDeleted(FileEvent fe) {
                modify(fe.getFile());
              }

              @Override
              public void fileRenamed(FileRenameEvent fre) {
                modify(fre.getFile());
              }

              @Override
              public void fileAttributeChanged(FileAttributeEvent fae) {
                modify(fae.getFile());
              }

              private void modify(FileObject file) {
                if (getLookup().lookup(ZIPSavable.class) == null) {
                  instanceContent.add(new ZIPSavable(file));
                }
              }
            });
      }
Пример #9
0
 public String getDisplayName() {
   FileObject folder = dataFolder.getPrimaryFile();
   String path = FileUtil.getRelativePath(root, folder);
   if (path == null) {
     // ???
     return "";
   }
   return PackageDisplayUtils.getDisplayLabel(path.replace('/', '.'));
 }
Пример #10
0
 private Image getMyIcon(int type) {
   FileObject folder = dataFolder.getPrimaryFile();
   String path = FileUtil.getRelativePath(root, folder);
   if (path == null) {
     // ???
     return null;
   }
   return PackageDisplayUtils.getIcon(folder, path.replace('/', '.'), isLeaf());
 }
Пример #11
0
 protected Node[] createNodes(Object obj) {
   FileObject fo = root.getFileObject((String) obj);
   if (fo != null && fo.isValid()) {
     Object o = names2nodes.get(obj);
     PackageNode n;
     if (o == NODE_NOT_CREATED) {
       n = new PackageNode(root, DataFolder.findFolder(fo), false);
     } else if (o == NODE_NOT_CREATED_EMPTY) {
       n = new PackageNode(root, DataFolder.findFolder(fo), true);
     } else {
       n = new PackageNode(root, DataFolder.findFolder(fo));
     }
     names2nodes.put(obj, n);
     return new Node[] {n};
   } else {
     return new Node[0];
   }
 }
Пример #12
0
 public String getShortDescription() {
   FileObject folder = dataFolder.getPrimaryFile();
   String path = FileUtil.getRelativePath(root, folder);
   if (path == null) {
     // ???
     return "";
   }
   return PackageDisplayUtils.getToolTip(folder, path.replace('/', '.'));
 }
Пример #13
0
 public Transferable paste() throws IOException {
   assert this.op != DnDConstants.ACTION_NONE;
   for (int ni = 0; ni < nodes.length; ni++) {
     FileObject fo = srcRoot;
     if (!nodes[ni].isDefaultPackage) {
       String pkgName = nodes[ni].getName();
       StringTokenizer tk = new StringTokenizer(pkgName, "."); // NOI18N
       while (tk.hasMoreTokens()) {
         String name = tk.nextToken();
         FileObject tmp = fo.getFileObject(name, null);
         if (tmp == null) {
           tmp = fo.createFolder(name);
         }
         fo = tmp;
       }
     }
     DataFolder dest = DataFolder.findFolder(fo);
     DataObject[] children = nodes[ni].dataFolder.getChildren();
     boolean cantDelete = false;
     for (int i = 0; i < children.length; i++) {
       if (children[i].getPrimaryFile().isData()
           && VisibilityQuery.getDefault().isVisible(children[i].getPrimaryFile())) {
         // Copy only the package level
         children[i].copy(dest);
         if (this.op == DnDConstants.ACTION_MOVE) {
           try {
             children[i].delete();
           } catch (IOException ioe) {
             cantDelete = true;
           }
         }
       } else {
         cantDelete = true;
       }
     }
     if (this.op == DnDConstants.ACTION_MOVE && !cantDelete) {
       try {
         FileObject tmpFo = nodes[ni].dataFolder.getPrimaryFile();
         FileObject originalRoot = nodes[ni].root;
         assert tmpFo != null && originalRoot != null;
         while (!tmpFo.equals(originalRoot)) {
           if (tmpFo.getChildren().length == 0) {
             FileObject tmpFoParent = tmpFo.getParent();
             tmpFo.delete();
             tmpFo = tmpFoParent;
           } else {
             break;
           }
         }
       } catch (IOException ioe) {
         // Not important
       }
     }
   }
   return ExTransferable.EMPTY;
 }
Пример #14
0
 public PackageNode(FileObject root, DataFolder dataFolder, boolean empty) {
   super(
       dataFolder.getNodeDelegate(),
       empty ? Children.LEAF : dataFolder.createNodeChildren(NO_FOLDERS_FILTER),
       new ProxyLookup(
           new Lookup[] {
             Lookups.singleton(new NoFoldersContainer(dataFolder)),
             dataFolder.getNodeDelegate().getLookup(),
             Lookups.singleton(
                 PackageRootNode.alwaysSearchableSearchInfo(
                     SearchInfoFactory.createSearchInfo(
                         dataFolder.getPrimaryFile(),
                         false, // not recursive
                         new FileObjectFilter[] {SearchInfoFactory.VISIBILITY_FILTER}))),
           }));
   this.root = root;
   this.dataFolder = dataFolder;
   this.isDefaultPackage = root.equals(dataFolder.getPrimaryFile());
 }
Пример #15
0
    public DataObject[] getChildren() {
      DataObject[] arr = folder.getChildren();
      ArrayList list = new ArrayList(arr.length);
      for (int i = 0; i < arr.length; i++) {
        if (arr[i] instanceof DataFolder) continue;

        list.add(arr[i]);
      }
      return list.size() == arr.length ? arr : (DataObject[]) list.toArray(new DataObject[0]);
    }
Пример #16
0
  private void createFile() {
    if (result != null && result.indexOf('\\') == -1) { // NOI18N

      if (!targetFolder.getPrimaryFile().canWrite()) {
        return;
      }

      DataObject dObj = null;

      try {
        FileObject fo =
            type == TYPE_FILE
                ? FileUtil.createData(targetFolder.getPrimaryFile(), result)
                : FileUtil.createFolder(targetFolder.getPrimaryFile(), result);
        if (fo != null) {
          dObj = DataObject.find(fo);
        }
      } catch (DataObjectNotFoundException e) {
        // No data object no open
      } catch (IOException e) {
        // XXX
      }

      if (result != null) {
        // handle new template in SystemFileSystem
        DataObject rootDO = findTemplate("/Templates"); // NOI18N
        if (rootDO != null && dObj != null) {
          if (FileUtil.isParentOf(rootDO.getPrimaryFile(), dObj.getPrimaryFile())) {
            try {
              dObj.setTemplate(true);
            } catch (IOException e) {
              // can ignore
            }
          }
        }
      }
      if (dObj != null) {
        ProjectUtilities.openAndSelectNewObject(dObj);
      }
    }
  }
Пример #17
0
    public java.awt.Image getOpenedIcon(int type) {
      java.awt.Image img = getMyOpenedIcon(type);

      try {
        FileObject fo = dataFolder.getPrimaryFile();
        Set set = new NonResursiveFolderSet(fo);
        img = fo.getFileSystem().getStatus().annotateIcon(img, type, set);
      } catch (FileStateInvalidException e) {
        // no fs, do nothing
      }

      return img;
    }
  @Override
  public Node createLogicalView() {
    try {
      // Get the Text directory, creating if deleted
      FileObject dir = project.getProjectDirectory();

      // Get the DataObject that represents it
      DataFolder textDataObject = DataFolder.findFolder(dir);

      // Get its default node-we'll wrap our node around it to change the
      // display name, icon, etc
      Node realTextFolderNode = textDataObject.getNodeDelegate();

      // This FilterNode will be our project node
      return new RootNode(realTextFolderNode, project);

    } catch (DataObjectNotFoundException donfe) {
      Exceptions.printStackTrace(donfe);
      // Fallback-the directory couldn't be created -
      // read-only filesystem or something evil happened
      return new AbstractNode(Children.LEAF);
    }
  }
Пример #19
0
 /**
  * Initially overridden to support CVS status labels in package nodes.
  *
  * @return annotated display name
  */
 public String getHtmlDisplayName() {
   String name = getDisplayName();
   try {
     FileObject fo = dataFolder.getPrimaryFile();
     Set set = new NonResursiveFolderSet(fo);
     org.openide.filesystems.FileSystem.Status status = fo.getFileSystem().getStatus();
     if (status instanceof org.openide.filesystems.FileSystem.HtmlStatus) {
       name =
           ((org.openide.filesystems.FileSystem.HtmlStatus) status).annotateNameHtml(name, set);
     } else {
       name = status.annotateName(name, set);
     }
   } catch (FileStateInvalidException e) {
     // no fs, do nothing
   }
   return name;
 }
Пример #20
0
  @Override
  public void changedUpdate(javax.swing.event.DocumentEvent e) {

    String fileName = getFileName();

    if (fileName.length() == 0) {
      okOption.setEnabled(false);
      return;
    }

    FileObject fo = targetFolder.getPrimaryFile().getFileObject(fileName);
    if (fo != null) {
      okOption.setEnabled(false);
      return;
    }

    okOption.setEnabled(true);
  }
Пример #21
0
  protected Node[] createNodes(Object key) {
    // interpret your key here...usually one node generated, but could be zero or more
    FileObject fo = (FileObject) key;

    try {
      DataObject dataObject = DataFolder.find(fo);

      String name = fo.getNameExt();

      if (name.equals("Input.xml")) { // NOI18N
        return new Node[] {new TestCaseInputNode(mProject, dataObject)};
      } else if (name.equals("Output.xml")) { // NOI18N
        return new Node[] {new TestCaseOutputNode(mProject, dataObject)};
      } else {
        return new Node[] {new TestCaseResultNode(mProject, dataObject)};
      }
    } catch (DataObjectNotFoundException e) {
      // Ignore on purpose. This could happen on test case deletion.
    }

    return new Node[0];
  }
Пример #22
0
 protected @Override DataObject handleCreateFromTemplate(DataFolder df, String name)
     throws IOException {
   if (name == null
       && language != null
       && language.getGsfLanguage().getPreferredExtension() != null) {
     // special case: name is null (unspecified or from one-parameter createFromTemplate)
     name =
         FileUtil.findFreeFileName(
             df.getPrimaryFile(),
             getPrimaryFile().getName(),
             language.getGsfLanguage().getPreferredExtension());
   }
   //        else if (!language.getGsfLanguage().isIdentifierChar(c)
   // Utilities.isJavaIdentifier(name)) {
   //            throw new IOException (NbBundle.getMessage(GsfDataObject.class,
   // "FMT_Not_Valid_FileName", language.getDisplayName(), name));
   //        }
   // IndentFileEntry entry = (IndentFileEntry)getPrimaryEntry();
   // entry.initializeIndentEngine();
   try {
     templateLanguage = language;
     DataObject retValue = super.handleCreateFromTemplate(df, name);
     FileObject fo = retValue.getPrimaryFile();
     assert fo != null;
     //        ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
     //        String pkgName;
     //        if (cp != null) {
     //            pkgName = cp.getResourceName(fo.getParent(),'.',false);
     //        }
     //        else {
     //            pkgName = "";   //NOI18N
     //        }
     //        renameJDO (retValue, pkgName, name, this.getPrimaryFile().getName());
     return retValue;
   } finally {
     templateLanguage = null;
   }
 }
Пример #23
0
 /**
  * Determines if the given folder is empty or not.
  *
  * <p>
  *
  * @param folder data folder to check.
  * @return true if folder is empty, false otherwise.
  */
 private static boolean isEmpty(DataFolder folder) {
   if (folder == null) {
     return true;
   }
   return SourcesView.isEmpty(folder.getPrimaryFile());
 }
Пример #24
0
 public FileObject getFolder() {
   return folder.getPrimaryFile();
 }
Пример #25
0
 private static boolean isEmpty(DataFolder dataFolder) {
   if (dataFolder == null) {
     return true;
   }
   return PackageDisplayUtils.isEmpty(dataFolder.getPrimaryFile());
 }
Пример #26
0
 public String getName() {
   String relativePath = FileUtil.getRelativePath(root, dataFolder.getPrimaryFile());
   return relativePath == null ? null : relativePath.replace('/', '.'); // NOI18N
 }
Пример #27
0
    public void setName(String name) {
      PackageRenameHandler handler = getRenameHandler();
      if (handler != null) {
        handler.handleRename(this, name);
        return;
      }

      if (isDefaultPackage) {
        return;
      }
      String oldName = getName();
      if (oldName.equals(name)) {
        return;
      }
      if (!isValidPackageName(name)) {
        DialogDisplayer.getDefault()
            .notify(
                new NotifyDescriptor.Message(
                    NbBundle.getMessage(PackageViewChildren.class, "MSG_InvalidPackageName"),
                    NotifyDescriptor.INFORMATION_MESSAGE));
        return;
      }
      name = name.replace('.', '/') + '/'; // NOI18N
      oldName = oldName.replace('.', '/') + '/'; // NOI18N
      int i;
      for (i = 0; i < oldName.length() && i < name.length(); i++) {
        if (oldName.charAt(i) != name.charAt(i)) {
          break;
        }
      }
      i--;
      int index = oldName.lastIndexOf('/', i); // NOI18N
      String commonPrefix = index == -1 ? null : oldName.substring(0, index);
      String toCreate = (index + 1 == name.length()) ? "" : name.substring(index + 1); // NOI18N
      try {
        FileObject commonFolder =
            commonPrefix == null ? this.root : this.root.getFileObject(commonPrefix);
        FileObject destination = commonFolder;
        StringTokenizer dtk = new StringTokenizer(toCreate, "/"); // NOI18N
        while (dtk.hasMoreTokens()) {
          String pathElement = dtk.nextToken();
          FileObject tmp = destination.getFileObject(pathElement);
          if (tmp == null) {
            tmp = destination.createFolder(pathElement);
          }
          destination = tmp;
        }
        FileObject source = this.dataFolder.getPrimaryFile();
        DataFolder sourceFolder = DataFolder.findFolder(source);
        DataFolder destinationFolder = DataFolder.findFolder(destination);
        DataObject[] children = sourceFolder.getChildren();
        for (int j = 0; j < children.length; j++) {
          if (children[j].getPrimaryFile().isData()) {
            children[j].move(destinationFolder);
          }
        }
        while (!commonFolder.equals(source)) {
          if (source.getChildren().length == 0) {
            FileObject tmp = source;
            source = source.getParent();
            tmp.delete();
          } else {
            break;
          }
        }
      } catch (IOException ioe) {
        ErrorManager.getDefault().notify(ioe);
      }
    }