Exemple #1
0
 protected void watchChildren(final IResource resource, int eventMask) {
   IResourceChangeListener listener =
       new IResourceChangeListener() {
         public void resourceChanged(IResourceChangeEvent event) {
           try {
             event
                 .getDelta()
                 .accept(
                     new IResourceDeltaVisitor() {
                       public boolean visit(IResourceDelta delta) throws CoreException {
                         if (delta.getAffectedChildren().length == 0
                             && delta
                                 .getResource()
                                 .getParent()
                                 .getFullPath()
                                 .equals(resource.getFullPath())) changed();
                         return true;
                       }
                     });
           } catch (CoreException e) {
             throw new RuntimeException(e);
           }
         }
       };
   resourceListeners.add(listener);
   resource.getWorkspace().addResourceChangeListener(listener, eventMask);
 }
 /**
  * Constructs a line breakpoint on the given resource at the given line number.
  *
  * @param resource file on which to set the breakpoint
  * @param lineNumber 1-based line number of the breakpoint
  * @throws CoreException if unable to create the breakpoint
  */
 public PHPConditionalBreakpoint(
     final IResource resource, final int lineNumber, final Map attributes) throws CoreException {
   IWorkspaceRunnable runnable =
       new IWorkspaceRunnable() {
         public void run(IProgressMonitor monitor) throws CoreException {
           IMarker marker =
               resource.createMarker(
                   "com.aptana.php.debug.epl.PHPConditionalBreakpointMarker"); //$NON-NLS-1$
           attributes.put(IBreakpoint.ENABLED, Boolean.TRUE);
           attributes.put(IBreakpoint.ID, getModelIdentifier());
           attributes.put(
               IMarker.MESSAGE,
               MessageFormat.format(
                   PHPDebugCoreMessages.LineBreakPointMessage_1,
                   new String[] {resource.getName(), Integer.toString(lineNumber)}));
           attributes.put(IPHPDebugConstants.ConditionEnabled, Boolean.FALSE);
           attributes.put(IPHPDebugConstants.Condition, "");
           attributes.put(IBreakpoint.PERSISTED, Boolean.FALSE);
           attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
           marker.setAttributes(attributes);
           setMarker(marker);
           setEnabled(true);
           register(true);
           setPersisted(true);
         }
       };
   resource.getWorkspace().run(runnable, null, IWorkspace.AVOID_UPDATE, null);
 }
 protected ISchedulingRule getSchedulingRule() {
   IResource resource = getSourceModule().getResource();
   IWorkspace workspace = resource.getWorkspace();
   if (resource.exists()) {
     return workspace.getRuleFactory().modifyRule(resource);
   } else {
     return workspace.getRuleFactory().createRule(resource);
   }
 }
 protected ISchedulingRule getSchedulingRule() {
   IResource resource = getElementToProcess().getResource();
   if (resource == null) return null;
   IWorkspace workspace = resource.getWorkspace();
   if (resource.exists()) {
     return workspace.getRuleFactory().modifyRule(resource);
   } else {
     return workspace.getRuleFactory().createRule(resource);
   }
 }
Exemple #5
0
  @Override
  public void dispose() {
    IResource resource = ResourceUtil.getResource(getEditorInput());

    super.dispose();

    if (resource != null) {
      resource.getWorkspace().removeResourceChangeListener(this);
    }

    buildFileImg.dispose();
  }
