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

The following examples show how to use org.eclipse.core.resources.IResourceDelta#CHANGED . 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: Builder.java    From cppcheclipse with Apache License 2.0 6 votes vote down vote up
public boolean visit(IResourceDelta delta) throws CoreException {
	IResource resource = delta.getResource();
	// ignore all parent elements (projects, folders)
	if (resource instanceof IFile) {
		switch (delta.getKind()) {
		case IResourceDelta.ADDED:
			// handle added resource
			processResource(resource,
					new SubProgressMonitor(monitor, 1));
			break;
		case IResourceDelta.REMOVED:
			// resources are not available any more and therefore the
			// markers were automatically removed
			break;
		case IResourceDelta.CHANGED:
			// handle changed resource
			processResource(resource,
					new SubProgressMonitor(monitor, 1));
			break;
		}
	}
	// return true to continue visiting children.
	return true;
}
 
Example 2
Source File: DefaultResourceChangeToIssueProcessor.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void dispatchMarkerDelta(final IMarkerDelta iMarkerDelta, final String elementID) {
	switch (iMarkerDelta.getKind()) {
		case IResourceDelta.ADDED :
			addSCTIssue(iMarkerDelta, elementID);
			break;
		case IResourceDelta.REMOVED :
			removeSCTIssue(iMarkerDelta, elementID);
			break;
		case IResourceDelta.CHANGED :
			removeSCTIssue(iMarkerDelta, elementID);
			addSCTIssue(iMarkerDelta, elementID);
			break;
		default :
			break;
	}
}
 
Example 3
Source File: WorkspaceRepositoriesProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Handles the given resource delta.
 *
 * Fires workspace repository changed event if a project was opened/closed or a project was added/removed.
 */
private boolean handleResourceDelta(IResourceDelta delta) {
	IResource affectedResource = delta.getResource();

	if (affectedResource instanceof IProject) {
		// check if kind is CHANGED
		if ((delta.getKind() & IResourceDelta.CHANGED) == IResourceDelta.CHANGED) {
			// if project was opened/closed
			if ((delta.getFlags() & IResourceDelta.OPEN) == IResourceDelta.OPEN) {
				fireWorkspaceRepositoriesChanged();
				return false;
			}
		}
		// check if kind is ADDED or REMOVED
		else if ((delta.getKind() & IResourceDelta.ADDED | IResourceDelta.REMOVED) != 0) {
			fireWorkspaceRepositoriesChanged();
			return false;
		}
	}
	return true;
}
 
Example 4
Source File: ProblemManager.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
	IResource resource = delta.getResource();
	if (resource instanceof IProject && delta.getKind() == IResourceDelta.CHANGED) {
		IProject project = (IProject) resource;
		if (!project.isAccessible()) {
			return false; // skip closed projects
		}
	}
	checkInvalidate(delta, resource);
	return true;
}
 
Example 5
Source File: UIResourceChangeRegistry.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private boolean hasContentsChanged(final IResourceDelta delta) {
  int _kind = delta.getKind();
  boolean _equals = (_kind == IResourceDelta.CHANGED);
  if (_equals) {
    return ((delta.getFlags() & UIResourceChangeRegistry.HAS_CONTENTS_CHANGED_FLAGS) != 0);
  } else {
    return false;
  }
}
 
Example 6
Source File: UniformResourceMarker.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @see org.eclipse.core.resources.IMarker#setAttributes(java.lang.String[], java.lang.Object[])
 */
public void setAttributes(String[] attributeNames, Object[] values) throws CoreException
{
	MarkerInfo info = getInfo();
	checkInfo(info);
	boolean validate = getMarkerManager().isPersistent(info);
	info.setAttributes(attributeNames, values, validate);
	IMarkerSetElement[] changes = new IMarkerSetElement[] { new MarkerDelta(IResourceDelta.CHANGED, resource, info) };
	getMarkerManager().changedMarkers(resource, changes);
}
 
