Class FileDocumentProvider

    • Constructor Detail

      • FileDocumentProvider

        public FileDocumentProvider()
        Creates and returns a new document provider.
    • Method Detail

      • setDocumentContent

        protected boolean setDocumentContent​(IDocument document,
                                             IEditorInput editorInput,
                                             String encoding)
                                      throws CoreException
        Description copied from class: StorageDocumentProvider
        Initializes the given document from the given editor input using the given character encoding.
        Overrides:
        setDocumentContent in class StorageDocumentProvider
        Parameters:
        document - the document to be initialized
        editorInput - the input from which to derive the content of the document
        encoding - the character encoding used to read the editor input
        Returns:
        true if the document content could be set, false otherwise
        Throws:
        CoreException - if the given editor input cannot be accessed
      • checkSynchronizationState

        protected void checkSynchronizationState​(long cachedModificationStamp,
                                                 IResource resource)
                                          throws CoreException
        Checks whether the given resource has been changed on the local file system by comparing the actual time stamp with the cached one. If the resource has been changed, a CoreException is thrown.
        Parameters:
        cachedModificationStamp - the cached modification stamp
        resource - the resource to check
        Throws:
        CoreException - if resource has been changed on the file system
      • computeModificationStamp

        protected long computeModificationStamp​(IResource resource)
        Computes the initial modification stamp for the given resource.
        Parameters:
        resource - the resource
        Returns:
        the modification stamp
      • doSaveDocument

        protected void doSaveDocument​(IProgressMonitor monitor,
                                      Object element,
                                      IDocument document,
                                      boolean overwrite)
                               throws CoreException
        Description copied from class: AbstractDocumentProvider
        Performs the actual work of saving the given document provided for the given element.

        Subclasses must implement this method.

        Overrides:
        doSaveDocument in class StorageDocumentProvider
        Parameters:
        monitor - a progress monitor to report progress and request cancelation
        element - the element
        document - the document
        overwrite - indicates whether an overwrite should happen if necessary
        Throws:
        CoreException - if document could not be stored to the given element
      • createElementInfo

        protected AbstractDocumentProvider.ElementInfo createElementInfo​(Object element)
                                                                  throws CoreException
        Description copied from class: AbstractDocumentProvider
        Creates a new element info object for the given element.

        This method is called from connect when an element info needs to be created. The AbstractDocumentProvider implementation of this method returns a new element info object whose document and annotation model are the values of createDocument(element) and createAnnotationModel(element), respectively. Subclasses may override.

        Overrides:
        createElementInfo in class StorageDocumentProvider
        Parameters:
        element - the element
        Returns:
        a new element info object
        Throws:
        CoreException - if the document or annotation model could not be created
      • handleElementContentChanged

        protected void handleElementContentChanged​(IFileEditorInput fileEditorInput)
        Updates the element info to a change of the file content and sends out appropriate notifications.
        Parameters:
        fileEditorInput - the input of an text editor
      • handleElementMoved

        protected void handleElementMoved​(IFileEditorInput fileEditorInput,
                                          IPath path)
        Sends out the notification that the file serving as document input has been moved.
        Parameters:
        fileEditorInput - the input of an text editor
        path - the path of the new location of the file
      • handleElementDeleted

        protected void handleElementDeleted​(IFileEditorInput fileEditorInput)
        Sends out the notification that the file serving as document input has been deleted.
        Parameters:
        fileEditorInput - the input of an text editor
      • doValidateState

        protected void doValidateState​(Object element,
                                       Object computationContext)
                                throws CoreException
        Description copied from class: AbstractDocumentProvider
        Hook method for validating the state of the given element. Must not take care of cache updating etc. Default implementation is empty.
        Overrides:
        doValidateState in class AbstractDocumentProvider
        Parameters:
        element - the element
        computationContext - the context in which validation happens
        Throws:
        CoreException - in case validation fails
      • isModifiable

        public boolean isModifiable​(Object element)
        Description copied from interface: IDocumentProviderExtension
        Returns whether the document provider thinks that the given element can persistently be modified. This is orthogonal to isReadOnly as read-only elements may be modifiable and writable elements may not be modifiable. If the given element is not connected to this document provider, the result is undefined. Document providers are allowed to use a cache to answer this question, i.e. there can be a difference between the "real" state of the element and the return value.
        Specified by:
        isModifiable in interface IDocumentProviderExtension
        Overrides:
        isModifiable in class StorageDocumentProvider
        Parameters:
        element - the element
        Returns:
        true if the given element is modifiable, false otherwise
      • refreshFile

        protected void refreshFile​(IFile file,
                                   IProgressMonitor monitor)
                            throws CoreException
        Refreshes the given file resource. This method will run the operation in the providers runnable context using given monitor.
        Parameters:
        file - the file to be refreshed
        monitor - the progress monitor
        Throws:
        CoreException - if the refresh fails
        Since:
        3.0
      • getPersistedEncoding

        protected String getPersistedEncoding​(Object element)
        Returns the persisted encoding for the given element.
        Overrides:
        getPersistedEncoding in class StorageDocumentProvider
        Parameters:
        element - the element for which to get the persisted encoding
        Returns:
        the persisted encoding
        Since:
        2.1
      • persistEncoding

        protected void persistEncoding​(Object element,
                                       String encoding)
                                throws CoreException
        Persists the given encoding for the given element.
        Overrides:
        persistEncoding in class StorageDocumentProvider
        Parameters:
        element - the element for which to store the persisted encoding
        encoding - the encoding
        Throws:
        CoreException - if persisting the encoding fails
        Since:
        2.1
      • getRefreshRule

        protected ISchedulingRule getRefreshRule​(Object element)
        Returns the scheduling rule required for executing refresh on the given element. This implementation uses default refresh rule provided by IResourceRuleFactory.refreshRule(IResource).
        Parameters:
        element - the element
        Returns:
        the scheduling rule for refresh
        Since:
        3.11
      • readUTF8BOM

        @Deprecated
        protected void readUTF8BOM​(IFile file,
                                   String encoding,
                                   Object element)
                            throws CoreException
        Deprecated.
        as of 3.0 this method is no longer in use and does nothing
        Reads the file's UTF-8 BOM if any and stores it.

        XXX: This is a workaround for a corresponding bug in Java readers and writer, see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html

        Parameters:
        file - the file
        encoding - the encoding
        element - the element, or null
        Throws:
        CoreException - if reading the BOM fails
        Since:
        3.0
      • cacheEncodingState

        protected void cacheEncodingState​(Object element)
                                   throws CoreException
        Internally caches the file's encoding data.
        Parameters:
        element - the element, or null
        Throws:
        CoreException - if the encoding cannot be retrieved
        Since:
        3.1