Пример #1
0
  public void fileDeleted(FileEvent fe) {
    FileObject fo = fe.getFile();
    if (FileUtil.isParentOf(root, fo) && isVisible(root, fo)) {
      if (fo.isFolder() || get(fo) != null) {
        removeSubTree(fo);
        // Now add the parent if necessary
        FileObject parent = fo.getParent();
        if ((FileUtil.isParentOf(root, parent) || root.equals(parent))
            && get(parent) == null
            && parent.isValid()) {
          // Candidate for adding
          if (!toBeRemoved(parent)) {
            add(parent, true);
          }
        }
        refreshKeysAsync();
      } else {
        FileObject parent = fo.getParent();
        final PackageNode n = get(parent);
        if (n != null) {
          // #61027: workaround to a deadlock when the package is being changed from non-leaf to
          // leaf:
          boolean leaf = n.isLeaf();
          DataFolder df = n.getDataFolder();
          boolean empty = n.isEmpty(df);

          if (leaf != empty) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    n.updateChildren();
                  }
                });
          } else {
            n.updateChildren();
          }
        }
        // If the parent folder only contains folders remove it
        if (toBeRemoved(parent)) {
          remove(parent);
          refreshKeysAsync();
        }
      }
    }
  }
Пример #2
0
  /** Finds all empty parents of given package and deletes them */
  private void cleanEmptyKeys(FileObject fo) {
    FileObject parent = fo.getParent();

    // Special case for default package
    if (root.equals(parent)) {
      PackageNode n = get(parent);
      // the default package is considered empty if it only contains folders,
      // regardless of the contents of these folders (empty or not)
      if (n != null && PackageDisplayUtils.isEmpty(root, false)) {
        remove(root);
      }
      return;
    }

    while (FileUtil.isParentOf(root, parent)) {
      PackageNode n = get(parent);
      if (n != null && n.isLeaf()) {
        remove(parent);
      }
      parent = parent.getParent();
    }
  }