/**
  * Ensure that the sync info for all the provided resources has been loaded. If an out-of-sync
  * resource is found, prompt to refresh all the projects involved.
  */
 protected boolean ensureSyncInfoLoaded(IResource[] resources) throws CVSException {
   boolean keepTrying = true;
   while (keepTrying) {
     try {
       EclipseSynchronizer.getInstance().ensureSyncInfoLoaded(resources, getActionDepth());
       keepTrying = false;
     } catch (CVSException e) {
       if (e.getStatus().getCode() == IResourceStatus.OUT_OF_SYNC_LOCAL) {
         // determine the projects of the resources involved
         Set projects = new HashSet();
         for (int i = 0; i < resources.length; i++) {
           IResource resource = resources[i];
           projects.add(resource.getProject());
         }
         // prompt to refresh
         if (promptToRefresh(
             getShell(),
             (IResource[]) projects.toArray(new IResource[projects.size()]),
             e.getStatus())) {
           for (Iterator iter = projects.iterator(); iter.hasNext(); ) {
             IProject project = (IProject) iter.next();
             try {
               project.refreshLocal(IResource.DEPTH_INFINITE, null);
             } catch (CoreException coreException) {
               throw CVSException.wrapException(coreException);
             }
           }
         } else {
           return false;
         }
       } else {
         throw e;
       }
     }
   }
   return true;
 }
  /**
   * 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;
  }