Class FileDocumentProvider
- java.lang.Object
-
- org.eclipse.ui.texteditor.AbstractDocumentProvider
-
- org.eclipse.ui.editors.text.StorageDocumentProvider
-
- org.eclipse.ui.editors.text.FileDocumentProvider
-
- All Implemented Interfaces:
IStorageDocumentProvider,IDocumentProvider,IDocumentProviderExtension,IDocumentProviderExtension2,IDocumentProviderExtension3,IDocumentProviderExtension4,IDocumentProviderExtension5
public class FileDocumentProvider extends StorageDocumentProvider
Shared document provider specialized for file resources (IFile).This class may be instantiated or be subclassed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classFileDocumentProvider.FileInfoBundle of all required information to allow files as underlying document resources.protected classFileDocumentProvider.FileSynchronizerSynchronizes the document with external resource changes.protected classFileDocumentProvider.SafeChangeRunnable 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
Constructors Constructor Description FileDocumentProvider()Creates and returns a new document provider.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidcacheEncodingState(Object element)Internally caches the file's encoding data.protected voidcheckSynchronizationState(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 longcomputeModificationStamp(IResource resource)Computes the initial modification stamp for the given resource.protected IAnnotationModelcreateAnnotationModel(Object element)Creates an annotation model for the given element.protected AbstractDocumentProvider.ElementInfocreateElementInfo(Object element)Creates a new element info object for the given element.protected voiddisposeElementInfo(Object element, AbstractDocumentProvider.ElementInfo info)Disposes of the given element info object.protected voiddoResetDocument(Object element, IProgressMonitor monitor)Executes the actual work of reseting the given elements document.protected voiddoSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)Performs the actual work of saving the given document provided for the given element.protected voiddoSynchronize(Object element, IProgressMonitor monitor)Performs the actual work of synchronizing the given element.protected voiddoValidateState(Object element, Object computationContext)Hook method for validating the state of the given element.IContentTypegetContentType(Object element)Returns the content type of for the given element ornullif none could be determined.protected AbstractDocumentProvider.ElementInfogetElementInfo(Object element)Returns the element info object for the given element.longgetModificationStamp(Object element)Returns the modification stamp of the given element.protected IRunnableContextgetOperationRunner(IProgressMonitor monitor)Returns the runnable context for this document provider.protected StringgetPersistedEncoding(Object element)Returns the persisted encoding for the given element.protected ISchedulingRulegetRefreshRule(Object element)Returns the scheduling rule required for executingrefreshon the given element.protected ISchedulingRulegetResetRule(Object element)Returns the scheduling rule required for executingreseton the given element.protected ISchedulingRulegetSaveRule(Object element)Returns the scheduling rule required for executingsaveon the given element.longgetSynchronizationStamp(Object element)Returns the time stamp of the last synchronization of the given element and its provided document.protected ISchedulingRulegetSynchronizeRule(Object element)Returns the scheduling rule required for executingsynchronizeon the given element.protected ISchedulingRulegetValidateStateRule(Object element)Returns the scheduling rule required for executingvalidateStateon the given element.protected voidhandleElementContentChanged(IFileEditorInput fileEditorInput)Updates the element info to a change of the file content and sends out appropriate notifications.protected voidhandleElementDeleted(IFileEditorInput fileEditorInput)Sends out the notification that the file serving as document input has been deleted.protected voidhandleElementMoved(IFileEditorInput fileEditorInput, IPath path)Sends out the notification that the file serving as document input has been moved.booleanisDeleted(Object element)Returns whether the given element has been deleted.booleanisModifiable(Object element)Returns whether the document provider thinks that the given element can persistently be modified.booleanisSynchronized(Object element)Returns whether the information provided for the given element is in sync with the element.protected voidpersistEncoding(Object element, String encoding)Persists the given encoding for the given element.protected voidreadUTF8BOM(IFile file, String encoding, Object element)Deprecated.as of 3.0 this method is no longer in use and does nothingprotected voidrefreshFile(IFile file)Refreshes the given file resource.protected voidrefreshFile(IFile file, IProgressMonitor monitor)Refreshes the given file resource.protected booleansetDocumentContent(IDocument document, IEditorInput editorInput)Deprecated.use file encoding based versionprotected booleansetDocumentContent(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
-
-
-
-
Method Detail
-
setDocumentContent
@Deprecated protected boolean setDocumentContent(IDocument document, IEditorInput editorInput) throws CoreException
Deprecated.use file encoding based versionOverridesStorageDocumentProvider#setDocumentContent(IDocument, IEditorInput).- Overrides:
setDocumentContentin classStorageDocumentProvider- Parameters:
document- the document to be initializededitorInput- the input from which to derive the content of the document- Returns:
trueif the document content could be set,falseotherwise- Throws:
CoreException- if the given editor input cannot be accessed- Since:
- 2.0
- See Also:
StorageDocumentProvider.setDocumentContent(IDocument, IEditorInput)
-
setDocumentContent
protected boolean setDocumentContent(IDocument document, IEditorInput editorInput, String encoding) throws CoreException
Description copied from class:StorageDocumentProviderInitializes the given document from the given editor input using the given character encoding.- Overrides:
setDocumentContentin 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:
trueif the document content could be set,falseotherwise- Throws:
CoreException- if the given editor input cannot be accessed
-
createAnnotationModel
protected IAnnotationModel createAnnotationModel(Object element) throws CoreException
Description copied from class:AbstractDocumentProviderCreates an annotation model for the given element.Subclasses must implement this method.
- Overrides:
createAnnotationModelin classStorageDocumentProvider- Parameters:
element- the element- Returns:
- the annotation model or
nullif none - Throws:
CoreException- if the annotation model could not be created
-
checkSynchronizationState
protected void checkSynchronizationState(long cachedModificationStamp, IResource resource) throws CoreExceptionChecks 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, aCoreExceptionis thrown.- Parameters:
cachedModificationStamp- the cached modification stampresource- 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
-
getModificationStamp
public long getModificationStamp(Object element)
Description copied from interface:IDocumentProviderReturns the modification stamp of the given element.- Specified by:
getModificationStampin interfaceIDocumentProvider- Overrides:
getModificationStampin classAbstractDocumentProvider- Parameters:
element- the element- Returns:
- the modification stamp of the given element
-
getSynchronizationStamp
public long getSynchronizationStamp(Object element)
Description copied from interface:IDocumentProviderReturns the time stamp of the last synchronization of the given element and its provided document.- Specified by:
getSynchronizationStampin interfaceIDocumentProvider- Overrides:
getSynchronizationStampin classAbstractDocumentProvider- Parameters:
element- the element- Returns:
- the synchronization stamp of the given element
-
doSynchronize
protected void doSynchronize(Object element, IProgressMonitor monitor) throws CoreException
Description copied from class:AbstractDocumentProviderPerforms the actual work of synchronizing the given element.- Overrides:
doSynchronizein classAbstractDocumentProvider- Parameters:
element- the elementmonitor- the progress monitor- Throws:
CoreException- in the case that synchronization fails
-
isDeleted
public boolean isDeleted(Object element)
Description copied from interface:IDocumentProviderReturns whether the given element has been deleted.- Specified by:
isDeletedin interfaceIDocumentProvider- Overrides:
isDeletedin classAbstractDocumentProvider- Parameters:
element- the element- Returns:
trueif the element has been deleted
-
doSaveDocument
protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException
Description copied from class:AbstractDocumentProviderPerforms the actual work of saving the given document provided for the given element.Subclasses must implement this method.
- Overrides:
doSaveDocumentin 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:AbstractDocumentProviderCreates a new element info object for the given element.This method is called from
connectwhen an element info needs to be created. TheAbstractDocumentProviderimplementation 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:
createElementInfoin classStorageDocumentProvider- Parameters:
element- the element- Returns:
- a new element info object
- Throws:
CoreException- if the document or annotation model could not be created
-
disposeElementInfo
protected void disposeElementInfo(Object element, AbstractDocumentProvider.ElementInfo info)
Description copied from class:AbstractDocumentProviderDisposes of the given element info object.This method is called when an element info is disposed. The
AbstractDocumentProviderimplementation of this method does nothing. Subclasses may reimplement.- Overrides:
disposeElementInfoin classAbstractDocumentProvider- Parameters:
element- the elementinfo- the element info object
-
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 editorpath- 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
-
getElementInfo
protected AbstractDocumentProvider.ElementInfo getElementInfo(Object element)
Description copied from class:AbstractDocumentProviderReturns the element info object for the given element.- Overrides:
getElementInfoin classAbstractDocumentProvider- Parameters:
element- the element- Returns:
- the element info object, or
nullif none
-
doValidateState
protected void doValidateState(Object element, Object computationContext) throws CoreException
Description copied from class:AbstractDocumentProviderHook method for validating the state of the given element. Must not take care of cache updating etc. Default implementation is empty.- Overrides:
doValidateStatein classAbstractDocumentProvider- Parameters:
element- the elementcomputationContext- the context in which validation happens- Throws:
CoreException- in case validation fails
-
isModifiable
public boolean isModifiable(Object element)
Description copied from interface:IDocumentProviderExtensionReturns whether the document provider thinks that the given element can persistently be modified. This is orthogonal toisReadOnlyas 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:
isModifiablein interfaceIDocumentProviderExtension- Overrides:
isModifiablein classStorageDocumentProvider- Parameters:
element- the element- Returns:
trueif the given element is modifiable,falseotherwise
-
doResetDocument
protected void doResetDocument(Object element, IProgressMonitor monitor) throws CoreException
Description copied from class:AbstractDocumentProviderExecutes the actual work of reseting the given elements document.- Overrides:
doResetDocumentin classAbstractDocumentProvider- Parameters:
element- the elementmonitor- the progress monitor- Throws:
CoreException- if resetting fails
-
refreshFile
protected void refreshFile(IFile file) throws CoreException
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
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 refreshedmonitor- the progress monitor- Throws:
CoreException- if the refresh fails- Since:
- 3.0
-
isSynchronized
public boolean isSynchronized(Object element)
Description copied from interface:IDocumentProviderExtension3Returns whether the information provided for the given element is in sync with the element.- Specified by:
isSynchronizedin interfaceIDocumentProviderExtension3- Overrides:
isSynchronizedin classAbstractDocumentProvider- Parameters:
element- the element- Returns:
trueif the information is in sync with the element,falseotherwise
-
getContentType
public IContentType getContentType(Object element) throws CoreException
Description copied from interface:IDocumentProviderExtension4Returns the content type of for the given element ornullif 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:
getContentTypein interfaceIDocumentProviderExtension4- Overrides:
getContentTypein classStorageDocumentProvider- Parameters:
element- the element- Returns:
- the content type or
null - Throws:
CoreException- if reading or accessing the underlying store fails
-
getPersistedEncoding
protected String getPersistedEncoding(Object element)
Returns the persisted encoding for the given element.- Overrides:
getPersistedEncodingin classStorageDocumentProvider- 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:
persistEncodingin 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
protected IRunnableContext getOperationRunner(IProgressMonitor monitor)
Description copied from class:AbstractDocumentProviderReturns the runnable context for this document provider.- Overrides:
getOperationRunnerin classStorageDocumentProvider- Parameters:
monitor- a progress monitor to track the operation- Returns:
- the runnable context for this document provider
-
getResetRule
protected ISchedulingRule getResetRule(Object element)
Description copied from class:AbstractDocumentProviderReturns the scheduling rule required for executingreseton the given element. This default implementation returnsnull.- Overrides:
getResetRulein classAbstractDocumentProvider- Parameters:
element- the element- Returns:
- the scheduling rule for
reset
-
getRefreshRule
protected ISchedulingRule getRefreshRule(Object element)
Returns the scheduling rule required for executingrefreshon 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
protected ISchedulingRule getSaveRule(Object element)
Description copied from class:AbstractDocumentProviderReturns the scheduling rule required for executingsaveon the given element. This default implementation returnsnull.- Overrides:
getSaveRulein classAbstractDocumentProvider- Parameters:
element- the element- Returns:
- the scheduling rule for
save
-
getSynchronizeRule
protected ISchedulingRule getSynchronizeRule(Object element)
Description copied from class:AbstractDocumentProviderReturns the scheduling rule required for executingsynchronizeon the given element. This default implementation returnsnull.- Overrides:
getSynchronizeRulein classAbstractDocumentProvider- Parameters:
element- the element- Returns:
- the scheduling rule for
synchronize
-
getValidateStateRule
protected ISchedulingRule getValidateStateRule(Object element)
Description copied from class:AbstractDocumentProviderReturns the scheduling rule required for executingvalidateStateon the given element. This default implementation returnsnull.- Overrides:
getValidateStateRulein 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
protected void cacheEncodingState(Object element) throws CoreException
Internally caches the file's encoding data.- Parameters:
element- the element, ornull- Throws:
CoreException- if the encoding cannot be retrieved- Since:
- 3.1
-
-