Class TextFileDocumentProvider
- All Implemented Interfaces:
- IStorageDocumentProvider,- IDocumentProvider,- IDocumentProviderExtension,- IDocumentProviderExtension2,- IDocumentProviderExtension3,- IDocumentProviderExtension4,- IDocumentProviderExtension5
IFile based domain elements.
 A text file document provider can have a parent document provider to which
 it may delegate calls i.e. instead of delegating work to a super class it
 delegates to a parent document provider. The parent chain acts as chain
 of command.
 Text file document providers use text file buffers to access the file content. This allows to share it between various clients including headless ones. Text file document providers should be preferred over file document providers due to this advantage.
Use a forwarding document provider if you need to ensure that all documents provided to clients are appropriately set up.
Clients can directly instantiate and configure this class with a suitable parent document provider or provide their own subclass.
- Since:
- 3.0
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classOperation created by the document provider and to be executed by the providers runnable context.protected classprotected static classprotected static classDeprecated.As of 3.3 - do not use
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a new text file document provider with no parent.TextFileDocumentProvider(IDocumentProvider parentProvider) Creates a new text file document provider which has the given parent provider.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaboutToChange(Object element) Informs this document provider about upcoming changes of the given element.voidaddElementStateListener(IElementStateListener listener) Adds the given element state listener to this document provider.booleancanSaveDocument(Object element) Returns whether the document provided for the given element differs from its original state which would required that it be saved.voidInforms this document provider that the given element has been changed.protected voidcommitFileBuffer(IProgressMonitor monitor, TextFileDocumentProvider.FileInfo info, boolean overwrite) Commits the given file info's file buffer by changing the contents of the underlying file to the contents of this file buffer.protected ISchedulingRulecomputeSchedulingRule(IResource toCreateOrModify) Computes the scheduling rule needed to create or modify a resource.voidConnects the given element to this document provider.protected IAnnotationModelcreateAnnotationModel(IFile file) Creates and returns the annotation model for the given file.protected TextFileDocumentProvider.FileInfoCreates and returns a new and empty file info object.protected voidcreateFileFromDocument(IProgressMonitor monitor, IFile file, IDocument document) Creates the given file with the given document content.protected TextFileDocumentProvider.FileInfocreateFileInfo(Object element) Creates and returns the file info object for the given element.createSaveOperation(Object element, IDocument document, boolean overwrite) voiddisconnect(Object element) Disconnects the given element from this document provider.protected voiddisposeFileInfo(Object element, TextFileDocumentProvider.FileInfo info) Releases all resources described by given element's info object.protected voidexecuteOperation(TextFileDocumentProvider.DocumentProviderOperation operation, IProgressMonitor monitor) Executes the given operation in the providers runnable context.protected voidfireElementStateChangeFailed(Object element) Informs all registered element state listeners about the failed state change of the element.protected voidfireElementStateChanging(Object element) Informs all registered element state listeners about the current state change of the element.getAnnotationModel(Object element) Returns the annotation model for the given element.Returns an iterator over the elements connected via this document provider.getContentType(Object element) Returns the content type of for the given element ornullif none could be determined.Returns the default character encoding used by this provider.getDocument(Object element) Returns the document for the given element.getElements(IFileBuffer file) Returns an iterator for all the elements that are connected to this file buffer.getEncoding(Object element) Returns the character encoding for the given element, ornullif the element is not managed by this provider.protected TextFileDocumentProvider.FileInfogetFileInfo(Object element) Returns the file info object for the given element.protected Iterator<TextFileDocumentProvider.FileInfo> Returns an iterator over this document provider's file info objects.protected IFileStoreReturns the file store denoted by the given info.longgetModificationStamp(Object element) Returns the modification stamp of the given element.protected IRunnableContextgetOperationRunner(IProgressMonitor monitor) Returns the runnable context for this document provider.protected final IDocumentProviderReturns the parent document provider.Returns this providers progress monitor.Returns the status of the given element.longgetSynchronizationStamp(Object element) Returns the time stamp of the last synchronization of the given element and its provided document.protected FileDeprecated.As of 3.2, replaced bygetFileStore(org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)protected voidhandleCoreException(CoreException exception, String message) Defines the standard procedure to handleCoreExceptions.booleanReturns whether the given element has been deleted.booleanisModifiable(Object element) Returns whether the document provider thinks that the given element can persistently be modified.booleanisNotSynchronizedException(Object element, CoreException ex) Tells whether the given core exception is exactly the exception which is thrown for a non-synchronized element.booleanisReadOnly(Object element) Returns whether the document provider thinks that the given element is read-only.booleanisStateValidated(Object element) Returns whether the state of the given element has been validated.booleanisSynchronized(Object element) Returns whether the information provided for the given element is in sync with the element.protected booleanReturns whether the system file denoted by the given info is read-only.booleanmustSaveDocument(Object element) Returns whether the document provided for the given element must be saved.voidRemoves the given element state listener from this document provider.voidresetDocument(Object element) Resets the given element's document to its last saved state.final voidsaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) Saves the given document provided for the given element.voidsetCanSaveDocument(Object element) Marks the document managed for the given element as savable.voidsetEncoding(Object element, String encoding) Sets the encoding for the given element.final voidsetParentDocumentProvider(IDocumentProvider parentProvider) Sets the given parent provider as this document provider's parent document provider.voidsetProgressMonitor(IProgressMonitor progressMonitor) Sets this providers progress monitor.protected voidSets up the synchronization for the document and the annotation mode.voidsynchronize(Object element) Synchronizes the document provided for the given element with the given element.voidupdateStateCache(Object element) Updates the state cache for the given element.voidvalidateState(Object element, Object computationContext) Validates the state of the given element.
- 
Constructor Details- 
TextFileDocumentProviderpublic TextFileDocumentProvider()Creates a new text file document provider with no parent.
- 
TextFileDocumentProviderCreates a new text file document provider which has the given parent provider.- Parameters:
- parentProvider- the parent document provider
 
 
- 
- 
Method Details- 
setParentDocumentProviderSets the given parent provider as this document provider's parent document provider.- Parameters:
- parentProvider- the parent document provider
 
