Ejemplo n.º 1
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);
    }
  }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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];
   }
 }
Ejemplo n.º 4
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;
 }
  @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);
    }
  }
Ejemplo n.º 6
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);
      }
    }