Search in sources :

Example 1 with IResourceDeltaVisitor

use of org.eclipse.core.resources.IResourceDeltaVisitor 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 2 with IResourceDeltaVisitor

use of org.eclipse.core.resources.IResourceDeltaVisitor 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 3 with IResourceDeltaVisitor

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

the class DeltaWrapper method hasProjectChanged.

/*
     * Any change other then src, test, test_bin, or generated is fair game.
     */
boolean hasProjectChanged() throws Exception {
    if (delta == null) {
        log.basic("Full build because delta is null");
        return true;
    }
    final AtomicBoolean result = new AtomicBoolean(false);
    delta.accept(new IResourceDeltaVisitor() {

        @Override
        public boolean visit(IResourceDelta visitDelta) throws CoreException {
            if ((delta.getKind() & (IResourceDelta.ADDED | IResourceDelta.CHANGED | IResourceDelta.REMOVED)) == 0)
                return false;
            IResource resource = visitDelta.getResource();
            if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT)
                return true;
            String path = resource.getProjectRelativePath().toString();
            if (resource.getType() == IResource.FOLDER) {
                if (//
                check(path, model.getProperty(Constants.DEFAULT_PROP_SRC_DIR)) || //
                check(path, model.getProperty(Constants.DEFAULT_PROP_TESTSRC_DIR)) || //
                check(path, model.getProperty(Constants.DEFAULT_PROP_TESTBIN_DIR)) || check(path, model.getProperty(Constants.DEFAULT_PROP_TARGET_DIR))) {
                    return false;
                }
            }
            if (IResourceDelta.MARKERS == delta.getFlags())
                return false;
            if (check(path, Project.BNDFILE))
                return false;
            log.basic("%s changed", resource);
            result.set(true);
            return false;
        }
    });
    return result.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 4 with IResourceDeltaVisitor

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

the class DeltaWrapper method toFiles.

private List<String> toFiles(final boolean dirsAlso) throws CoreException {
    if (delta == null)
        return null;
    final List<String> files = new ArrayList<String>();
    delta.accept(new IResourceDeltaVisitor() {

        @Override
        public boolean visit(IResourceDelta d) throws CoreException {
            IResource r = d.getResource();
            if (r != null) {
                if (r.getType() == IResource.PROJECT) {
                    return true;
                }
                if (r.getType() == IResource.FILE) {
                    files.add(d.getProjectRelativePath().toString());
                    return false;
                }
                if (r.getType() == IResource.FOLDER) {
                    if (dirsAlso)
                        files.add(d.getProjectRelativePath().toString());
                    return true;
                }
            }
            return false;
        }
    });
    return files;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 5 with IResourceDeltaVisitor

use of org.eclipse.core.resources.IResourceDeltaVisitor in project che by eclipse.

the class ResourceChangeChecker method getChangedFiles.

/* package */
IFile[] getChangedFiles() throws CoreException {
    IResourceDelta root = fDeltaFactory.getDelta();
    final List result = new ArrayList();
    root.accept(new IResourceDeltaVisitor() {

        public boolean visit(IResourceDelta delta) throws CoreException {
            final IResource resource = delta.getResource();
            if (resource.getType() == IResource.FILE) {
                final int kind = delta.getKind();
                if (isSet(kind, IResourceDelta.CHANGED)) {
                    result.add(resource);
                } else if (isSet(kind, IResourceDelta.ADDED) && isSet(delta.getFlags(), IResourceDelta.CONTENT | IResourceDelta.MOVED_FROM)) {
                    final IFile movedFrom = resource.getWorkspace().getRoot().getFile(delta.getMovedFromPath());
                    result.add(movedFrom);
                }
            }
            return true;
        }
    });
    return (IFile[]) result.toArray(new IFile[result.size()]);
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Aggregations

IResourceDelta (org.eclipse.core.resources.IResourceDelta)8 IResourceDeltaVisitor (org.eclipse.core.resources.IResourceDeltaVisitor)8 CoreException (org.eclipse.core.runtime.CoreException)8 IResource (org.eclipse.core.resources.IResource)6 ArrayList (java.util.ArrayList)3 IProject (org.eclipse.core.resources.IProject)3 HashSet (java.util.HashSet)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IFile (org.eclipse.core.resources.IFile)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 IContainer (org.eclipse.core.resources.IContainer)1 IFolder (org.eclipse.core.resources.IFolder)1 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1