Class FileChangesCollection

  • All Implemented Interfaces:
    IFolderFileChangeListener, org.eclipse.core.resources.IResourceDeltaVisitor, org.eclipse.core.resources.IResourceVisitor
    Direct Known Subclasses:
    JavaManager

    public class FileChangesCollection
    extends java.lang.Object
    implements org.eclipse.core.resources.IResourceVisitor, org.eclipse.core.resources.IResourceDeltaVisitor, IFolderFileChangeListener
    Class used to process file changes to create a collection of added, removed or renamed/moved files from a list of folders upon a change in the file system.

    The tables addedOrChanged, renamedOrMoved and removed are public, but care should be taken to only work on the snap-shot copy and not the "live" one, otherwise unpredictable results may occur.

    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      java.lang.Stringdescription
      The description of the visit.
      protected org.eclipse.core.runtime.IProgressMonitormonitor
      A progress monitor if not null.
      protected ProjectManagerprojectManager
      The current Project Manager, null for none, to inform file changes.
    • Constructor Summary

      Constructors 
      ConstructorDescription
      FileChangesCollection​(java.lang.String description, ProjectManager projectManager)
      Constructs the instance without specified folders.
      FileChangesCollection​(java.lang.String description, org.eclipse.core.resources.IFolder[] folders, ProjectManager projectManager)
      Constructs the instance with the specified folders.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      org.eclipse.core.resources.IFolder[]getFolders()
      Gets the folders currently used.
      org.eclipse.core.runtime.MultiStatusgetMultiStatus()
      Gets the MultiStatus instance when visiting, in order to merge errors.
      protected booleanisFileProcessed​(org.eclipse.core.resources.IFile file)
      Checks if file is processed.
      booleanisProcessed​(org.eclipse.core.resources.IResource resource)
      Checks if the resource is one of the folders.
      voidonFileAdded​(org.eclipse.core.resources.IFile file)
      File has been added.
      voidonFileChanged​(org.eclipse.core.resources.IFile file, int flags)
      File has been changed (markers, contents, etc).
      voidonFileMoved​(org.eclipse.core.resources.IFile newFile, org.eclipse.core.resources.IFile oldFile)
      File has been moved.
      voidonFileRemoved​(org.eclipse.core.resources.IFile file)
      File has been removed.
      voidonFolderAdded​(org.eclipse.core.resources.IFolder folder)
      Folder has been added.
      voidonFolderMoved​(org.eclipse.core.resources.IFolder newFolder, org.eclipse.core.resources.IFolder oldFolder)
      Folder has been moved.
      voidonFolderRemoved​(org.eclipse.core.resources.IFolder folder)
      Folder has been removed.
      voidonNewFolders​(org.eclipse.core.resources.IFolder[] folders)
      Called when new folders has been assigned, due to e.g.
      voidprocess​(org.eclipse.core.resources.IResourceDelta delta)
      Processes a delta, it is assumed a check for folder processing has been done using isProcessed(folder) prior to calling this method.
      voidsetMultiStatus​(org.eclipse.core.runtime.MultiStatus multiStatus)
      Assigns a MultiStatus before visit.
      voidsetNewFolders​(org.eclipse.core.resources.IFolder[] folders)
      Assigns the folders to process.
      voidsetProgressMonitor​(org.eclipse.core.runtime.IProgressMonitor monitor)
      Assigns a progress monitor to cancel lengthy job.
      booleanvisit​(org.eclipse.core.resources.IResource resource)
      Called to visit the a resource in one of the processed folders.
      booleanvisit​(org.eclipse.core.resources.IResourceDelta delta)
      Called to visit the delta changes in one of the processed folders.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • description

        public final java.lang.String description
        The description of the visit.
      • projectManager

        protected final ProjectManager projectManager
        The current Project Manager, null for none, to inform file changes.
      • monitor

        protected org.eclipse.core.runtime.IProgressMonitor monitor
        A progress monitor if not null.
    • Constructor Detail

      • FileChangesCollection

        public FileChangesCollection​(java.lang.String description,
                                     ProjectManager projectManager)
        Constructs the instance without specified folders.
        Parameters:
        description - Description of the visit, if it fails.
        projectManager - Instance of Project Manager to inform of changes, null not to inform...
      • FileChangesCollection

        public FileChangesCollection​(java.lang.String description,
                                     org.eclipse.core.resources.IFolder[] folders,
                                     ProjectManager projectManager)
        Constructs the instance with the specified folders.
        Parameters:
        description - Description of the visit, if it fails.
        folders - The folders to process.
        projectManager - Instance of Project Manager to inform of changes, null not to inform...
    • Method Detail

      • setProgressMonitor

        public void setProgressMonitor​(org.eclipse.core.runtime.IProgressMonitor monitor)
        Assigns a progress monitor to cancel lengthy job.
      • setNewFolders

        public final void setNewFolders​(org.eclipse.core.resources.IFolder[] folders)
        Assigns the folders to process.
      • onNewFolders

        public void onNewFolders​(org.eclipse.core.resources.IFolder[] folders)
        Called when new folders has been assigned, due to e.g. Java project settings changed to add/remove a source folder.

        Subclasses should override to process the event, no need to call the super method.

        Parameters:
        folders - The new folders.
      • getFolders

        public org.eclipse.core.resources.IFolder[] getFolders()
        Gets the folders currently used.
      • isProcessed

        public final boolean isProcessed​(org.eclipse.core.resources.IResource resource)
        Checks if the resource is one of the folders.
      • process

        public final void process​(org.eclipse.core.resources.IResourceDelta delta)
                           throws org.eclipse.core.runtime.CoreException
        Processes a delta, it is assumed a check for folder processing has been done using isProcessed(folder) prior to calling this method.
        Parameters:
        delta - The delta for resources.
        Throws:
        org.eclipse.core.runtime.CoreException - For visiting errors.
      • setMultiStatus

        public void setMultiStatus​(org.eclipse.core.runtime.MultiStatus multiStatus)
        Assigns a MultiStatus before visit. This helps catching the exception into this multiple status that is thrown upon return.
        Parameters:
        multiStatus - The multi-status or null not to use it.
      • getMultiStatus

        public org.eclipse.core.runtime.MultiStatus getMultiStatus()
        Gets the MultiStatus instance when visiting, in order to merge errors.
      • visit

        public final boolean visit​(org.eclipse.core.resources.IResource resource)
                            throws org.eclipse.core.runtime.CoreException
        Called to visit the a resource in one of the processed folders.
        Specified by:
        visit in interface org.eclipse.core.resources.IResourceVisitor
        Throws:
        org.eclipse.core.runtime.CoreException - For visiting errors.
      • visit

        public final boolean visit​(org.eclipse.core.resources.IResourceDelta delta)
                            throws org.eclipse.core.runtime.CoreException
        Called to visit the delta changes in one of the processed folders.
        Specified by:
        visit in interface org.eclipse.core.resources.IResourceDeltaVisitor
        Throws:
        org.eclipse.core.runtime.CoreException - For visiting errors.
      • isFileProcessed

        protected boolean isFileProcessed​(org.eclipse.core.resources.IFile file)
        Checks if file is processed.

        Subclasses must check if this resource is to be processed and return true if it's a valid file (typically the file extension).

        Parameters:
        file - The file.
        Returns:
        true if file is to be processed, false otherwise.
      • onFileAdded

        public void onFileAdded​(org.eclipse.core.resources.IFile file)
                         throws org.eclipse.core.runtime.CoreException
        File has been added.

        Subclasses should override to process the event, no need to call the super method.

        Specified by:
        onFileAdded in interface IFolderFileChangeListener
        Parameters:
        file - The file.
        Throws:
        org.eclipse.core.runtime.CoreException - For failures.
      • onFileMoved

        public void onFileMoved​(org.eclipse.core.resources.IFile newFile,
                                org.eclipse.core.resources.IFile oldFile)
                         throws org.eclipse.core.runtime.CoreException
        File has been moved.

        Subclasses should override to process the event, no need to call the super method.

        Specified by:
        onFileMoved in interface IFolderFileChangeListener
        Parameters:
        newFile - The new file.
        oldFile - The old file.
        Throws:
        org.eclipse.core.runtime.CoreException - For failures.
      • onFileChanged

        public void onFileChanged​(org.eclipse.core.resources.IFile file,
                                  int flags)
                           throws org.eclipse.core.runtime.CoreException
        File has been changed (markers, contents, etc).

        Subclasses should override to process the event, no need to call the super method.

        Specified by:
        onFileChanged in interface IFolderFileChangeListener
        Parameters:
        file - The file.
        flags - How the file was changed, from IResourceDelta, where the important ones are CONTENT, MARKERS, ENCODING, LOCAL_CHANGE, DERIVED_CHANGED, REPLACED.
        Throws:
        org.eclipse.core.runtime.CoreException - For failures.
      • onFileRemoved

        public void onFileRemoved​(org.eclipse.core.resources.IFile file)
                           throws org.eclipse.core.runtime.CoreException
        File has been removed.

        Subclasses should override to process the event, no need to call the super method.

        Specified by:
        onFileRemoved in interface IFolderFileChangeListener
        Parameters:
        file - The file.
        Throws:
        org.eclipse.core.runtime.CoreException - For failures.
      • onFolderAdded

        public void onFolderAdded​(org.eclipse.core.resources.IFolder folder)
                           throws org.eclipse.core.runtime.CoreException
        Folder has been added.

        Subclasses should override to process the event, no need to call the super method.

        Specified by:
        onFolderAdded in interface IFolderFileChangeListener
        Parameters:
        folder - The folder.
        Throws:
        org.eclipse.core.runtime.CoreException - For failures.
      • onFolderMoved

        public void onFolderMoved​(org.eclipse.core.resources.IFolder newFolder,
                                  org.eclipse.core.resources.IFolder oldFolder)
                           throws org.eclipse.core.runtime.CoreException
        Folder has been moved.

        Subclasses should override to process the event, no need to call the super method.

        Specified by:
        onFolderMoved in interface IFolderFileChangeListener
        Parameters:
        newFolder - The new folder.
        oldFolder - The old folder.
        Throws:
        org.eclipse.core.runtime.CoreException - For failures.
      • onFolderRemoved

        public void onFolderRemoved​(org.eclipse.core.resources.IFolder folder)
                             throws org.eclipse.core.runtime.CoreException
        Folder has been removed.

        Subclasses should override to process the event, no need to call the super method.

        Specified by:
        onFolderRemoved in interface IFolderFileChangeListener
        Parameters:
        folder - The folder.
        Throws:
        org.eclipse.core.runtime.CoreException - For failures.