- 
getParentProviderReturns the parent document provider.- Returns:
- the parent document provider
 
- 
getOperationRunnerReturns the runnable context for this document provider.- Parameters:
- monitor- the progress monitor
- Returns:
- the runnable context for this document provider
 
- 
executeOperationprotected void executeOperation(TextFileDocumentProvider.DocumentProviderOperation operation, IProgressMonitor monitor) throws CoreException Executes the given operation in the providers runnable context.- Parameters:
- operation- the operation to be executes
- monitor- the progress monitor
- Throws:
- CoreException- the operation's core exception
 
- 
connectDescription copied from interface:IDocumentProviderConnects the given element to this document provider. This tells the provider that caller of this method is interested to work with the document provided for the given domain model element. By counting the invocations of this method anddisconnect(Object)this provider can assume to know the correct number of clients working with the document provided for that domain model element.The given element must not be null.- Specified by:
- connectin interface- IDocumentProvider
- Parameters:
- element- the element
- Throws:
- CoreException- if the textual representation or the annotation model of the element could not be created
 
- 
createEmptyFileInfoCreates and returns a new and empty file info object.Subclasses which extend TextFileDocumentProvider.FileInfoshould override this method.- Returns:
- a new and empty object of type FileInfo
 
- 
createFileInfoCreates and returns the file info object for the given element.Subclasses which extend TextFileDocumentProvider.FileInfowill probably have to extend this method as well.- Parameters:
- element- the element
- Returns:
- a file info object of type FileInfoornullif none can be created
- Throws:
- CoreException- if the file info object could not successfully be created
 
- 
setUpSynchronizationSets up the synchronization for the document and the annotation mode.- Parameters:
- info- the file info
- Since:
- 3.2
 
- 
createAnnotationModelCreates and returns the annotation model for the given file.- Parameters:
- file- the file
- Returns:
- the file's annotation model or nullif none
 
- 
disconnectDescription copied from interface:IDocumentProviderDisconnects the given element from this document provider. This tells the provider that the caller of this method is no longer interested in working with the document provided for the given domain model element. By counting the invocations ofconnect(Object)and of this method this provider can assume to know the correct number of clients working with the document provided for that domain model element.The given element must not be null.- Specified by:
- disconnectin interface- IDocumentProvider
- Parameters:
- element- the element
 
