Esempio n. 1
0
 private void registerInWorkspaceIfNeeded() {
   IPath jarPath = fJarPackage.getAbsolutePharLocation();
   IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
   for (int i = 0; i < projects.length; i++) {
     IProject project = projects[i];
     // The Jar is always put into the local file system. So it can only be
     // part of a project if the project is local as well. So using getLocation
     // is currently save here.
     IPath projectLocation = project.getLocation();
     if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
       try {
         jarPath = jarPath.removeFirstSegments(projectLocation.segmentCount());
         jarPath = jarPath.removeLastSegments(1);
         IResource containingFolder = project.findMember(jarPath);
         if (containingFolder != null && containingFolder.isAccessible())
           containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
       } catch (CoreException ex) {
         // don't refresh the folder but log the problem
         PHPUiPlugin.log(ex);
       }
     }
   }
 }
Esempio n. 2
0
  /**
   * Checks whether the given move included is vaild
   *
   * @param destination
   * @return a staus indicating whether the included is valid or not
   */
  public RefactoringStatus verifyDestination(IResource destination) {
    RefactoringStatus status = new RefactoringStatus();

    Assert.isNotNull(destination);
    if (!destination.exists() || destination.isPhantom())
      return RefactoringStatus.createFatalErrorStatus(
          PhpRefactoringCoreMessages.getString("MoveDelegate.2")); // $NON-NLS-1$
    if (!destination.isAccessible())
      return RefactoringStatus.createFatalErrorStatus(
          PhpRefactoringCoreMessages.getString("MoveDelegate.3")); // $NON-NLS-1$
    Assert.isTrue(destination.getType() != IResource.ROOT);

    IResource[] sourceResources = fProcessor.getSourceSelection();
    for (IResource element : sourceResources) {
      if (destination.equals(element.getParent()))
        return RefactoringStatus.createFatalErrorStatus(
            PhpRefactoringCoreMessages.getString("MoveDelegate.4")); // $NON-NLS-1$
      if (destination.equals(element)) {
        return RefactoringStatus.createFatalErrorStatus(
            PhpRefactoringCoreMessages.getString("MoveDelegate.5")); // $NON-NLS-1$
      }
    }
    return status;
  }
  /**
   * 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;
  }