Example 7
Source File: RefreshJob.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean addToQueue(DeltaInfo res) {
    switch (res.changeKind) {
    case IResourceDelta.CHANGED:
        return false;
    }
    synchronized (deltaToRefresh) {
        if (!deltaToRefresh.contains(res)) {
            deltaToRefresh.add(res);
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: FileContentNotifierBridge.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
  if (event.getDelta() == null) return;

  Deque<IResourceDelta> stack = new LinkedList<IResourceDelta>();

  stack.addAll(Arrays.asList(event.getDelta().getAffectedChildren()));

  while (!stack.isEmpty()) {
    IResourceDelta delta = stack.pop();
    stack.addAll(Arrays.asList(delta.getAffectedChildren()));

    if (delta.getResource().getType() == IResource.FILE) {

      // TODO check the Eclipse API to ignore more events
      if (delta.getKind() == IResourceDelta.NO_CHANGE) continue;

      if ((delta.getKind() == IResourceDelta.CHANGED)
          && (delta.getFlags() == IResourceDelta.MARKERS)) continue;

      final IFile file = delta.getResource().getAdapter(IFile.class);

      for (IFileContentChangedListener listener : fileContentChangedListeners)
        listener.fileContentChanged(ResourceAdapterFactory.create(file));
    }
  }
}
 
Example 9
Source File: UniformResourceMarker.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @see org.eclipse.core.resources.IMarker#setAttributes(java.util.Map)
 */
@SuppressWarnings("unchecked")
public void setAttributes(Map attributes) throws CoreException
{
	MarkerInfo info = getInfo();
	checkInfo(info);
	boolean validate = getMarkerManager().isPersistent(info);
	info.setAttributes(attributes, validate);
	IMarkerSetElement[] changes = new IMarkerSetElement[] { new MarkerDelta(IResourceDelta.CHANGED, resource, info) };
	getMarkerManager().changedMarkers(resource, changes);
}
 
Example 10
Source File: ProblemMarkerManager.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
    IResource res = delta.getResource();
    if (res instanceof IProject && delta.getKind() == IResourceDelta.CHANGED) {
        IProject project = (IProject) res;
        if (!project.isAccessible()) {
            // only track open projects
            return false;
        }
    }
    checkInvalidate(delta, res);
    return true;
}
 
Example 11
Source File: ProblemMarkerManager.java    From goclipse 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 12
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 13
Source File: MultiPageCSVEditor.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Closes all project files on project close.
 *
 * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
 */
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	if (event.getType() == IResourceChangeEvent.PRE_CLOSE || event.getType() == IResourceChangeEvent.PRE_DELETE) {
		WorkbenchHelper.asyncRun(() -> {
			final IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages();
			for (final IWorkbenchPage page : pages) {
				if (((FileEditorInput) editor.getEditorInput()).getFile().getProject()
						.equals(event.getResource())) {
					final IEditorPart editorPart = page.findEditor(editor.getEditorInput());
					page.closeEditor(editorPart, true);
				}
			}
		});
	} else {

		final IResourceDelta delta = event.getDelta().findMember(getFileFor(getEditorInput()).getFullPath());
		if (delta != null) {
			// file deleted -- close the editor
			if (delta.getKind() == IResourceDelta.REMOVED) {
				final Runnable r = () -> getSite().getPage().closeEditor(MultiPageCSVEditor.this, false);
				getSite().getShell().getDisplay().asyncExec(r);
			}
			// file changed -- reload
			else if (delta.getKind() == IResourceDelta.CHANGED) {
				final int flags = delta.getFlags();
				if ((flags & IResourceDelta.CONTENT) != 0 || (flags & IResourceDelta.LOCAL_CHANGED) != 0) {
					WorkbenchHelper.asyncRun(() -> MultiPageCSVEditor.this.updateTableFromTextEditor());
				}
			}
		}

	}
}
 