Exemple #6
0
  @Override
  public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    sourcePage.init(site, input);

    setPartNameForInput(input);

    IResource resource = ResourceUtil.getResource(input);
    if (resource != null) {
      resource.getWorkspace().addResourceChangeListener(this);
    }

    final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
    IDocument document = docProvider.getDocument(input);
    try {
      model.loadFrom(new IDocumentWrapper(document));
      model.setProjectFile(Project.BNDFILE.equals(input.getName()));

      if (resource != null) {
        model.setBndResource(resource.getLocation().toFile());
      }
      // model.addPropertyChangeListener(modelListener);
    } catch (IOException e) {
      throw new PartInitException("Error reading editor input.", e);
    }

    // Ensure the field values are updated if the file content is replaced
    docProvider.addElementStateListener(
        new IElementStateListener() {
          public void elementMoved(Object originalElement, Object movedElement) {}

          public void elementDirtyStateChanged(Object element, boolean isDirty) {}

          public void elementDeleted(Object element) {}

          public void elementContentReplaced(Object element) {
            try {
              model.loadFrom(new IDocumentWrapper(docProvider.getDocument(element)));
            } catch (IOException e) {
              logger.logError("Error loading model from document.", e);
            }
          }

          public void elementContentAboutToBeReplaced(Object element) {}
        });
  }
 /**
  * Finds a resource corresponding to a path that is relative to the SCM repository root.
  * Heuristically drops path prefixes (like "trunk", ...) until a resource can be found. If none
  * can be found, null is returned.
  */
 public IResource determineResource() {
   String partOfPath = this.getPath();
   if (partOfPath.startsWith("/")) {
     partOfPath = partOfPath.substring(1);
   }
   while (true) {
     final IResource resource = PositionTransformer.toResource(partOfPath);
     if (!(resource instanceof IWorkspaceRoot)) {
       // perhaps too much was dropped and a different file then the intended returned
       //  therefore double check by using the inverse lookup
       final String shortName =
           PositionTransformer.toPosition(resource.getFullPath(), 1, resource.getWorkspace())
               .getShortFileName();
       if (partOfPath.contains(shortName)) {
         return resource;
       }
     }
     final int slashIndex = partOfPath.indexOf('/');
     if (slashIndex < 0) {
       return null;
     }
     partOfPath = partOfPath.substring(slashIndex + 1);
   }
 }
  @Override
  public boolean visit(final IResource resource) {
    if (resource == null || !resource.isAccessible()) {
      return false;
    }

    final URI resourceLocation = resource.getLocationURI();
    resourcename = resource.getName();
    if (resourcename == null || resourcename.startsWith(DOT)) {
      return false;
    }

    try {
      URI resolved = resource.getWorkspace().getPathVariableManager().resolveURI(resourceLocation);
      IFileStore store = EFS.getStore(resolved);
      IFileInfo fileInfo = store.fetchInfo();
      if (!fileInfo.exists()) {
        ErrorReporter.logError(
            "The resource `" + resource.getFullPath() + "' points to a non-existing location.");
        return false;
      }
    } catch (CoreException e) {
      ErrorReporter.logExceptionStackTrace(e);
      return false;
    }

    switch (resource.getType()) {
      case IResource.FILE:
        if (!ResourceExclusionHelper.isDirectlyExcluded((IFile) resource)
            && !helper.isExcludedByRegexp(resourcename)) {
          boolean inExcluded = false;
          IPath resourceFullPath = resource.getFullPath();
          for (int i = 0; i < excludedFolders.size(); i++) {
            IPath excludedFolder = excludedFolders.get(i);
            if (excludedFolder.isPrefixOf(resourceFullPath)) {
              inExcluded = true;
              break;
            }
          }

          IFile file = (IFile) resource;
          if (inExcluded) {
            excludedFiles.put(resource.getName(), file);
            return false;
          }

          boolean inCentralStorage = false;
          for (int i = 0; i < centralStorages.size(); i++) {
            URI centralFolder = centralStorages.get(i);
            if (centralFolder.getHost() == resourceLocation.getHost()
                && resourceLocation.getPath().startsWith(centralFolder.getPath())) {
              inCentralStorage = true;
              break;
            }
          }
          file = (IFile) resource;
          if (inCentralStorage) {
            if (file.getLocation() == null) {
              centralStorageFiles.put(file.getName(), file);
            } else {
              centralStorageFiles.put(file.getLocation().toOSString(), file);
            }
          } else {
            files.put(resourcename, file);
          }
        }
        return false;
      case IResource.FOLDER:
        for (IContainer workingDirectory : workingDirectories) {
          if (workingDirectory.equals(resource)) {
            return false;
          }
        }

        try {
          if (ResourceExclusionHelper.isDirectlyExcluded((IFolder) resource)
              || helper.isExcludedByRegexp(resourcename)) {
            excludedFolders.add(resource.getFullPath());
          }

          if (TRUE.equals(
              resource.getPersistentProperty(
                  new QualifiedName(
                      FolderBuildPropertyData.QUALIFIER,
                      FolderBuildPropertyData.CENTRAL_STORAGE_PROPERTY)))) {
            centralStorages.add(resourceLocation);
          }
        } catch (CoreException e) {
          return false;
        }
        break;
      default:
    }
    return true;
  }
 @Override
 protected ISchedulingRule getSchedulingRule() {
   IResource resource = getCompilationUnit().getResource();
   IWorkspace workspace = resource.getWorkspace();
   return workspace.getRuleFactory().modifyRule(resource);
 }