Java Code Examples for org.eclipse.core.resources.IResourceDelta#ADDED

The following examples show how to use org.eclipse.core.resources.IResourceDelta#ADDED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProblemMarkerManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private boolean isErrorDelta(IResourceDelta delta)
{
	if ((delta.getFlags() & IResourceDelta.MARKERS) != 0)
	{
		IMarkerDelta[] markerDeltas = delta.getMarkerDeltas();
		for (int i = 0; i < markerDeltas.length; i++)
		{
			if (markerDeltas[i].isSubtypeOf(IMarker.PROBLEM))
			{
				int kind = markerDeltas[i].getKind();
				if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED)
				{
					return true;
				}
				int severity = markerDeltas[i].getAttribute(IMarker.SEVERITY, -1);
				int newSeverity = markerDeltas[i].getMarker().getAttribute(IMarker.SEVERITY, -1);
				if (newSeverity != severity)
				{
					return true;
				}
			}
		}
	}
	return false;
}
 
Example 2
Source File: SyncFileChangeListener.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
protected void handleSVNDir(IContainer svnDir, int kind) {
	if((kind & IResourceDelta.ALL_WITH_PHANTOMS)!=0) {
		if(kind==IResourceDelta.ADDED) {
			// should this dir be made team-private? If it contains Entries then yes!
			IFile entriesFile = svnDir.getFile(new Path(SVNConstants.SVN_ENTRIES));

			if (entriesFile.exists() &&  !svnDir.isTeamPrivateMember()) {
				try {
					svnDir.setTeamPrivateMember(true);			
					if(Policy.DEBUG_METAFILE_CHANGES) {
						System.out.println("[svn] found a new SVN meta folder, marking as team-private: " + svnDir.getFullPath()); //$NON-NLS-1$
					}
				} catch(CoreException e) {
					SVNProviderPlugin.log(SVNException.wrapException(svnDir, Policy.bind("SyncFileChangeListener.errorSettingTeamPrivateFlag"), e)); //$NON-NLS-1$
				}
			}
		}
	}
}
 
Example 3
Source File: ProjectDeltaVisitor.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
private boolean handleFolderDelta(IResourceDelta delta) {
  IResource resource = delta.getResource();
  int kind = delta.getKind();

  switch (kind) {
    case IResourceDelta.ADDED:
      generateCreated(resource);
      return true;

    case IResourceDelta.REMOVED:
      generateRemoved(resource);
      return true;

    default:
      return kind != IResourceDelta.NO_CHANGE;
  }
}
 
