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();
  }
Пример #2
0
 private ICVSRepositoryLocation internalGetRepositoryLocationFor(ICVSResource resource)
     throws CVSException {
   ICVSFolder folder;
   if (resource.isFolder()) {
     folder = (ICVSFolder) resource;
   } else {
     folder = resource.getParent();
   }
   if (folder.isCVSFolder()) {
     ICVSRepositoryLocation location =
         KnownRepositories.getInstance().getRepository(folder.getFolderSyncInfo().getRoot());
     return location;
   }
   // XXX This is asking for trouble
   return null;
 }
 /**
  * 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; //
    }
  }