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
    @Override
    protected void addNotify() {
      super.addNotify();

      Set<Node> children = new TreeSet<Node>();
      FileObject[] kids = sourceRoot.getChildren();
      boolean archive = FileUtil.isArchiveFile(sourceRoot);
      VisibilityQuery vq = VisibilityQuery.getDefault();
      for (int ii = 0; ii < kids.length; ii++) {
        if (archive || vq.isVisible(kids[ii])) {
          if (kids[ii].isFolder()) {
            findVisiblePackages(children, kids[ii], sourceRoot, !archive);
          } else {
            try {
              DataObject data = DataObject.find(kids[ii]);
              // For sorting, wrap a filter around the node.
              Node node = new SortableNode(data.getNodeDelegate());
              children.add(node);
            } catch (DataObjectNotFoundException donfe) {
              // in that case, ignore the file
            }
          }
        }
      }

      // Add the children to our own set (which should be empty).
      Node[] kidsArray = children.toArray(new Node[children.size()]);
      super.add(kidsArray);
    }
Ejemplo n.º 3
0
 public void run() {
   computeKeys();
   refreshKeys();
   try {
     FileSystem fs = root.getFileSystem();
     wfcl = (FileChangeListener) WeakListeners.create(FileChangeListener.class, this, fs);
     fs.addFileChangeListener(wfcl);
   } catch (FileStateInvalidException e) {
     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
   }
   wvqcl = WeakListeners.change(this, VisibilityQuery.getDefault());
   VisibilityQuery.getDefault().addChangeListener(wvqcl);
 }
Ejemplo n.º 4
0
  public void fileRenamed(FileRenameEvent fe) {
    FileObject fo = fe.getFile();
    if (FileUtil.isParentOf(root, fo) && fo.isFolder()) {
      String rp = FileUtil.getRelativePath(root, fo.getParent());
      String oldPath = rp + (rp.length() == 0 ? "" : "/") + fe.getName() + fe.getExt(); // NOI18N

      boolean visible = VisibilityQuery.getDefault().isVisible(fo);
      boolean doUpdate = false;

      // Find all entries which have to be updated
      ArrayList needsUpdate = new ArrayList();
      for (Iterator it = names2nodes.keySet().iterator(); it.hasNext(); ) {
        String p = (String) it.next();
        if (p.startsWith(oldPath)) {
          if (visible) {
            needsUpdate.add(p);
          } else {
            names2nodes.remove(p);
            doUpdate = true;
          }
        }
      }

      // If the node does not exists then there might have been update
      // from ignored to non ignored
      if (get(fo) == null && visible) {
        cleanEmptyKeys(fo);
        findNonExcludedPackages(fo);
        doUpdate = true; // force refresh
      }

      int oldPathLen = oldPath.length();
      String newPath = FileUtil.getRelativePath(root, fo);
      for (Iterator it = needsUpdate.iterator(); it.hasNext(); ) {
        String p = (String) it.next();
        StringBuffer np = new StringBuffer(p);
        np.replace(0, oldPathLen, newPath);
        PackageNode n = updatePath(p, np.toString()); // Replace entries in cache
        if (n != null) {
          n.updateDisplayName(); // Update nodes
        }
      }

      if (needsUpdate.size() > 1 || doUpdate) {
        // Sorting might change
        refreshKeys();
      }
    }
    /*
    else if ( FileUtil.isParentOf( root, fo ) && fo.isFolder() ) {
        FileObject parent = fo.getParent();
        PackageNode n = get( parent );
        if ( n != null && VisibilityQuery.getDefault().isVisible( parent ) ) {
            n.updateChildren();
        }

    }
    */

  }
Ejemplo n.º 5
0
 @Override
 public boolean acceptDataObject(DataObject obj) {
   if (obj instanceof DataFolder) {
     return false;
   }
   FileObject fo = obj.getPrimaryFile();
   return VisibilityQuery.getDefault().isVisible(fo);
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
0
  /** Test whether file and all it's parent up to parent paremeter are visible */
  private boolean isVisible(FileObject parent, FileObject file) {

    do {
      if (!VisibilityQuery.getDefault().isVisible(file)) {
        return false;
      }
      file = file.getParent();
    } while (file != null && file != parent);

    return true;
  }
Ejemplo n.º 8
0
 protected void removeNotify() {
   VisibilityQuery.getDefault().removeChangeListener(wvqcl);
   try {
     root.getFileSystem().removeFileChangeListener(wfcl);
   } catch (FileStateInvalidException e) {
     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
   }
   setKeys(Collections.EMPTY_SET);
   names2nodes.clear();
   super.removeNotify();
 }
Ejemplo n.º 9
0
 /**
  * Check whether a package is empty (devoid of files except for subpackages).
  *
  * <p>
  *
  * @param fo file object to check.
  * @param recurse specifies whether to check if subpackages are empty too.
  */
 private static boolean isEmpty(FileObject fo, boolean recurse) {
   if (fo != null) {
     FileObject[] kids = fo.getChildren();
     for (int ii = 0; ii < kids.length; ii++) {
       if (!kids[ii].isFolder() && VisibilityQuery.getDefault().isVisible(kids[ii])) {
         return false;
       } else if (recurse && !isEmpty(kids[ii])) {
         return false;
       }
     }
   }
   return true;
 }
Ejemplo n.º 10
0
 public void fileDataCreated(FileEvent fe) {
   FileObject fo = fe.getFile();
   if (FileUtil.isParentOf(root, fo) && isVisible(root, fo)) {
     FileObject parent = fo.getParent();
     if (!VisibilityQuery.getDefault().isVisible(parent)) {
       return; // Adding file into ignored directory
     }
     PackageNode n = get(parent);
     if (n == null && !contains(parent)) {
       add(parent, false);
       refreshKeys();
     } else if (n != null) {
       n.updateChildren();
     }
   }
 }
Ejemplo n.º 11
0
 /**
  * Returns true if the folder should be removed from the view i.e. it has some unignored children
  * and the children are folders only
  */
 private boolean toBeRemoved(FileObject folder) {
   boolean ignoredOnly = true;
   boolean foldersOnly = true;
   FileObject kids[] = folder.getChildren();
   for (int i = 0; i < kids.length; i++) {
     if (VisibilityQuery.getDefault().isVisible(kids[i])) {
       ignoredOnly = false;
       if (!kids[i].isFolder()) {
         foldersOnly = false;
         break;
       }
     }
   }
   if (ignoredOnly) {
     return false; // It is either empty or it only contains ignored files
     // thus is leaf and it means package
   } else {
     return foldersOnly;
   }
 }
Ejemplo n.º 12
0
 public NoFoldersDataFilter() {
   VisibilityQuery.getDefault().addChangeListener(this);
 }
Ejemplo n.º 13
0
 public boolean acceptDataObject(DataObject obj) {
   FileObject fo = obj.getPrimaryFile();
   return VisibilityQuery.getDefault().isVisible(fo) && !(obj instanceof DataFolder);
 }