Example 4
Source File: ProblemMarkerManager.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isErrorDelta(IResourceDelta delta) {
    if ((delta.getFlags() & IResourceDelta.MARKERS) != 0) {
        IMarkerDelta[] markerDeltas = delta.getMarkerDeltas();
        for (int i = 0; i < markerDeltas.length; i++) {
            IMarkerDelta iMarkerDelta = markerDeltas[i];
            if (iMarkerDelta.isSubtypeOf(IMarker.PROBLEM)) {
                int kind = iMarkerDelta.getKind();
                if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED) {
                    return true;
                }
                int severity = iMarkerDelta.getAttribute(IMarker.SEVERITY, -1);
                int newSeverity = iMarkerDelta.getMarker().getAttribute(IMarker.SEVERITY, -1);
                if (newSeverity != severity) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 5
Source File: RestoreProjectListener.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta[] projectDeltas = event.getDelta().getAffectedChildren();
	for (IResourceDelta delta : projectDeltas) {
		if((delta.getResource().getType() == IResource.PROJECT) && 
			(delta.getKind() == IResourceDelta.CHANGED || delta.getKind() == IResourceDelta.ADDED) 
				&& (delta.getFlags() & IResourceDelta.OPEN) != 0){
			IProject project = delta.getResource().getProject();
			if(project.isOpen()){
				HybridProject hybridProject  = HybridProject.getHybridProject(project);
				if(hybridProject != null ) {
					RestoreProjectJob job = new RestoreProjectJob(project);
					ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(project);
					job.setRule(rule);
					job.schedule();
				}
			}
		}
	}
}
 
Example 6
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates a visitor that is used to traverse the information that is obtained from {@link #getDelta(IProject)}. It
 * accumulates its findings in the given <code>toBeBuilt</code>.
 */
protected IResourceDeltaVisitor createDeltaVisitor(ToBeBuiltComputer toBeBuiltComputer, ToBeBuilt toBeBuilt,
		final SubMonitor progress) {
	IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
		@Override
		public boolean visit(IResourceDelta delta) throws CoreException {
			if (progress.isCanceled())
				throw new OperationCanceledException();
			if (delta.getResource() instanceof IProject) {
				return true;
			}
			if (delta.getResource() instanceof IStorage) {
				if (delta.getKind() == IResourceDelta.REMOVED) {
					return toBeBuiltComputer.removeStorage(null, toBeBuilt, (IStorage) delta.getResource());
				} else if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED) {
					return toBeBuiltComputer.updateStorage(null, toBeBuilt, (IStorage) delta.getResource());
				}
			}
			return true;
		}
	};
	return visitor;
}
 
Example 7
Source File: ProblemMarkerManager.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean isErrorDelta(IResourceDelta delta) {
	if ((delta.getFlags() & IResourceDelta.MARKERS) != 0) {
		IMarkerDelta[] markerDeltas= delta.getMarkerDeltas();
		for (int i= 0; i < markerDeltas.length; i++) {
			if (markerDeltas[i].isSubtypeOf(IMarker.PROBLEM)) {
				int kind= markerDeltas[i].getKind();
				if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED)
					return true;
				int severity= markerDeltas[i].getAttribute(IMarker.SEVERITY, -1);
				int newSeverity= markerDeltas[i].getMarker().getAttribute(IMarker.SEVERITY, -1);
				if (newSeverity != severity)
					return true;
			}
		}
	}
	return false;
}
 
Example 8
Source File: ProblemMarkerManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void checkInvalidate(IResourceDelta delta, IResource resource)
{
	int kind = delta.getKind();
	if (kind == IResourceDelta.REMOVED || kind == IResourceDelta.ADDED
			|| (kind == IResourceDelta.CHANGED && isErrorDelta(delta)))
	{
		// invalidate the resource and all parents
		while (resource.getType() != IResource.ROOT && fChangedElements.add(resource))
		{
			resource = resource.getParent();
		}
	}
}
 
Example 9
Source File: ClientBundleResourceChangeListener.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isPossibleClientBundleResourceDelta(
    IResourceDelta delta) {
  IResource resource = delta.getResource();

  if (resource.isDerived()) {
    return false;
  }

  if (resource.getType() != IResource.FILE) {
    return false;
  }

  // We only care about additions/deletions. If the contents of a
  // resource file change, it doesn't affect our validation.
  if (delta.getKind() != IResourceDelta.ADDED
      && delta.getKind() != IResourceDelta.REMOVED) {
    return false;
  }

  // Ignore Java source changes, since we're only interested in resource files
  if ("java".equals(resource.getFileExtension())) {
    return false;
  }

  if (!GWTNature.isGWTProject(resource.getProject())) {
    return false;
  }

  IJavaProject javaProject = JavaCore.create(resource.getProject());
  if (!javaProject.isOnClasspath(resource)) {
    return false;
  }

  // All checks passed; it looks like a change we care about
  return true;
}
 
Example 10
Source File: TsvBuilder.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(final IResourceDelta delta) throws CoreException {
	switch (delta.getKind()) {
	case IResourceDelta.ADDED:
	case IResourceDelta.CHANGED:
		return visit(delta.getResource());
	}
	return true;
}
 