- 
disposeFileInfoReleases all resources described by given element's info object.Subclasses which extend TextFileDocumentProvider.FileInfowill probably have to extend this method as well.- Parameters:
- element- the element
- info- the element's file info object
 
- 
getElementsReturns an iterator for all the elements that are connected to this file buffer.- Parameters:
- file- the file buffer
- Returns:
- an iterator for all elements connected with the given file buffer
 
- 
getDocumentDescription copied from interface:IDocumentProviderReturns the document for the given element. Usually the document contains a textual presentation of the content of the element, or is the element itself.- Specified by:
- getDocumentin interface- IDocumentProvider
- Parameters:
- element- the element, or- null
- Returns:
- the document, or nullif none
 
- 
resetDocumentDescription copied from interface:IDocumentProviderResets the given element's document to its last saved state. Element state listeners are notified both before (elementContentAboutToBeReplaced) and after (elementContentReplaced) the content is changed.- Specified by:
- resetDocumentin interface- IDocumentProvider
- Parameters:
- element- the element, or- null
- Throws:
- CoreException- if document could not be reset for the given element
 
- 
saveDocumentpublic final void saveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException Description copied from interface:IDocumentProviderSaves the given document provided for the given element.- Specified by:
- saveDocumentin interface- IDocumentProvider
- Parameters:
- monitor- a progress monitor to report progress and request cancelation
- element- the element, or- null
- document- the document
- overwrite- indicates whether overwrite should be performed while saving the given element if necessary
- Throws:
- CoreException- if document could not be stored to the given element
 
- 
createSaveOperationprotected TextFileDocumentProvider.DocumentProviderOperation createSaveOperation(Object element, IDocument document, boolean overwrite) throws CoreException - Throws:
- CoreException
 
- 
commitFileBufferprotected void commitFileBuffer(IProgressMonitor monitor, TextFileDocumentProvider.FileInfo info, boolean overwrite) throws CoreException Commits the given file info's file buffer by changing the contents of the underlying file to the contents of this file buffer. After that call,isDirtyreturnsfalseandisSynchronizedreturnstrue.- Parameters:
- monitor- the progress monitor
- info- the element's file info object
- overwrite- indicates whether the underlying file should be overwritten if it is not synchronized with the file system
- Throws:
- CoreException- if writing or accessing the underlying file fails
 
- 
createFileFromDocumentprotected void createFileFromDocument(IProgressMonitor monitor, IFile file, IDocument document) throws CoreException Creates the given file with the given document content.- Parameters:
- monitor- the progress monitor
- file- the file to be created
- document- the document to be written to the file
- Throws:
- CoreException- if the creation of the file fails
 
- 
getModificationStampDescription copied from interface:IDocumentProviderReturns the modification stamp of the given element.- Specified by:
- getModificationStampin interface- IDocumentProvider
- Parameters:
- element- the element
- Returns:
- the modification stamp of the given element
 
- 
getSynchronizationStampDescription copied from interface:IDocumentProviderReturns the time stamp of the last synchronization of the given element and its provided document.- Specified by:
- getSynchronizationStampin interface- IDocumentProvider
- Parameters:
- element- the element
- Returns:
- the synchronization stamp of the given element
 
- 
isDeletedDescription copied from interface:IDocumentProviderReturns whether the given element has been deleted.- Specified by:
- isDeletedin interface- IDocumentProvider
- Parameters:
- element- the element
- Returns:
- trueif the element has been deleted
 
- 
mustSaveDocumentDescription copied from interface:IDocumentProviderReturns whether the document provided for the given element must be saved.- Specified by:
- mustSaveDocumentin interface- IDocumentProvider
- Parameters:
- element- the element, or- null
- Returns:
- trueif the document must be saved, and- falseotherwise (including the element is- null)
 
- 
canSaveDocumentDescription copied from interface:IDocumentProviderReturns whether the document provided for the given element differs from its original state which would required that it be saved.- Specified by:
- canSaveDocumentin interface- IDocumentProvider
- Parameters:
- element- the element, or- null
- Returns:
- trueif the document can be saved, and- falseotherwise (including the element is- null)
 
- 
getAnnotationModelDescription copied from interface:IDocumentProviderReturns the annotation model for the given element.- Specified by:
- getAnnotationModelin interface- IDocumentProvider
- Parameters:
- element- the element, or- null
- Returns:
- the annotation model, or nullif none
 
