示例#1
0
  /**
   * Semantics is similar to {@link org.openide.windows.TopComponent#getActivatedNodes()} except
   * that this method returns File objects instead od Nodes. Every node is examined for Files it
   * represents. File and Folder nodes represent their underlying files or folders. Project nodes
   * are represented by their source groups. Other logical nodes must provide FileObjects in their
   * Lookup.
   *
   * @param nodes null (then taken from windowsystem, it may be wrong on editor tabs #66700).
   * @param includingFileStatus if any activated file does not have this CVS status, an empty array
   *     is returned
   * @param includingFolderStatus if any activated folder does not have this CVS status, an empty
   *     array is returned
   * @param onlyCachedStatus if set to true, only cached status will be considered
   * @return File [] array of activated files, or an empty array if any of examined files/folders
   *     does not have given status
   */
  public static Context getCurrentContext(
      Node[] nodes, int includingFileStatus, int includingFolderStatus, boolean onlyCachedStatus) {
    Context context = getCurrentContext(nodes);
    FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache();
    File[] files = context.getRootFiles();
    for (int i = 0; i < files.length; i++) {
      File file = files[i];
      FileInformation fi = onlyCachedStatus ? cache.getCachedStatus(file) : cache.getStatus(file);
      int status = fi == null ? FileInformation.STATUS_VERSIONED_UPTODATE : fi.getStatus();
      if (file.isDirectory()) {
        if ((status & includingFolderStatus) == 0) return Context.Empty;
      } else {
        if ((status & includingFileStatus) == 0) return Context.Empty;
      }
    }
    // if there are no exclusions, we may safely return this context because filtered files == root
    // files
    if (context.getExclusions().isEmpty()) return context;

    // in this code we remove files from filteredFiles to NOT include any files that do not have
    // required status
    // consider a freeform project that has 'build' in filteredFiles, the Branch action would try to
    // branch it
    // so, it is OK to have BranchAction enabled but the context must be a bit adjusted here
    Set<File> filteredFiles = new HashSet<File>(Arrays.asList(context.getFiles()));
    Set<File> rootFiles = new HashSet<File>(Arrays.asList(context.getRootFiles()));
    Set<File> rootFileExclusions = new HashSet<File>(context.getExclusions());

    for (Iterator<File> i = filteredFiles.iterator(); i.hasNext(); ) {
      File file = i.next();
      if (file.isDirectory()) {
        if ((cache.getStatus(file).getStatus() & includingFolderStatus) == 0) i.remove();
      } else {
        if ((cache.getStatus(file).getStatus() & includingFileStatus) == 0) i.remove();
      }
    }
    return new Context(filteredFiles, rootFiles, rootFileExclusions);
  }