Example 14
Source File: ExtLibDesignElementLookup.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {
            // @TODO: need to filter resource events!
            try {
                IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
                    
                    boolean keepVisiting = true;
                    
                    public boolean visit(IResourceDelta delta) {
                        
                        if (!keepVisiting || null == designerProject)
                            return false;
                        
                        int k = delta.getKind();
                        if ( ! (IResourceDelta.ADDED == k || 
                                IResourceDelta.REMOVED == k || 
                                IResourceDelta.CHANGED == k) )  // an update could be a name change
                           return true;

//                       if ((delta.getFlags() ...?
                       IResource resource = delta.getResource();
                       if (resource.getType() == IResource.FILE && resource.getProject().equals(designerProject.getProject())) {
                           String resExt = resource.getFileExtension();
                           String typeExt = extForType(); 
                           if (typeExt.length() > 0 && resExt.length() > 0 &&
                               typeExt.equalsIgnoreCase(resExt)) {
                               keepVisiting = false;
                               updateDesignElements();
                           }
                       }
                       return keepVisiting;
                    }
                 };
                 
                 event.getDelta().accept(visitor);
            }
            catch(Exception e) {
                ExtLibToolingLogger.EXT_LIB_TOOLING_LOGGER.error(e, e.toString());            }
        }
 
Example 15
Source File: N4JSAllContainersState.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handles the given {@link IResourceDelta} and updates the project state (cache of available projects and project
 * descriptions) accordingly.
 *
 * If so, invalidates the {@link EclipseBasedN4JSWorkspace} cache of project descriptions for the updated projects.
 */
private boolean updateProjectState(IResourceDelta delta) {
	if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED) {
		if (IN4JSProject.PACKAGE_JSON.equals(delta.getFullPath().lastSegment())) {
			return true;
		}
		if (delta.getResource() instanceof IProject) {
			return true;
		}
		if (delta.getResource() instanceof IFolder) {
			if (isSourceContainerModification(delta)) {
				return true;
			}
		}
		return false;
	} else if (delta.getKind() == IResourceDelta.CHANGED) {
		if (delta.getResource() instanceof IProject) {
			if ((delta.getFlags() & IResourceDelta.OPEN) != 0) {
				return true;
			}
			return false;
		}
		if (delta.getResource() instanceof IFolder) {
			if (N4JSGlobals.NODE_MODULES.equals(delta.getFullPath().lastSegment())) {
				return true;
			}
			return false;
		}
	}
	if (packageJSONFileHasBeenChanged(delta)) {
		return true;
	}
	return false;
}
 
Example 16
Source File: JavaWorkingSetUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void processResourceDelta(WorkingSetDelta result, IResourceDelta delta) {
	IResource resource= delta.getResource();
	int type= resource.getType();
	int index= result.indexOf(resource);
	int kind= delta.getKind();
	int flags= delta.getFlags();
	if (kind == IResourceDelta.CHANGED && type == IResource.PROJECT && index != -1) {
		if ((flags & IResourceDelta.OPEN) != 0) {
			result.set(index, resource);
		}
	}
	if (index != -1 && kind == IResourceDelta.REMOVED) {
		if ((flags & IResourceDelta.MOVED_TO) != 0) {
			result.set(index,
				ResourcesPlugin.getWorkspace().getRoot().findMember(delta.getMovedToPath()));
		} else {
			result.remove(index);
		}
	}

	// Don't dive into closed or opened projects
	if (projectGotClosedOrOpened(resource, kind, flags))
		return;

	IResourceDelta[] children= delta.getAffectedChildren();
	for (int i= 0; i < children.length; i++) {
		processResourceDelta(result, children[i]);
	}
}
 
