Class FileDocumentProvider
- All Implemented Interfaces:
IStorageDocumentProvider
,IDocumentProvider
,IDocumentProviderExtension
,IDocumentProviderExtension2
,IDocumentProviderExtension3
,IDocumentProviderExtension4
,IDocumentProviderExtension5
IFile
).
This class may be instantiated or be subclassed.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Bundle of all required information to allow files as underlying document resources.protected class
Synchronizes the document with external resource changes.protected class
Runnable encapsulating an element state change.Nested classes/interfaces inherited from class org.eclipse.ui.editors.text.StorageDocumentProvider
StorageDocumentProvider.StorageInfo
Nested classes/interfaces inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
AbstractDocumentProvider.DocumentProviderOperation, AbstractDocumentProvider.ElementInfo
-
Field Summary
Fields inherited from class org.eclipse.ui.editors.text.StorageDocumentProvider
DEFAULT_FILE_SIZE
Fields inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
PR10806_UC5_ENABLED, PR14469_ENABLED, STATUS_ERROR, STATUS_OK
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
cacheEncodingState
(Object element) Internally caches the file's encoding data.protected void
checkSynchronizationState
(long cachedModificationStamp, IResource resource) Checks whether the given resource has been changed on the local file system by comparing the actual time stamp with the cached one.protected long
computeModificationStamp
(IResource resource) Computes the initial modification stamp for the given resource.protected IAnnotationModel
createAnnotationModel
(Object element) Creates an annotation model for the given element.protected AbstractDocumentProvider.ElementInfo
createElementInfo
(Object element) Creates a new element info object for the given element.protected void
disposeElementInfo
(Object element, AbstractDocumentProvider.ElementInfo info) Disposes of the given element info object.protected void
doResetDocument
(Object element, IProgressMonitor monitor) Executes the actual work of reseting the given elements document.protected void
doSaveDocument
(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) Performs the actual work of saving the given document provided for the given element.protected void
doSynchronize
(Object element, IProgressMonitor monitor) Performs the actual work of synchronizing the given element.protected void
doValidateState
(Object element, Object computationContext) Hook method for validating the state of the given element.getContentType
(Object element) Returns the content type of for the given element ornull
if none could be determined.protected AbstractDocumentProvider.ElementInfo
getElementInfo
(Object element) Returns the element info object for the given element.long
getModificationStamp
(Object element) Returns the modification stamp of the given element.protected IRunnableContext
getOperationRunner
(IProgressMonitor monitor) Returns the runnable context for this document provider.protected String
getPersistedEncoding
(Object element) Returns the persisted encoding for the given element.protected ISchedulingRule
getRefreshRule
(Object element) Returns the scheduling rule required for executingrefresh
on the given element.protected ISchedulingRule
getResetRule
(Object element) Returns the scheduling rule required for executingreset
on the given element.protected ISchedulingRule
getSaveRule
(Object element) Returns the scheduling rule required for executingsave
on the given element.long
getSynchronizationStamp
(Object element) Returns the time stamp of the last synchronization of the given element and its provided document.protected ISchedulingRule
getSynchronizeRule
(Object element) Returns the scheduling rule required for executingsynchronize
on the given element.protected ISchedulingRule
getValidateStateRule
(Object element) Returns the scheduling rule required for executingvalidateState
on the given element.protected void
handleElementContentChanged
(IFileEditorInput fileEditorInput) Updates the element info to a change of the file content and sends out appropriate notifications.protected void
handleElementDeleted
(IFileEditorInput fileEditorInput) Sends out the notification that the file serving as document input has been deleted.protected void
handleElementMoved
(IFileEditorInput fileEditorInput, IPath path) Sends out the notification that the file serving as document input has been moved.boolean
Returns whether the given element has been deleted.boolean
isModifiable
(Object element) Returns whether the document provider thinks that the given element can persistently be modified.boolean
isSynchronized
(Object element) Returns whether the information provided for the given element is in sync with the element.protected void
persistEncoding
(Object element, String encoding) Persists the given encoding for the given element.protected void
readUTF8BOM
(IFile file, String encoding, Object element) Deprecated.as of 3.0 this method is no longer in use and does nothingprotected void
refreshFile
(IFile file) Refreshes the given file resource.protected void
refreshFile
(IFile file, IProgressMonitor monitor) Refreshes the given file resource.protected boolean
setDocumentContent
(IDocument document, IEditorInput editorInput) Deprecated.use file encoding based versionprotected boolean
setDocumentContent
(IDocument document, IEditorInput editorInput, String encoding) Initializes the given document from the given editor input using the given character encoding.Methods inherited from class org.eclipse.ui.editors.text.StorageDocumentProvider
createDocument, createEmptyDocument, doUpdateStateCache, getDefaultEncoding, getEncoding, handleCoreException, isNotSynchronizedException, isReadOnly, setDocumentContent, setDocumentContent, setEncoding, setupDocument, updateCache
Methods inherited from class org.eclipse.ui.texteditor.AbstractDocumentProvider
aboutToChange, addElementStateListener, addUnchangedElementListeners, canSaveDocument, changed, connect, connected, disconnect, disconnected, executeOperation, fireElementContentAboutToBeReplaced, fireElementContentReplaced, fireElementDeleted, fireElementDirtyStateChanged, fireElementMoved, fireElementStateChangeFailed, fireElementStateChanging, fireElementStateValidationChanged, getAnnotationModel, getConnectedElements, getDocument, getProgressMonitor, getStatus, invalidatesState, isStateValidated, mustSaveDocument, removeElementStateListener, removeUnchangedElementListeners, resetDocument, saveDocument, setCanSaveDocument, setProgressMonitor, synchronize, updateStateCache, validateState
-
Constructor Details
-
FileDocumentProvider
public FileDocumentProvider()Creates and returns a new document provider.
-
-
Method Details
-
setDocumentContent
@Deprecated protected boolean setDocumentContent(IDocument document, IEditorInput editorInput) throws CoreException Deprecated.use file encoding based versionOverridesStorageDocumentProvider#setDocumentContent(IDocument, IEditorInput)
.- Overrides:
setDocumentContent
in classStorageDocumentProvider
- Parameters:
document
- the document to be initializededitorInput
- the input from which to derive the content of the document- Returns:
true
if the document content could be set,false
otherwise- Throws:
CoreException
- if the given editor input cannot be accessed- Since:
- 2.0
- See Also:
-
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 classStorageDocumentProvider
- Parameters:
document
- the document to be initializededitorInput
- the input from which to derive the content of the documentencoding
- 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
-
createAnnotationModel
Description copied from class:AbstractDocumentProvider
Creates an annotation model for the given element.Subclasses must implement this method.
- Overrides:
createAnnotationModel
in classStorageDocumentProvider
- Parameters:
element
- the element- Returns:
- the annotation model or
null
if none - Throws:
CoreException
- if the annotation model could not be created
-
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, aCoreException
is thrown.- Parameters:
cachedModificationStamp
- the cached modification stampresource
- the resource to check- Throws:
CoreException
- if resource has been changed on the file system
-
computeModificationStamp
Computes the initial modification stamp for the given resource.- Parameters:
resource
- the resource- Returns:
- the modification stamp
-
getModificationStamp
Description copied from interface:IDocumentProvider
Returns the modification stamp of the given element.- Specified by:
getModificationStamp
in interfaceIDocumentProvider
- Overrides:
getModificationStamp
in classAbstractDocumentProvider
- Parameters:
element
- the element- Returns:
- the modification stamp of the given element
-
getSynchronizationStamp
Description copied from interface:IDocumentProvider
Returns the time stamp of the last synchronization of the given element and its provided document.- Specified by:
getSynchronizationStamp
in interfaceIDocumentProvider
- Overrides:
getSynchronizationStamp
in classAbstractDocumentProvider
- Parameters:
element
- the element- Returns:
- the synchronization stamp of the given element
-
doSynchronize
Description copied from class:AbstractDocumentProvider
Performs the actual work of synchronizing the given element.- Overrides:
doSynchronize
in classAbstractDocumentProvider
- Parameters:
element
- the elementmonitor
- the progress monitor- Throws:
CoreException
- in the case that synchronization fails
-
isDeleted
Description copied from interface:IDocumentProvider
Returns whether the given element has been deleted.- Specified by:
isDeleted
in interfaceIDocumentProvider
- Overrides:
isDeleted
in classAbstractDocumentProvider
- Parameters:
element
- the element- Returns:
true
if the element has been deleted
-
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 classStorageDocumentProvider
- Parameters:
monitor
- a progress monitor to report progress and request cancelationelement
- the elementdocument
- the documentoverwrite
- 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. TheAbstractDocumentProvider
implementation of this method returns a new element info object whose document and annotation model are the values ofcreateDocument(element)
andcreateAnnotationModel(element)
, respectively. Subclasses may override.- Overrides:
createElementInfo
in classStorageDocumentProvider
- Parameters:
element
- the element- Returns:
- a new element info object
- Throws:
CoreException
- if the document or annotation model could not be created
-
disposeElementInfo
Description copied from class:AbstractDocumentProvider
Disposes of the given element info object.This method is called when an element info is disposed. The
AbstractDocumentProvider
implementation of this method does nothing. Subclasses may reimplement.- Overrides:
disposeElementInfo
in classAbstractDocumentProvider
- Parameters:
element
- the elementinfo
- the element info object
-
handleElementContentChanged
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
Sends out the notification that the file serving as document input has been moved.- Parameters:
fileEditorInput
- the input of an text editorpath
- the path of the new location of the file
-
handleElementDeleted
Sends out the notification that the file serving as document input has been deleted.- Parameters:
fileEditorInput
- the input of an text editor
-
getElementInfo
Description copied from class:AbstractDocumentProvider
Returns the element info object for the given element.- Overrides:
getElementInfo
in classAbstractDocumentProvider
- Parameters:
element
- the element- Returns:
- the element info object, or
null
if none
-
doValidateState
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 classAbstractDocumentProvider
- Parameters:
element
- the elementcomputationContext
- the context in which validation happens- Throws:
CoreException
- in case validation fails
-
isModifiable
Description copied from interface:IDocumentProviderExtension
Returns whether the document provider thinks that the given element can persistently be modified. This is orthogonal toisReadOnly
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 interfaceIDocumentProviderExtension
- Overrides:
isModifiable
in classStorageDocumentProvider
- Parameters:
element
- the element- Returns:
true
if the given element is modifiable,false
otherwise
-
doResetDocument
Description copied from class:AbstractDocumentProvider
Executes the actual work of reseting the given elements document.- Overrides:
doResetDocument
in classAbstractDocumentProvider
- Parameters:
element
- the elementmonitor
- the progress monitor- Throws:
CoreException
- if resetting fails
-
refreshFile
Refreshes the given file resource. This method will run the operation in the providers runnable context using the monitor supplied byAbstractDocumentProvider.getProgressMonitor()
.- Parameters:
file
- the file- Throws:
CoreException
- if the refresh fails- Since:
- 2.1
-
refreshFile
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 refreshedmonitor
- the progress monitor- Throws:
CoreException
- if the refresh fails- Since:
- 3.0
-
isSynchronized
Description copied from interface:IDocumentProviderExtension3
Returns whether the information provided for the given element is in sync with the element.- Specified by:
isSynchronized
in interfaceIDocumentProviderExtension3
- Overrides:
isSynchronized
in classAbstractDocumentProvider
- Parameters:
element
- the element- Returns:
true
if the information is in sync with the element,false
otherwise
-
getContentType
Description copied from interface:IDocumentProviderExtension4
Returns the content type of for the given element ornull
if none could be determined. If the element's document can be saved, the returned content type is determined by the document's current content.- Specified by:
getContentType
in interfaceIDocumentProviderExtension4
- Overrides:
getContentType
in classStorageDocumentProvider
- Parameters:
element
- the element- Returns:
- the content type or
null
- Throws:
CoreException
- if reading or accessing the underlying store fails
-
getPersistedEncoding
Returns the persisted encoding for the given element.- Overrides:
getPersistedEncoding
in classStorageDocumentProvider
- Parameters:
element
- the element for which to get the persisted encoding- Returns:
- the persisted encoding
- Since:
- 2.1
-
persistEncoding
Persists the given encoding for the given element.- Overrides:
persistEncoding
in classStorageDocumentProvider
- Parameters:
element
- the element for which to store the persisted encodingencoding
- the encoding- Throws:
CoreException
- if persisting the encoding fails- Since:
- 2.1
-
getOperationRunner
Description copied from class:AbstractDocumentProvider
Returns the runnable context for this document provider.- Overrides:
getOperationRunner
in classStorageDocumentProvider
- Parameters:
monitor
- a progress monitor to track the operation- Returns:
- the runnable context for this document provider
-
getResetRule
Description copied from class:AbstractDocumentProvider
Returns the scheduling rule required for executingreset
on the given element. This default implementation returnsnull
.- Overrides:
getResetRule
in classAbstractDocumentProvider
- Parameters:
element
- the element- Returns:
- the scheduling rule for
reset
-
getRefreshRule
Returns the scheduling rule required for executingrefresh
on the given element. This implementation uses default refresh rule provided byIResourceRuleFactory.refreshRule(IResource)
.- Parameters:
element
- the element- Returns:
- the scheduling rule for
refresh
- Since:
- 3.11
-
getSaveRule
Description copied from class:AbstractDocumentProvider
Returns the scheduling rule required for executingsave
on the given element. This default implementation returnsnull
.- Overrides:
getSaveRule
in classAbstractDocumentProvider
- Parameters:
element
- the element- Returns:
- the scheduling rule for
save
-
getSynchronizeRule
Description copied from class:AbstractDocumentProvider
Returns the scheduling rule required for executingsynchronize
on the given element. This default implementation returnsnull
.- Overrides:
getSynchronizeRule
in classAbstractDocumentProvider
- Parameters:
element
- the element- Returns:
- the scheduling rule for
synchronize
-
getValidateStateRule
Description copied from class:AbstractDocumentProvider
Returns the scheduling rule required for executingvalidateState
on the given element. This default implementation returnsnull
.- Overrides:
getValidateStateRule
in classAbstractDocumentProvider
- Parameters:
element
- the element- Returns:
- the scheduling rule for
validateState
-
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 nothingReads 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 fileencoding
- the encodingelement
- the element, ornull
- Throws:
CoreException
- if reading the BOM fails- Since:
- 3.0
-
cacheEncodingState
Internally caches the file's encoding data.- Parameters:
element
- the element, ornull
- Throws:
CoreException
- if the encoding cannot be retrieved- Since:
- 3.1
-