Beispiel #1
0
  public void startup() {
    loadState();
    loadCommentHistory();
    loadCommentTemplates();
    CVSProviderPlugin.getPlugin()
        .addRepositoryListener(
            new ICVSListener() {
              public void repositoryAdded(ICVSRepositoryLocation root) {
                rootAdded(root);
              }

              public void repositoryRemoved(ICVSRepositoryLocation root) {
                rootRemoved(root);
              }
            });

    IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore();
    store.addPropertyChangeListener(
        new IPropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ICVSUIConstants.PREF_COMMIT_COMMENTS_MAX_HISTORY)) {
              Object newValue = event.getNewValue();
              if (newValue instanceof String) {
                try {
                  setMaxComments(Integer.parseInt((String) newValue));
                } catch (NumberFormatException e) {
                  // fail silently
                }
              }
            }
          }
        });
    setMaxComments(store.getInt(ICVSUIConstants.PREF_COMMIT_COMMENTS_MAX_HISTORY));
  }
 /*
  * Determine if the resource is a descendant of an orphaned subtree.
  * If it is, purge the CVS folders of the subtree.
  */
 private void handleOrphanedSubtree(IResource resource) {
   try {
     if (!CVSWorkspaceRoot.isSharedWithCVS(resource)) return;
     ICVSFolder folder;
     if (resource.getType() == IResource.FILE) {
       folder = CVSWorkspaceRoot.getCVSFolderFor(resource.getParent());
     } else {
       folder = CVSWorkspaceRoot.getCVSFolderFor((IContainer) resource);
     }
     handleOrphanedSubtree(folder);
   } catch (CVSException e) {
     CVSProviderPlugin.log(e);
   }
 }
  /**
   * The action is enabled for the appropriate resources. This method checks that:
   *
   * <ol>
   *   <li>there is no overlap between a selected file and folder (overlapping folders is allowed
   *       because of logical vs. physical mapping problem in views)
   *   <li>the state of the resources match the conditions provided by:
   *       <ul>
   *         <li>isEnabledForIgnoredResources()
   *         <li>isEnabledForManagedResources()
   *         <li>isEnabledForUnManagedResources() (i.e. not ignored and not managed)
   *       </ul>
   * </ol>
   *
   * @see TeamAction#isEnabled()
   */
  public boolean isEnabled() {

    // allow the super to decide enablement. if the super doesn't know it will return false.
    boolean enabled = super.isEnabled();
    if (enabled) return true;

    // invoke the inherited method so that overlaps are maintained
    IResource[] resources = getSelectedResourcesWithOverlap();

    // disable if no resources are selected
    if (resources.length == 0) return false;

    // disable properly for single resource enablement
    if (!isEnabledForMultipleResources() && resources.length != 1) return false;

    // validate enabled for each resource in the selection
    List folderPaths = new ArrayList();
    List filePaths = new ArrayList();
    for (int i = 0; i < resources.length; i++) {
      IResource resource = resources[i];

      // only enable for accessible resources
      if (resource.getType() == IResource.PROJECT) {
        if (!resource.isAccessible()) return false;
      }

      // no CVS actions are enabled if the selection contains a linked resource
      if (CVSWorkspaceRoot.isLinkedResource(resource)) return false;

      // only enable for resources in a project shared with CVS
      if (RepositoryProvider.getProvider(resource.getProject(), CVSProviderPlugin.getTypeId())
          == null) {
        return false;
      }

      // collect files and folders separately to check for overlap later
      IPath resourceFullPath = resource.getFullPath();
      if (resource.getType() == IResource.FILE) {
        filePaths.add(resourceFullPath);
      } else {
        folderPaths.add(resourceFullPath);
      }

      // ensure that resource management state matches what the action requires
      ICVSResource cvsResource = getCVSResourceFor(resource);
      try {
        if (!isEnabledForCVSResource(cvsResource)) {
          return false;
        }
      } catch (CVSException e) {
        if (!isEnabledForException(e)) return false;
      }
    }
    // Ensure that there is no overlap between files and folders
    // NOTE: folder overlap must be allowed because of logical vs. physical
    if (!folderPaths.isEmpty()) {
      for (Iterator fileIter = filePaths.iterator(); fileIter.hasNext(); ) {
        IPath resourcePath = (IPath) fileIter.next();
        for (Iterator it = folderPaths.iterator(); it.hasNext(); ) {
          IPath folderPath = (IPath) it.next();
          if (folderPath.isPrefixOf(resourcePath)) {
            return false;
          }
        }
      }
    }
    return true;
  }