Example 11
Source File: ProjectStateChangeListener.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private boolean collectAffectedProjects(IResourceDelta delta, Set<IProject> accumulator) {
	IResource resource = delta.getResource();
	if (resource instanceof IProject && "RemoteSystemsTempFiles".equals(resource.getName())) {
		return false;
	}
	if (resource instanceof IWorkspaceRoot)
		return true;
	if (resource instanceof IProject) {
		IProject project = (IProject) resource;
		if ("RemoteSystemsTempFiles".equals(resource.getName())) {
			return false;
		}
		if ((delta.getKind() & IResourceDelta.CHANGED) != 0 && project.isOpen()) {
			if ((delta.getFlags() & IResourceDelta.OPEN) != 0) {
				accumulator.add(project);
			}
			if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
				if ((delta.findMember(new Path(".project")) != null) && XtextProjectHelper.hasNature(project)
						&& XtextProjectHelper.hasBuilder(project)) {
					accumulator.add(project);
				}
			}
		}
		return true;
	}
	if (resource instanceof IFolder) {
		if (N4JSGlobals.NODE_MODULES.equals(resource.getName())) {
			accumulator.add(resource.getProject());
		} else if ((delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED)
				&& isSourceContainerModification(resource)) {
			accumulator.add(resource.getProject());
		}
	}
	return false;
}
 
Example 12
Source File: RevertResourceManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
    * Revert previously deleted resources that are added again. When a file is
    * reverted, it's parent directories are also reverted.
    * When new files are added in folders that are scheduled for deletion, the parent
    * folder tree is reverted.
    * 
    * @param resources
    */

private ISVNLocalResource[] processResources(IResourceDelta[] resources) throws CoreException {
   	List<ISVNLocalResource> revertedResources = new ArrayList<ISVNLocalResource>();
       for (IResourceDelta resourceDelta : resources) {
       	IResource resource = resourceDelta.getResource();
           if (resource.getType() == IResource.FILE) {
               ISVNLocalFile res = SVNWorkspaceRoot.getSVNFileFor((IFile) resource);
               if (res.getFile().exists()) {
               	boolean deleted;
               	if (resourceDelta.getKind() == IResourceDelta.ADDED)
               		deleted = res.getStatusFromCache().isDeleted();
               	else {
               		deleted = SVNMoveDeleteHook.isDeleted((IFile)resource);
               		if (deleted) SVNMoveDeleteHook.removeFromDeletedFileList((IFile)resource);
               	}
                   if (deleted) {
                       revertedResources.add(res);
                   }
                   ISVNLocalFolder parentFolder = res.getParent();
                   while (parentFolder != null) {
                       if (parentFolder.getStatusFromCache().isDeleted() && !parentFolder.getResource().exists() && !revertedResources.contains(parentFolder)) {
                           revertedResources.add(parentFolder);
                       } else {
                           break;
                       }
                       if (parentFolder.getParent() == null) {
                           break;
                       }
                       parentFolder = parentFolder.getParent();
                   }                    
               }
           }
       }
       return (ISVNLocalResource[]) revertedResources.toArray(new ISVNLocalResource[revertedResources.size()]);
   }
 
Example 13
Source File: ExternalFileAnnotationModel.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates this model to the given marker deltas.
 * 
 * @param markerDeltas
 *            the array of marker deltas
 */
protected void update(IMarkerDelta[] markerDeltas)
{
	if (markerDeltas.length == 0)
	{
		return;
	}

	for (IMarkerDelta delta : markerDeltas)
	{
		switch (delta.getKind())
		{
			case IResourceDelta.ADDED:
				addMarkerAnnotation(delta.getMarker());
				break;
			case IResourceDelta.REMOVED:
				removeMarkerAnnotation(delta.getMarker());
				break;
			case IResourceDelta.CHANGED:
				modifyMarkerAnnotation(delta.getMarker());
				break;
			default:
				break;
		}
	}
	fireModelChanged();
}
 