Example 17
Source File: BundleMonitor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public boolean visit(IResourceDelta delta) throws CoreException
{
	// process project bundle files, but ignore user bundles since file watcher will take care of those
	if (isProjectBundleFile(delta))
	{
		this.processFile(delta);
	}
	else
	{
		if (delta.getKind() == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.CONTENT) != 0)
		{
			IResource resource = delta.getResource();

			if (resource != null)
			{
				IPath location = resource.getLocation();

				if (location != null)
				{
					File file = location.toFile();

					if (file != null)
					{
						this.reloadDependentScripts(file);
					}
				}
			}
		}
	}

	return true;
}
 
Example 18
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 19
Source File: DeleteResourceShortcutListener.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
 */
public void resourceChanged(IResourceChangeEvent event) {
    IResourceDelta delta = event.getDelta();

    switch (delta.getKind()) {
    case IResourceDelta.REMOVED:
        break;
    case IResourceDelta.CHANGED:
        List<IConnectionPoint> deleted = new ArrayList<IConnectionPoint>();
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

        IConnectionPointManager manager = CoreIOPlugin.getConnectionPointManager();
        IConnectionPoint[] projectShortcuts = manager.getConnectionPointCategory(CATEGORY_ID)
                .getConnectionPoints();
        WorkspaceConnectionPoint connectionPoint;
        for (IConnectionPoint shortcut : projectShortcuts) {
            connectionPoint = (WorkspaceConnectionPoint) shortcut;

            // see if the relative path matches the changed item
            IResourceDelta d = delta.findMember(connectionPoint.getPath());
            if (d != null && d.getKind() == IResourceDelta.REMOVED) {
                if (d.getMovedToPath() == null) {
                	IResource resource = d.getResource();
                	if (!(resource instanceof IProject) && resource.getProject().exists() && !resource.getProject().isOpen())
                	{
                		continue;
                	}
                	// the original container was deleted
                	deleted.add(shortcut);
                } else {
                    // the original container was moved
                    IPath newPath = d.getMovedToPath();
                    IContainer newContainer;
                    if (d.getResource() instanceof IProject) {
                        newContainer = root.getProject(newPath.toString());
                    } else {
                        newContainer = root.getFolder(newPath);
                    }
                    connectionPoint.setResource(newContainer);
                    connectionPoint.setName(newContainer.getName());
                }
            }
        }

        // if the item was deleted, remove it
        for (IConnectionPoint projectShortcut : deleted) {
            manager.removeConnectionPoint(projectShortcut);
        }
        break;
    }
}
 
Example 20
Source File: ProjectDeltaVisitor.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
private void handleFileDelta(IResourceDelta delta) {
  IResource resource = delta.getResource();
  int kind = delta.getKind();

  IProject project = resource.getProject();
  boolean contentChange = isContentChange(delta);

  /*
   * TODO Generate better move deltas, e.g we share multiple projects and
   * a file is moved between those projects. Currently we generate a
   * delete and create activity.
   */

  switch (kind) {
    case IResourceDelta.CHANGED:
      if (contentChange) generateContentChanged(resource);

      return;

    case IResourceDelta.ADDED:

      // Was this file moved or renamed?
      if (isMovedFrom(delta)) {

        // Adds have getMovedFrom set:
        IPath oldFullPath = delta.getMovedFromPath();
        IProject oldProject = getProject(oldFullPath);

        if (project.equals(oldProject)) {
          // Moving inside this project
          generateMoved(resource, oldFullPath, oldProject, contentChange);
          return;
        }

        /*
         * else moving a file into the shared project , treat like an
         * add! Fall-through ...
         */
      }

      generateCreated(resource);

      return;

    case IResourceDelta.REMOVED:
      if (isMoved(delta)) {

        // REMOVED deltas have MovedTo set
        IPath newPath = delta.getMovedToPath();
        IProject newProject = ProjectDeltaVisitor.getProject(newPath);

        // Ignore "REMOVED" while moving into shared project
        if (project.equals(newProject)) return;

        /*
         * else moving file away from shared project, need to tell
         * others to delete! Fall-through...
         */
      }

      generateRemoved(resource);
      return;

    default:
      return;
  }
}