protected IResource[] checkOverwriteOfDirtyResources(
      IResource[] resources, IProgressMonitor monitor) throws CVSException, InterruptedException {
    List dirtyResources = new ArrayList();
    IResource[] selectedResources = getSelectedResources();

    try {
      monitor = Policy.monitorFor(monitor);
      monitor.beginTask(null, selectedResources.length * 100);
      monitor.setTaskName(CVSUIMessages.ReplaceWithAction_calculatingDirtyResources);
      for (int i = 0; i < selectedResources.length; i++) {
        IResource resource = selectedResources[i];
        ICVSResource cvsResource = getCVSResourceFor(resource);
        if (cvsResource.isModified(Policy.subMonitorFor(monitor, 100))) {
          dirtyResources.add(resource);
        }
      }
    } finally {
      monitor.done();
    }

    PromptingDialog dialog =
        new PromptingDialog(
            getShell(),
            selectedResources,
            getPromptCondition(
                (IResource[]) dirtyResources.toArray(new IResource[dirtyResources.size()])),
            CVSUIMessages.ReplaceWithAction_confirmOverwrite);
    return dialog.promptForMultiple();
  }
  /**
   * Prime the remote tree with the sync info from the local workspace. This is done to ensure that
   * we don't get a huge number of outgoing changes before the first refresh.
   */
  public void primeRemoteTree() throws CVSException {
    for (int i = 0; i < resources.length; i++) {
      IResource resource = resources[i];
      ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
      cvsResource.accept(
          new ICVSResourceVisitor() {
            public void visitFile(ICVSFile file) throws CVSException {
              byte[] bytes = file.getSyncBytes();
              if (bytes != null) {
                try {
                  tree.getByteStore().setBytes(file.getIResource(), bytes);
                } catch (TeamException e) {
                  throw CVSException.wrapException(e);
                }
              }
            }

            public void visitFolder(ICVSFolder folder) throws CVSException {
              // No need to copy sync info for folders since
              // CVS resource variant tree will get missing
              // folder info from the local resources
              folder.acceptChildren(this);
            }
          });
    }
  }
 /**
  * Method isEnabledForCVSResource.
  *
  * @param cvsResource
  * @return boolean
  */
 protected boolean isEnabledForCVSResource(ICVSResource cvsResource) throws CVSException {
   boolean managed = false;
   boolean ignored = false;
   boolean added = false;
   if (cvsResource.isIgnored()) {
     ignored = true;
   } else if (cvsResource.isFolder()) {
     managed = ((ICVSFolder) cvsResource).isCVSFolder();
   } else {
     ResourceSyncInfo info = cvsResource.getSyncInfo();
     managed = info != null;
     if (managed) added = info.isAdded();
   }
   if (managed && !isEnabledForManagedResources()) return false;
   if (!managed && !isEnabledForUnmanagedResources()) return false;
   if (ignored && !isEnabledForIgnoredResources()) return false;
   if (added && !isEnabledForAddedResources()) return false;
   if (!cvsResource.exists() && !isEnabledForNonExistantResources()) return false;
   return true;
 }
  /**
   * Given the current selection this method returns a text label that can be shown to the user that
   * reflects the tags in the current selection. These can be used in the <b>Compare With</b> and
   * <b>Replace With</b> actions.
   */
  protected String calculateActionTagValue() {
    try {
      IResource[] resources = getSelectedResources();
      CVSTag commonTag = null;
      boolean sameTagType = true;
      boolean multipleSameNames = true;

      for (int i = 0; i < resources.length; i++) {
        ICVSResource cvsResource = getCVSResourceFor(resources[i]);
        CVSTag tag = null;
        if (cvsResource.isFolder()) {
          FolderSyncInfo info = ((ICVSFolder) cvsResource).getFolderSyncInfo();
          if (info != null) {
            tag = info.getTag();
          }
          if (tag != null && tag.getType() == CVSTag.BRANCH) {
            tag = Util.getAccurateFolderTag(resources[i], tag);
          }
        } else {
          tag = Util.getAccurateFileTag(cvsResource);
        }
        if (tag == null) {
          tag = new CVSTag();
        }
        if (commonTag == null) {
          commonTag = tag;
        } else if (!commonTag.equals(tag)) {
          if (commonTag.getType() != tag.getType()) {
            sameTagType = false;
          }
          if (!commonTag.getName().equals(tag.getName())) {
            multipleSameNames = false;
          }
        }
      }

      // set text to default
      String actionText = CVSUIMessages.ReplaceWithLatestAction_multipleTags;
      if (commonTag != null) {
        int tagType = commonTag.getType();
        String tagName = commonTag.getName();
        // multiple tag names but of the same type
        if (sameTagType && !multipleSameNames) {
          if (tagType == CVSTag.BRANCH) {
            actionText = CVSUIMessages.ReplaceWithLatestAction_multipleBranches; //
          } else {
            actionText = CVSUIMessages.ReplaceWithLatestAction_multipleVersions;
          }
          // same tag names and types
        } else if (sameTagType && multipleSameNames) {
          if (tagType == CVSTag.BRANCH) {
            actionText =
                NLS.bind(
                    CVSUIMessages.ReplaceWithLatestAction_singleBranch, new String[] {tagName}); //
          } else if (tagType == CVSTag.VERSION) {
            actionText =
                NLS.bind(
                    CVSUIMessages.ReplaceWithLatestAction_singleVersion, new String[] {tagName});
          } else if (tagType == CVSTag.HEAD) {
            actionText =
                NLS.bind(CVSUIMessages.ReplaceWithLatestAction_singleHEAD, new String[] {tagName});
          }
        }
      }

      return actionText;
    } catch (CVSException e) {
      // silently ignore
      return CVSUIMessages.ReplaceWithLatestAction_multipleTags; //
    }
  }