Example 14
Source File: N4JSAllContainersState.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Indicates whether the resource change represented by the given {@code delta} does affect this container state.
 *
 * Note that this method will only be invoked until a container-state-affecting delta is found. Thus, it is not
 * suitable for listening for all resource changes that may occur in the workspace.
 */
@Override
protected boolean isAffectingContainerState(IResourceDelta delta) {
	if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED) {
		String fileExtension = delta.getFullPath().getFileExtension();
		if (null != fileExtension && fileExtensionTypeHelper.isTypable(fileExtension)) {
			return true;
		}
		if (IN4JSProject.PACKAGE_JSON.equals(delta.getFullPath().lastSegment())) {
			return true;
		}

		if (delta.getResource() instanceof IProject) {
			return true;
		}
		if (delta.getResource() instanceof IFolder && isSourceContainerModification(delta)) {
			return true;
		}
		return false;
	} else if (delta.getKind() == IResourceDelta.CHANGED && delta.getResource() instanceof IProject) {
		if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
			return true;
		}
		if ((delta.getFlags() & IResourceDelta.OPEN) != 0) {
			return true;
		}
		return false;
	}
	if (packageJSONFileHasBeenChanged(delta)) {
		return true;
	}
	return false;
}
 
Example 15
Source File: ProblemMarkerManager.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void checkInvalidate(IResourceDelta delta, IResource resource) {
    int kind = delta.getKind();
    if (kind == IResourceDelta.REMOVED || kind == IResourceDelta.ADDED
            || (kind == IResourceDelta.CHANGED && isErrorDelta(delta))) {
        // invalidate the resource and all parents
        while (resource.getType() != IResource.ROOT && fChangedElements.add(resource)) {
            resource = resource.getParent();
        }
    }
}
 
Example 16
Source File: DeltaProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void checkSourceAttachmentChange(IResourceDelta delta, IResource res) {
	IPath rootPath = (IPath)this.state.sourceAttachments.get(externalPath(res));
	if (rootPath != null) {
		RootInfo rootInfo = rootInfo(rootPath, delta.getKind());
		if (rootInfo != null) {
			IJavaProject projectOfRoot = rootInfo.project;
			IPackageFragmentRoot root = null;
			try {
				// close the root so that source attachment cache is flushed
				root = projectOfRoot.findPackageFragmentRoot(rootPath);
				if (root != null) {
					root.close();
				}
			} catch (JavaModelException e) {
				// root doesn't exist: ignore
			}
			if (root == null) return;
			switch (delta.getKind()) {
				case IResourceDelta.ADDED:
					currentDelta().sourceAttached(root);
					break;
				case IResourceDelta.CHANGED:
					currentDelta().sourceDetached(root);
					currentDelta().sourceAttached(root);
					break;
				case IResourceDelta.REMOVED:
					currentDelta().sourceDetached(root);
					break;
			}
		}
	}
}
 
Example 17
Source File: RadlValidatingVisitor.java    From RADL with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
  IResource resource = delta.getResource();
  switch (delta.getKind()) {
    case IResourceDelta.ADDED:
    case IResourceDelta.CHANGED:
      validateRadl(resource);
      break;
    default:
      // Do nothing
      break;
  }
  // Continue visiting children
  return true;
}
 
Example 18
Source File: ToStringResourceDeltaVisitor.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
  boolean result = true;
  switch (delta.getKind()) {
    case IResourceDelta.NO_CHANGE:
      sb.append("0");
      result = false;
      break;
    case IResourceDelta.CHANGED:
      sb.append("C(");
      int f = delta.getFlags();
      if (f == 0) {
        sb.append("0) ");
      } else {
        Set<Entry<Integer, String>> entrySet = map.entrySet();
        for (Entry<Integer, String> entry : entrySet) {
          if (0 != (f & entry.getKey())) sb.append(entry.getValue());
        }
        sb.append(") ");
      }

      break;
    case IResourceDelta.ADDED:
      sb.append("A ");
      break;
    case IResourceDelta.REMOVED:
      sb.append("R ");
      break;
    default:
      sb.append("? ");
  }
  IResource resource = delta.getResource();
  if (resource != null) {
    if (resource.isDerived()) sb.append("* ");

    if (resource.isPhantom()) sb.append("P ");

    if (resource.isHidden()) sb.append("H ");

    sb.append(resource.getFullPath().toPortableString());
  } else {
    sb.append("No resource");
  }
  sb.append("\n");

  return result;
}
 
