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();
}
}
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);
}
}
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();
}
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;
}
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()]);
}
Aggregations