- 
aboutToChangeDescription copied from interface:IDocumentProviderInforms this document provider about upcoming changes of the given element. The changes might cause change notifications specific for the type of the given element. If this provider manages a document for the given element, the document provider must not change the document because of the notifications received afteraboutToChangehas been and beforechangedis called. In this case, it is assumed that the document is already up to date, e.g., a save operation is a typical case.The concrete nature of the change notification depends on the concrete type of the given element. If the element is, e.g., an IResourcethe notification is a resource delta.- Specified by:
- aboutToChangein interface- IDocumentProvider
- Parameters:
- element- the element, or- null
 
- 
changedDescription copied from interface:IDocumentProviderInforms this document provider that the given element has been changed. All notifications have been sent out. If this provider manages a document for the given element, the document provider must from now on change the document on the receipt of change notifications. The concrete nature of the change notification depends on the concrete type of the given element. If the element is, e.g., anIResourcethe notification is a resource delta.- Specified by:
- changedin interface- IDocumentProvider
- Parameters:
- element- the element, or- null
 
- 
addElementStateListenerDescription copied from interface:IDocumentProviderAdds the given element state listener to this document provider. Has no effect if an identical listener is already registered.- Specified by:
- addElementStateListenerin interface- IDocumentProvider
- Parameters:
- listener- the listener
 
- 
removeElementStateListenerDescription copied from interface:IDocumentProviderRemoves the given element state listener from this document provider. Has no effect if an identical listener is not registered.- Specified by:
- removeElementStateListenerin interface- IDocumentProvider
- Parameters:
- listener- the listener
 
- 
isReadOnlyDescription copied from interface:IDocumentProviderExtensionReturns whether the document provider thinks that the given element is read-only. If this method returnstrue,saveDocumentcould fail. This method does not say anything about the document constructed from the given element. If the given element is not connected to this document provider, the return value 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:
- isReadOnlyin interface- IDocumentProviderExtension
- Parameters:
- element- the element
- Returns:
- trueif the given element is read-only,- falseotherwise
 
- 
isModifiableDescription 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 interface- IDocumentProviderExtension
- Parameters:
- element- the element
- Returns:
- trueif the given element is modifiable,- falseotherwise
 
- 
validateStateDescription copied from interface:IDocumentProviderExtensionValidates the state of the given element. This method may change the "real" state of the element. If using, it also updates the internal caches, so that this method may also change the results returned byisReadOnlyandisModifiable. If the given element is not connected to this document provider, the effect is undefined.- Specified by:
- validateStatein interface- IDocumentProviderExtension
- Parameters:
- element- the element
- computationContext- the context in which the computation is performed, e.g., a SWT shell
- Throws:
- CoreException- if validating fails
 
- 
isStateValidatedDescription copied from interface:IDocumentProviderExtensionReturns whether the state of the given element has been validated.- Specified by:
- isStateValidatedin interface- IDocumentProviderExtension
- Parameters:
- element- the element
- Returns:
- trueif the state has been validated
 
- 
updateStateCacheDescription copied from interface:IDocumentProviderExtensionUpdates the state cache for the given element. This method may change the result returned byisReadOnlyandisModifiable. If the given element is not connected to this document provider, the effect is undefined.- Specified by:
- updateStateCachein interface- IDocumentProviderExtension
- Parameters:
- element- the element
- Throws:
- CoreException- if validating fails
 
- 
setCanSaveDocumentDescription copied from interface:IDocumentProviderExtensionMarks the document managed for the given element as savable. I.e.canBeSaved(element)will returntrueafterwards.- Specified by:
- setCanSaveDocumentin interface- IDocumentProviderExtension
- Parameters:
- element- the element
 
- 
getStatusDescription copied from interface:IDocumentProviderExtensionReturns the status of the given element.- Specified by:
- getStatusin interface- IDocumentProviderExtension
- Parameters:
- element- the element
- Returns:
- the status of the given element
 
- 
synchronizeDescription copied from interface:IDocumentProviderExtensionSynchronizes the document provided for the given element with the given element. After that callgetSynchronizationTimeStampandgetModificationTimeStampreturn the same value.- Specified by:
- synchronizein interface- IDocumentProviderExtension
- Parameters:
- element- the element
- Throws:
- CoreException- if the synchronization could not be performed
 
