Search in sources :

Example 6 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta in project sling by apache.

the class JcrContentContentProvider method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    if (viewer.getTree().isDisposed()) {
        return;
    }
    try {
        final Set<IProject> toBeRefreshed = new HashSet<>();
        event.getDelta().accept(new IResourceDeltaVisitor() {

            @Override
            public boolean visit(IResourceDelta delta) throws CoreException {
                if (delta.getResource() instanceof IContainer) {
                    return true;
                }
                IProject p = delta.getResource().getProject();
                IFolder syncDir = getSyncDir(p);
                if (syncDir == null) {
                    return false;
                }
                toBeRefreshed.add(syncDir.getProject());
                return true;
            }
        });
        for (final IProject project : toBeRefreshed) {
            viewer.getTree().getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (viewer.getTree().isDisposed()) {
                        return;
                    }
                    long start = System.currentTimeMillis();
                    viewer.refresh(project, true);
                    long end = System.currentTimeMillis();
                    Activator.getDefault().getPluginLogger().tracePerformance("viewer.refresh({0},true)", (end - start), project);
                }
            });
        }
    } catch (CoreException e) {
        //TODO proper logging
        e.printStackTrace();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet) IResourceDelta(org.eclipse.core.resources.IResourceDelta) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta in project bndtools by bndtools.

the class NewProjectResourceListener method resourceChanged.

public void resourceChanged(IResourceChangeEvent event) {
    IResourceDelta delta = event.getDelta();
    if (delta == null)
        return;
    final List<IProject> newProjects = new LinkedList<IProject>();
    try {
        delta.accept(new IResourceDeltaVisitor() {

            public boolean visit(IResourceDelta delta) throws CoreException {
                if (delta.getFlags() == IResourceDelta.MARKERS)
                    // ignore marker-only deltas.
                    return false;
                IResource resource = delta.getResource();
                if (resource.getType() == IResource.ROOT)
                    return true;
                if (resource.getType() == IResource.PROJECT) {
                    IProject project = (IProject) resource;
                    if (project.isOpen() && project.hasNature(BndtoolsConstants.NATURE_ID) && ((delta.getKind() & IResourceDelta.ADDED) != 0)) {
                        newProjects.add(project);
                    }
                }
                return false;
            }
        });
        for (IProject project : newProjects) {
            AdjustClasspathsForNewProjectJob adjustClasspathsJob = new AdjustClasspathsForNewProjectJob(project);
            adjustClasspathsJob.setSystem(true);
            adjustClasspathsJob.schedule();
        }
    } catch (CoreException e) {
        logger.logError("An error occurred while analysing the resource change", e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) LinkedList(java.util.LinkedList) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 8 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta in project bndtools by bndtools.

the class ProjectBuildPage method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    IResource myResource = ResourceUtil.getResource(getEditorInput());
    IResourceDelta delta = event.getDelta();
    if (delta == null)
        return;
    IPath fullPath = myResource.getFullPath();
    delta = delta.findMember(fullPath);
    if (delta == null)
        return;
    if ((delta.getKind() & IResourceDelta.CHANGED) != 0 && (delta.getFlags() & IResourceDelta.MARKERS) != 0) {
        getEditorSite().getShell().getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                loadProblems();
                reportProblemsInHeader();
            }
        });
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 9 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta in project bndtools by bndtools.

the class FileUtils method dumpResourceDelta.

private static void dumpResourceDelta(IResourceDelta delta, PrintStream out, String indent) {
    out.println(String.format("%s%s: kind=%h, flags=%h", indent, delta.getFullPath(), delta.getKind(), delta.getFlags()));
    IResourceDelta[] children = delta.getAffectedChildren();
    for (IResourceDelta child : children) {
        dumpResourceDelta(child, out, indent + "   ");
    }
}
Also used : IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 10 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta in project bndtools by bndtools.

the class BndtoolsBuilder method hasUpstreamChanges.

/*
     * Check if any of the projects of which we depend has changes.
     * We use the generated/buildfiles as the marker.
     */
private boolean hasUpstreamChanges() throws Exception {
    for (IProject upstream : dependsOn) {
        if (!upstream.exists())
            continue;
        Project up = Central.getProject(upstream);
        if (up == null)
            continue;
        IResourceDelta delta = getDelta(upstream);
        DeltaWrapper dw = new DeltaWrapper(up, delta, buildLog);
        if (dw.hasBuildfile()) {
            buildLog.full("Upstream project %s changed", up);
            return true;
        }
    }
    return false;
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) IJavaProject(org.eclipse.jdt.core.IJavaProject) IProject(org.eclipse.core.resources.IProject) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Aggregations

IResourceDelta (org.eclipse.core.resources.IResourceDelta)33 IResource (org.eclipse.core.resources.IResource)21 IPath (org.eclipse.core.runtime.IPath)12 IProject (org.eclipse.core.resources.IProject)10 CoreException (org.eclipse.core.runtime.CoreException)9 IResourceDeltaVisitor (org.eclipse.core.resources.IResourceDeltaVisitor)8 ArrayList (java.util.ArrayList)7 IFile (org.eclipse.core.resources.IFile)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Iterator (java.util.Iterator)3 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)3 Project (aQute.bnd.build.Project)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IFolder (org.eclipse.core.resources.IFolder)2 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2