use of org.eclipse.core.resources.IResourceChangeListener in project liferay-ide by liferay.
the class PluginPackageEditor method createFileChangeListener.
protected void createFileChangeListener() {
_fileChangeListener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
handleFileChangedEvent(event);
}
};
ResourcesPlugin.getWorkspace().addResourceChangeListener(_fileChangeListener, IResourceChangeEvent.POST_CHANGE);
}
use of org.eclipse.core.resources.IResourceChangeListener in project egit by eclipse.
the class GitResourceDeltaTestHelper method setUp.
public void setUp() {
resourceChangeListener = new IResourceChangeListener() {
@Override
public void resourceChanged(final IResourceChangeEvent event) {
try {
event.getDelta().accept(new IResourceDeltaVisitor() {
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
final IResource resource = delta.getResource();
IProject project = resource.getProject();
if (project == null)
return true;
RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
if (mapping == null)
return true;
if (mapping.getRepository() != repository)
return false;
GitResourceDeltaVisitor visitor = new GitResourceDeltaVisitor(repository);
try {
event.getDelta().accept(visitor);
} catch (CoreException e) {
String msg = "Exception during accept of GitResourceDeltaVisitor for resource delta";
throw new RuntimeException(msg, e);
}
IPath gitDirAbsolutePath = mapping.getGitDirAbsolutePath();
for (IResource res : visitor.getResourcesToUpdate()) {
if (ignoreTeamPrivateMember && (res.isTeamPrivateMember() || gitDirAbsolutePath.isPrefixOf(res.getRawLocation().makeAbsolute())))
continue;
changedResources.add(res);
}
return false;
}
});
} catch (CoreException e) {
throw new RuntimeException("Exception during accept of test visitor for resource delta", e);
}
}
};
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
}
use of org.eclipse.core.resources.IResourceChangeListener in project egit by eclipse.
the class Activator method registerPreDeleteResourceChangeListener.
private void registerPreDeleteResourceChangeListener() {
if (preDeleteProjectListener == null) {
preDeleteProjectListener = new IResourceChangeListener() {
@Override
public void resourceChanged(IResourceChangeEvent event) {
IResource resource = event.getResource();
if (resource instanceof IProject) {
IProject project = (IProject) resource;
if (project.isAccessible()) {
if (ResourceUtil.isSharedWithGit(project)) {
IResource dotGit = project.findMember(Constants.DOT_GIT);
if (dotGit != null && dotGit.getType() == IResource.FOLDER) {
GitProjectData.reconfigureWindowCache();
}
}
} else {
// bug 419706: project is closed - use java.io API
IPath locationPath = project.getLocation();
if (locationPath != null) {
File locationDir = locationPath.toFile();
File dotGit = new File(locationDir, Constants.DOT_GIT);
if (dotGit.exists() && dotGit.isDirectory()) {
GitProjectData.reconfigureWindowCache();
}
}
}
}
}
};
ResourcesPlugin.getWorkspace().addResourceChangeListener(preDeleteProjectListener, IResourceChangeEvent.PRE_DELETE);
}
}
use of org.eclipse.core.resources.IResourceChangeListener in project egit by eclipse.
the class IndexDiffCacheEntry method createResourceChangeListener.
private void createResourceChangeListener() {
resourceChangeListener = new IResourceChangeListener() {
private final Map<IProject, IPath> deletedProjects = new HashMap<>();
@Override
public void resourceChanged(IResourceChangeEvent event) {
if (event.getDelta() != null) {
SkipNotInterestingDeltaVisitor skipNotInterestingVisitor = new SkipNotInterestingDeltaVisitor();
try {
event.getDelta().accept(skipNotInterestingVisitor);
if (!skipNotInterestingVisitor.hasAtLeastOneInterestingDelta()) {
return;
}
} catch (CoreException e) {
Activator.logError(e.getMessage(), e);
}
}
Repository repository = getRepository();
if (repository == null) {
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
resourceChangeListener = null;
return;
}
if (event.getType() == IResourceChangeEvent.PRE_DELETE) {
// Deletion of a project.
IResource resource = event.getResource();
if (resource.getType() == IResource.PROJECT) {
IPath projectPath = resource.getLocation();
if (projectPath != null) {
IPath repoPath = ResourceUtil.getRepositoryRelativePath(projectPath, repository);
if (repoPath != null) {
deletedProjects.put((IProject) resource, projectPath);
}
}
}
// event for the deletion.
return;
}
GitResourceDeltaVisitor visitor = new GitResourceDeltaVisitor(repository, deletedProjects);
try {
event.getDelta().accept(visitor);
} catch (CoreException e) {
Activator.logError(e.getMessage(), e);
return;
}
if (visitor.getGitIgnoreChanged()) {
// $NON-NLS-1$
scheduleReloadJob("A .gitignore changed");
} else if (visitor.isProjectDeleted()) {
// $NON-NLS-1$
scheduleReloadJob("A project was deleted");
} else if (indexDiffData == null) {
// $NON-NLS-1$
scheduleReloadJob("Resource changed, no diff available");
} else {
Collection<String> filesToUpdate = visitor.getFilesToUpdate();
Collection<IResource> resourcesToUpdate = visitor.getResourcesToUpdate();
if (!filesToUpdate.isEmpty()) {
scheduleUpdateJob(filesToUpdate, resourcesToUpdate);
}
}
}
};
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE);
}
use of org.eclipse.core.resources.IResourceChangeListener in project bndtools by bndtools.
the class BndEditor 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;
// Delegate to any interested pages
for (Object page : pages) {
if (page instanceof IResourceChangeListener) {
((IResourceChangeListener) page).resourceChanged(event);
}
}
// Close editor if file removed or switch to new location if file moved
if (delta.getKind() == IResourceDelta.REMOVED) {
if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(delta.getMovedToPath());
final FileEditorInput newInput = new FileEditorInput(file);
setInput(newInput);
Display display = getEditorSite().getShell().getDisplay();
if (display != null) {
SWTConcurrencyUtil.execForDisplay(display, true, new Runnable() {
@Override
public void run() {
setPartNameForInput(newInput);
sourcePage.setInput(newInput);
}
});
}
} else {
close(false);
}
} else // File content updated externally => reload all pages
if ((delta.getKind() & IResourceDelta.CHANGED) > 0 && (delta.getFlags() & IResourceDelta.CONTENT) > 0) {
if (!saving.get()) {
final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
// #1625: Ensure the IDocumentProvider is not null.
if (docProvider != null) {
final IDocument document = docProvider.getDocument(getEditorInput());
SWTConcurrencyUtil.execForControl(getEditorSite().getShell(), true, new Runnable() {
@Override
public void run() {
try {
model.loadFrom(new IDocumentWrapper(document));
updateIncludedPages();
} catch (IOException e) {
logger.logError("Failed to reload document", e);
}
}
});
}
}
}
}
Aggregations