- 
setProgressMonitorDescription copied from interface:IDocumentProviderExtension2Sets this providers progress monitor.- Specified by:
- setProgressMonitorin interface- IDocumentProviderExtension2
- Parameters:
- progressMonitor- the progress monitor
 
- 
getProgressMonitorDescription copied from interface:IDocumentProviderExtension2Returns this providers progress monitor.- Specified by:
- getProgressMonitorin interface- IDocumentProviderExtension2
- Returns:
- IProgressMonitor
 
- 
isSynchronizedDescription copied from interface:IDocumentProviderExtension3Returns whether the information provided for the given element is in sync with the element.- Specified by:
- isSynchronizedin interface- IDocumentProviderExtension3
- Parameters:
- element- the element
- Returns:
- trueif the information is in sync with the element,- falseotherwise
 
- 
isNotSynchronizedExceptionDescription copied from interface:IDocumentProviderExtension5Tells whether the given core exception is exactly the exception which is thrown for a non-synchronized element.- Specified by:
- isNotSynchronizedExceptionin interface- IDocumentProviderExtension5
- Parameters:
- element- the element
- ex- the core exception
- Returns:
- trueiff the given core exception is exactly the exception which is thrown for a non-synchronized element
 
- 
getDefaultEncodingDescription copied from interface:IStorageDocumentProviderReturns the default character encoding used by this provider.- Specified by:
- getDefaultEncodingin interface- IStorageDocumentProvider
- Returns:
- the default character encoding used by this provider
 
- 
getEncodingDescription copied from interface:IStorageDocumentProviderReturns the character encoding for the given element, ornullif the element is not managed by this provider.- Specified by:
- getEncodingin interface- IStorageDocumentProvider
- Parameters:
- element- the element
- Returns:
- the encoding for the given element
 
- 
setEncodingDescription copied from interface:IStorageDocumentProviderSets the encoding for the given element. Ifencodingisnullthe workbench's character encoding should be used.- Specified by:
- setEncodingin interface- IStorageDocumentProvider
- Parameters:
- element- the element
- encoding- the encoding to be used
 
- 
getContentTypeDescription 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 interface- IDocumentProviderExtension4
- Parameters:
- element- the element
- Returns:
- the content type or null
- Throws:
- CoreException- if reading or accessing the underlying store fails
 
- 
handleCoreExceptionDefines the standard procedure to handleCoreExceptions. Exceptions are written to the plug-in log.- Parameters:
- exception- the exception to be logged
- message- the message to be logged
 
- 
getFileStoreReturns the file store denoted by the given info.- Parameters:
- info- the element's file info object
- Returns:
- the IFileStorefor the given file info
- Since:
- 3.2
 
- 
getSystemFileDeprecated.As of 3.2, replaced bygetFileStore(org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)Returns the system file denoted by the given info.- Parameters:
- info- the element's file info object
- Returns:
- the system file for the given file info
 
- 
isSystemFileReadOnlyReturns whether the system file denoted by the given info is read-only.- Parameters:
- info- the element's file info object
- Returns:
- trueiff read-only
 
- 
getFileInfoReturns the file info object for the given element.- Parameters:
- element- the element
- Returns:
- the file info object, or nullif none
 
- 
getConnectedElementsIteratorReturns an iterator over the elements connected via this document provider.- Returns:
- an iterator over the list of elements
 
- 
getFileInfosIteratorReturns an iterator over this document provider's file info objects.- Returns:
- the iterator over list of file info objects
 
- 
fireElementStateChangingInforms all registered element state listeners about the current state change of the element.- Parameters:
- element- the element
- See Also:
 
- 
fireElementStateChangeFailedInforms all registered element state listeners about the failed state change of the element.- Parameters:
- element- the element
- See Also:
 
- 
computeSchedulingRuleComputes the scheduling rule needed to create or modify a resource. If the resource exists, its modify rule is returned. If it does not, the resource hierarchy is iterated towards the workspace root to find the first parent oftoCreateOrModifythat exists. Then the 'create' rule for the last non-existing resource is returned.- Parameters:
- toCreateOrModify- the resource to create or modify
- Returns:
- the minimal scheduling rule needed to modify or create a resource
- Since:
- 3.1
 
 
-