Class ForwardingDocumentProvider
- All Implemented Interfaces:
IStorageDocumentProvider,IDocumentProvider,IDocumentProviderExtension,IDocumentProviderExtension2,IDocumentProviderExtension3,IDocumentProviderExtension4,IDocumentProviderExtension5
This document provider should be used by editors that directly or indirectly
work with a TextFileDocumentProvider and do not
accept that they may be provided with documents which do not contain the partitioning
they work on. This can happen either because of a plug-in configuration error
or when a user associates a file name or file extension with an existing text
editor and the file buffer infrastructure does not recognize that file name
or file extension to be of the same file type the editor works on. Thus, the
document provided for the files with that name or extension may not be set up
in the way the editor expects it. The ForwardingDocumentProvider
compensates for that situation.
Editors that directly work with a TextFileDocumentProvider can
now use a ForwardingDocumentProvider instead and configure a
TextFileDocumentProvider as its parent provider. Editors that
indirectly work with a TextFileDocumentProvider, e.g. never
set a document provider explicitly, should explicitly set a
ForwardingDocumentProvider as document provider. In this case
the forwarding document provider may not be shared between editors.
- Since:
- 3.0
-
Constructor Summary
ConstructorsConstructorDescriptionForwardingDocumentProvider(String partitioning, IDocumentSetupParticipant documentSetupParticipant) Creates a new forwarding document provider with a dynamically changeable parent provider.ForwardingDocumentProvider(String partitioning, IDocumentSetupParticipant documentSetupParticipant, IDocumentProvider parentProvider) Creates a new forwarding document provider with a fixed parent document provider. -
Method Summary
Modifier 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.voidConnects the given element to this document provider.voiddisconnect(Object element) Disconnects the given element from this document provider.getAnnotationModel(Object element) Returns the annotation model for the given element.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.getEncoding(Object element) Returns the character encoding for the given element, ornullif the element is not managed by this provider.longgetModificationStamp(Object element) Returns the modification stamp of the given element.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.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.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.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.voidsetParentProvider(IDocumentProvider parentProvider) Sets the parent document provider.voidsetProgressMonitor(IProgressMonitor progressMonitor) Sets this providers progress monitor.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
-
ForwardingDocumentProvider
public ForwardingDocumentProvider(String partitioning, IDocumentSetupParticipant documentSetupParticipant, IDocumentProvider parentProvider) Creates a new forwarding document provider with a fixed parent document provider. CallingsetParentProvider(IDocumentProvider)does not have any effect on this object.- Parameters:
partitioning- the partitioningdocumentSetupParticipant- the document setup participantparentProvider- the parent document provider
-
ForwardingDocumentProvider
public ForwardingDocumentProvider(String partitioning, IDocumentSetupParticipant documentSetupParticipant) Creates a new forwarding document provider with a dynamically changeable parent provider. Forwarding document providers created with that method are not allowed to be shared by multiple editors.- Parameters:
partitioning- the partitioningdocumentSetupParticipant- the document setup participant
-
-
Method Details
-
setParentProvider
Sets the parent document provider. This method has only an effect if the forwarding document provider has accordingly be created.- Parameters:
parentProvider- the new parent document provider
-
connect
Description 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 interfaceIDocumentProvider- Parameters:
element- the element- Throws:
CoreException- if the textual representation or the annotation model of the element could not be created
-
disconnect
Description 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 interfaceIDocumentProvider- Parameters:
element- the element
-
getDocument
Description 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 interfaceIDocumentProvider- Parameters:
element- the element, ornull- Returns:
- the document, or
nullif none
-
resetDocument
Description 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 interfaceIDocumentProvider- Parameters:
element- the element, ornull- Throws:
CoreException- if document could not be reset for the given element
-
saveDocument
public 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 interfaceIDocumentProvider- Parameters:
monitor- a progress monitor to report progress and request cancelationelement- the element, ornulldocument- the documentoverwrite- 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
-
getModificationStamp
Description copied from interface:IDocumentProviderReturns the modification stamp of the given element.- Specified by:
getModificationStampin interfaceIDocumentProvider- Parameters:
element- the element- Returns:
- the modification stamp of the given element
-
getSynchronizationStamp
Description copied from interface:IDocumentProviderReturns the time stamp of the last synchronization of the given element and its provided document.- Specified by:
getSynchronizationStampin interfaceIDocumentProvider- Parameters:
element- the element- Returns:
- the synchronization stamp of the given element
-
isDeleted
Description copied from interface:IDocumentProviderReturns whether the given element has been deleted.- Specified by:
isDeletedin interfaceIDocumentProvider- Parameters:
element- the element- Returns:
trueif the element has been deleted
-
mustSaveDocument
Description copied from interface:IDocumentProviderReturns whether the document provided for the given element must be saved.- Specified by:
mustSaveDocumentin interfaceIDocumentProvider- Parameters:
element- the element, ornull- Returns:
trueif the document must be saved, andfalseotherwise (including the element isnull)
-
canSaveDocument
Description 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 interfaceIDocumentProvider- Parameters:
element- the element, ornull- Returns:
trueif the document can be saved, andfalseotherwise (including the element isnull)
-
getAnnotationModel
Description copied from interface:IDocumentProviderReturns the annotation model for the given element.- Specified by:
getAnnotationModelin interfaceIDocumentProvider- Parameters:
element- the element, ornull- Returns:
- the annotation model, or
nullif none
-
aboutToChange
Description 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 interfaceIDocumentProvider- Parameters:
element- the element, ornull
-
changed
Description 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 interfaceIDocumentProvider- Parameters:
element- the element, ornull
-
addElementStateListener
Description 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 interfaceIDocumentProvider- Parameters:
listener- the listener
-
removeElementStateListener
Description 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 interfaceIDocumentProvider- Parameters:
listener- the listener
-
isReadOnly
Description 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 interfaceIDocumentProviderExtension- Parameters:
element- the element- Returns:
trueif the given element is read-only,falseotherwise
-
isModifiable
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- Parameters:
element- the element- Returns:
trueif the given element is modifiable,falseotherwise
-
validateState
Description 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 interfaceIDocumentProviderExtension- Parameters:
element- the elementcomputationContext- the context in which the computation is performed, e.g., a SWT shell- Throws:
CoreException- if validating fails
-
isStateValidated
Description copied from interface:IDocumentProviderExtensionReturns whether the state of the given element has been validated.- Specified by:
isStateValidatedin interfaceIDocumentProviderExtension- Parameters:
element- the element- Returns:
trueif the state has been validated
-
updateStateCache
Description 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 interfaceIDocumentProviderExtension- Parameters:
element- the element- Throws:
CoreException- if validating fails
-
setCanSaveDocument
Description copied from interface:IDocumentProviderExtensionMarks the document managed for the given element as savable. I.e.canBeSaved(element)will returntrueafterwards.- Specified by:
setCanSaveDocumentin interfaceIDocumentProviderExtension- Parameters:
element- the element
-
getStatus
Description copied from interface:IDocumentProviderExtensionReturns the status of the given element.- Specified by:
getStatusin interfaceIDocumentProviderExtension- Parameters:
element- the element- Returns:
- the status of the given element
-
synchronize
Description copied from interface:IDocumentProviderExtensionSynchronizes the document provided for the given element with the given element. After that callgetSynchronizationTimeStampandgetModificationTimeStampreturn the same value.- Specified by:
synchronizein interfaceIDocumentProviderExtension- Parameters:
element- the element- Throws:
CoreException- if the synchronization could not be performed
-
setProgressMonitor
Description copied from interface:IDocumentProviderExtension2Sets this providers progress monitor.- Specified by:
setProgressMonitorin interfaceIDocumentProviderExtension2- Parameters:
progressMonitor- the progress monitor
-
getProgressMonitor
Description copied from interface:IDocumentProviderExtension2Returns this providers progress monitor.- Specified by:
getProgressMonitorin interfaceIDocumentProviderExtension2- Returns:
- IProgressMonitor
-
isSynchronized
Description copied from interface:IDocumentProviderExtension3Returns whether the information provided for the given element is in sync with the element.- Specified by:
isSynchronizedin interfaceIDocumentProviderExtension3- Parameters:
element- the element- Returns:
trueif the information is in sync with the element,falseotherwise
-
isNotSynchronizedException
Description copied from interface:IDocumentProviderExtension5Tells whether the given core exception is exactly the exception which is thrown for a non-synchronized element.- Specified by:
isNotSynchronizedExceptionin interfaceIDocumentProviderExtension5- Parameters:
element- the elementex- the core exception- Returns:
trueiff the given core exception is exactly the exception which is thrown for a non-synchronized element
-
getContentType
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- Parameters:
element- the element- Returns:
- the content type or
null - Throws:
CoreException- if reading or accessing the underlying store fails
-
getDefaultEncoding
Description copied from interface:IStorageDocumentProviderReturns the default character encoding used by this provider.- Specified by:
getDefaultEncodingin interfaceIStorageDocumentProvider- Returns:
- the default character encoding used by this provider
-
getEncoding
Description copied from interface:IStorageDocumentProviderReturns the character encoding for the given element, ornullif the element is not managed by this provider.- Specified by:
getEncodingin interfaceIStorageDocumentProvider- Parameters:
element- the element- Returns:
- the encoding for the given element
-
setEncoding
Description copied from interface:IStorageDocumentProviderSets the encoding for the given element. Ifencodingisnullthe workbench's character encoding should be used.- Specified by:
setEncodingin interfaceIStorageDocumentProvider- Parameters:
element- the elementencoding- the encoding to be used
-