/*
  * The order in the diaog should be HEAD, Branches, Versions, Dates, BASE
  */
 public int category(Object element) {
   if (element instanceof TagElement) {
     CVSTag tag = ((TagElement) element).getTag();
     if (tag == CVSTag.DEFAULT) return 1;
     if (tag == CVSTag.BASE) return 5;
     if (tag.getType() == CVSTag.BRANCH) return 2;
     if (tag.getType() == CVSTag.VERSION) return 3;
     if (tag.getType() == CVSTag.DATE) return 4;
   } else if (element instanceof TagRootElement) {
     if (((TagRootElement) element).getTypeOfTagRoot() == CVSTag.BRANCH) return 2;
     if (((TagRootElement) element).getTypeOfTagRoot() == CVSTag.VERSION) return 3;
     if (((TagRootElement) element).getTypeOfTagRoot() == CVSTag.DATE) return 4;
   }
   return 0;
 }
예제 #2
0
  /** Get the list of known branch tags for a given remote root. */
  public CVSTag[] getKnownTags(ICVSFolder project, int tagType) {
    try {
      CVSTag[] tags = getKnownTags(project);
      Set result = new HashSet();
      for (int i = 0; i < tags.length; i++) {
        CVSTag tag = tags[i];
        if (tag.getType() == tagType) result.add(tag);
      }

      return (CVSTag[]) result.toArray(new CVSTag[result.size()]);
    } catch (CVSException e) {
      CVSUIPlugin.log(e);
      return new CVSTag[0];
    }
  }
예제 #3
0
 public ICVSRemoteResource[] getFoldersForTag(
     ICVSRepositoryLocation location, CVSTag tag, IProgressMonitor monitor) throws CVSException {
   monitor = Policy.monitorFor(monitor);
   try {
     monitor.beginTask(
         NLS.bind(
             CVSUIMessages.RepositoryManager_fetchingRemoteFolders, new String[] {tag.getName()}),
         100);
     if (tag.getType() == CVSTag.HEAD) {
       ICVSRemoteResource[] resources =
           location.members(tag, false, Policy.subMonitorFor(monitor, 60));
       RepositoryRoot root = getRepositoryRootFor(location);
       ICVSRemoteResource[] modules =
           root.getDefinedModules(tag, Policy.subMonitorFor(monitor, 40));
       ICVSRemoteResource[] result = new ICVSRemoteResource[resources.length + modules.length];
       System.arraycopy(resources, 0, result, 0, resources.length);
       System.arraycopy(modules, 0, result, resources.length, modules.length);
       return result;
     }
     if (tag.getType() == CVSTag.DATE) {
       ICVSRemoteResource[] resources =
           location.members(tag, false, Policy.subMonitorFor(monitor, 60));
       RepositoryRoot root = getRepositoryRootFor(location);
       ICVSRemoteResource[] modules =
           root.getDefinedModules(tag, Policy.subMonitorFor(monitor, 40));
       ICVSRemoteResource[] result = new ICVSRemoteResource[resources.length + modules.length];
       System.arraycopy(resources, 0, result, 0, resources.length);
       System.arraycopy(modules, 0, result, resources.length, modules.length);
       return result;
     }
     Set result = new HashSet();
     // Get the tags for the location
     RepositoryRoot root = getRepositoryRootFor(location);
     String[] paths = root.getKnownRemotePaths();
     for (int i = 0; i < paths.length; i++) {
       String path = paths[i];
       List tags = Arrays.asList(root.getAllKnownTags(path));
       if (tags.contains(tag)) {
         ICVSRemoteFolder remote =
             root.getRemoteFolder(path, tag, Policy.subMonitorFor(monitor, 100));
         result.add(remote);
       }
     }
     return (ICVSRemoteResource[]) result.toArray(new ICVSRemoteResource[result.size()]);
   } finally {
     monitor.done();
   }
 }
 public int compare(Viewer viewer, Object e1, Object e2) {
   int cat1 = category(e1);
   int cat2 = category(e2);
   if (cat1 != cat2) return cat1 - cat2;
   // Sort version tags in reverse order
   if (e1 instanceof TagElement) {
     CVSTag tag1 = ((TagElement) e1).getTag();
     int type = tag1.getType();
     if (type == CVSTag.VERSION) {
       return -1 * super.compare(viewer, e1, e2);
     } else if (type == CVSTag.DATE) {
       return -1 * tag1.compareTo(((TagElement) e2).getTag());
     }
   }
   return super.compare(viewer, e1, e2);
 }
예제 #5
0
 /** Get the list of known version tags for a given project. */
 public CVSTag[] getKnownTags(ICVSRepositoryLocation location, int tagType) {
   Set result = new HashSet();
   RepositoryRoot root = (RepositoryRoot) repositoryRoots.get(location.getLocation(false));
   if (root != null) {
     String[] paths = root.getKnownRemotePaths();
     for (int i = 0; i < paths.length; i++) {
       String path = paths[i];
       CVSTag[] tags = root.getAllKnownTags(path);
       for (int j = 0; j < tags.length; j++) {
         CVSTag tag = tags[j];
         if (tag.getType() == tagType) result.add(tag);
       }
     }
   }
   return (CVSTag[]) result.toArray(new CVSTag[0]);
 }
예제 #6
0
  /**
   * Return the appropriate Tag label for properties pages based on the tag type.
   *
   * @param tag
   * @return String
   */
  public static String getTagLabel(CVSTag tag) {

    if (tag == null) {
      return CVSUIMessages.CVSFilePropertiesPage_none;
    }

    switch (tag.getType()) {
      case CVSTag.HEAD:
        return tag.getName();
      case CVSTag.VERSION:
        return NLS.bind(CVSUIMessages.CVSFilePropertiesPage_version, new String[] {tag.getName()});
      case CVSTag.BRANCH:
        return NLS.bind(CVSUIMessages.CVSFilePropertiesPage_branch, new String[] {tag.getName()});
      case CVSTag.DATE:
        return NLS.bind(CVSUIMessages.CVSFilePropertiesPage_date, new String[] {tag.getName()});
      default:
        return tag.getName();
    }
  }
  /**
   * 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; //
    }
  }