Search in sources :

Example 11 with IResourceChangeListener

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);
}
Also used : IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener)

Example 12 with IResourceChangeListener

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);
}
Also used : IPath(org.eclipse.core.runtime.IPath) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IProject(org.eclipse.core.resources.IProject) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) GitResourceDeltaVisitor(org.eclipse.egit.core.internal.indexdiff.GitResourceDeltaVisitor) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 13 with IResourceChangeListener

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);
    }
}
Also used : IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IPath(org.eclipse.core.runtime.IPath) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 14 with IResourceChangeListener

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);
}
Also used : IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IProject(org.eclipse.core.resources.IProject) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) Collection(java.util.Collection) IResource(org.eclipse.core.resources.IResource)

Example 15 with IResourceChangeListener

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);
                        }
                    }
                });
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IOException(java.io.IOException) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument) IResourceDelta(org.eclipse.core.resources.IResourceDelta) Display(org.eclipse.swt.widgets.Display)

Aggregations

IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)19 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)14 IResource (org.eclipse.core.resources.IResource)9 IProject (org.eclipse.core.resources.IProject)8 IResourceDelta (org.eclipse.core.resources.IResourceDelta)6 IWorkspace (org.eclipse.core.resources.IWorkspace)6 IPath (org.eclipse.core.runtime.IPath)6 CoreException (org.eclipse.core.runtime.CoreException)5 IResourceDeltaVisitor (org.eclipse.core.resources.IResourceDeltaVisitor)3 File (java.io.File)2 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 IDocumentWrapper (bndtools.editor.model.IDocumentWrapper)1 ProjectModel (ch.acanda.eclipse.pmd.domain.ProjectModel)1 WorkspaceModel (ch.acanda.eclipse.pmd.domain.WorkspaceModel)1 ProjectModelRepository (ch.acanda.eclipse.pmd.repository.ProjectModelRepository)1 ILiferayLegacyProjectUpdater (com.liferay.ide.project.core.upgrade.ILiferayLegacyProjectUpdater)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1