Example 19
Source File: ResourceManager.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean visit(final IResourceDelta delta) {
	final IResource res = delta.getResource();
	boolean update = false;
	switch (delta.getKind()) {
		case IResourceDelta.OPEN:
			if (res.isAccessible()) {
				update = projectOpened((IProject) res);
			} else {
				update = projectClosed((IProject) res);
			}
			break;
		case IResourceDelta.ADDED:
			update = processAddition(res);
			break;
		case IResourceDelta.REMOVED:
			update = processRemoval(res);
			break;
		case IResourceDelta.CHANGED:
			final int flags = delta.getFlags();
			if ((flags & IResourceDelta.MARKERS) != 0) {
				update = processMarkersChanged(res);
			}
			if ((flags & IResourceDelta.TYPE) != 0) {
				if (DEBUG.IS_ON()) {
					DEBUG.OUT("Resource type changed: " + res);
				}
			}
			if ((flags & IResourceDelta.CONTENT) != 0) {
				if (DEBUG.IS_ON()) {
					DEBUG.OUT("Resource contents changed: " + res);
				}
			}
			if ((flags & IResourceDelta.SYNC) != 0) {
				if (DEBUG.IS_ON()) {
					DEBUG.OUT("Resource sync info changed: " + res);
				}
			}
			if ((flags & IResourceDelta.LOCAL_CHANGED) != 0) {
				if (DEBUG.IS_ON()) {
					DEBUG.OUT("Linked resource target info changed: " + res);
				}
				update = processLinkedTargerChanged(res);
			}
			break;
	}
	if (update) {
		updateResource(res);
	}
	return true; // visit the children
}
 
Example 20
Source File: JavaElementDelta.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns a string representation of this delta's
 * structure suitable for debug purposes.
 *
 * @see #toString()
 */
public String toDebugString(int depth) {
	StringBuffer buffer = new StringBuffer();
	for (int i= 0; i < depth; i++) {
		buffer.append('\t');
	}
	buffer.append(((JavaElement)getElement()).toDebugString());
	toDebugString(buffer);
	IJavaElementDelta[] children = getAffectedChildren();
	if (children != null) {
		for (int i = 0; i < children.length; ++i) {
			buffer.append("\n"); //$NON-NLS-1$
			buffer.append(((JavaElementDelta) children[i]).toDebugString(depth + 1));
		}
	}
	for (int i = 0; i < this.resourceDeltasCounter; i++) {
		buffer.append("\n");//$NON-NLS-1$
		for (int j = 0; j < depth+1; j++) {
			buffer.append('\t');
		}
		IResourceDelta resourceDelta = this.resourceDeltas[i];
		buffer.append(resourceDelta.toString());
		buffer.append("["); //$NON-NLS-1$
		switch (resourceDelta.getKind()) {
			case IResourceDelta.ADDED :
				buffer.append('+');
				break;
			case IResourceDelta.REMOVED :
				buffer.append('-');
				break;
			case IResourceDelta.CHANGED :
				buffer.append('*');
				break;
			default :
				buffer.append('?');
				break;
		}
		buffer.append("]"); //$NON-NLS-1$
	}
	IJavaElementDelta[] annotations = getAnnotationDeltas();
	if (annotations != null) {
		for (int i = 0; i < annotations.length; ++i) {
			buffer.append("\n"); //$NON-NLS-1$
			buffer.append(((JavaElementDelta) annotations[i]).toDebugString(depth + 1));
		}
	}
	return buffer.toString();
}