public class ForwardingDocumentProvider extends Object implements IDocumentProvider, IDocumentProviderExtension, IDocumentProviderExtension2, IDocumentProviderExtension3, IDocumentProviderExtension4, IDocumentProviderExtension5, IStorageDocumentProvider
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.
Constructor and Description |
---|
ForwardingDocumentProvider(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.
|
Modifier and Type | Method and Description |
---|---|
void |
aboutToChange(Object element)
Informs this document provider about upcoming changes of the given element.
|
void |
addElementStateListener(IElementStateListener listener)
Adds the given element state listener to this document provider.
|
boolean |
canSaveDocument(Object element)
Returns whether the document provided for the given element differs from
its original state which would required that it be saved.
|
void |
changed(Object element)
Informs this document provider that the given element has been changed.
|
void |
connect(Object element)
Connects the given element to this document provider.
|
void |
disconnect(Object element)
Disconnects the given element from this document provider.
|
IAnnotationModel |
getAnnotationModel(Object element)
Returns the annotation model for the given element.
|
IContentType |
getContentType(Object element)
Returns the content type of for the given element or
null if none could be determined. |
String |
getDefaultEncoding()
Returns the default character encoding used by this provider.
|
IDocument |
getDocument(Object element)
Returns the document for the given element.
|
String |
getEncoding(Object element)
Returns the character encoding for the given element, or
null if the element is not managed by this provider. |
long |
getModificationStamp(Object element)
Returns the modification stamp of the given element.
|
IProgressMonitor |
getProgressMonitor()
Returns this providers progress monitor.
|
IStatus |
getStatus(Object element)
Returns the status of the given element.
|
long |
getSynchronizationStamp(Object element)
Returns the time stamp of the last synchronization of the given element and its provided
document.
|
boolean |
isDeleted(Object element)
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 |
isNotSynchronizedException(Object element,
CoreException ex)
Tells whether the given core exception is exactly the
exception which is thrown for a non-synchronized element.
|
boolean |
isReadOnly(Object element)
Returns whether the document provider thinks that the given element is read-only.
|
boolean |
isStateValidated(Object element)
Returns whether the state of the given element has been validated.
|
boolean |
isSynchronized(Object element)
Returns whether the information provided for the given element is in sync with the element.
|
boolean |
mustSaveDocument(Object element)
Returns whether the document provided for the given element must be saved.
|
void |
removeElementStateListener(IElementStateListener listener)
Removes the given element state listener from this document provider.
|
void |
resetDocument(Object element)
Resets the given element's document to its last saved state.
|
void |
saveDocument(IProgressMonitor monitor,
Object element,
IDocument document,
boolean overwrite)
Saves the given document provided for the given element.
|
void |
setCanSaveDocument(Object element)
Marks the document managed for the given element as savable.
|
void |
setEncoding(Object element,
String encoding)
Sets the encoding for the given element.
|
void |
setParentProvider(IDocumentProvider parentProvider)
Sets the parent document provider.
|
void |
setProgressMonitor(IProgressMonitor progressMonitor)
Sets this providers progress monitor.
|
void |
synchronize(Object element)
Synchronizes the document provided for the given element with the
given element.
|
void |
updateStateCache(Object element)
Updates the state cache for the given element.
|
void |
validateState(Object element,
Object computationContext)
Validates the state of the given element.
|
public ForwardingDocumentProvider(String partitioning, IDocumentSetupParticipant documentSetupParticipant, IDocumentProvider parentProvider)
setParentProvider(IDocumentProvider)
does not have any effect on this object.partitioning
- the partitioningdocumentSetupParticipant
- the document setup participantparentProvider
- the parent document providerpublic ForwardingDocumentProvider(String partitioning, IDocumentSetupParticipant documentSetupParticipant)
partitioning
- the partitioningdocumentSetupParticipant
- the document setup participantpublic void setParentProvider(IDocumentProvider parentProvider)
parentProvider
- the new parent document providerpublic void connect(Object element) throws CoreException
IDocumentProvider
disconnect(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
.
connect
in interface IDocumentProvider
element
- the elementCoreException
- if the textual representation or the annotation model
of the element could not be createdpublic void disconnect(Object element)
IDocumentProvider
connect(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
.
disconnect
in interface IDocumentProvider
element
- the elementpublic IDocument getDocument(Object element)
IDocumentProvider
getDocument
in interface IDocumentProvider
element
- the element, or null
null
if nonepublic void resetDocument(Object element) throws CoreException
IDocumentProvider
elementContentAboutToBeReplaced
)
and after (elementContentReplaced
) the content is changed.resetDocument
in interface IDocumentProvider
element
- the element, or null
CoreException
- if document could not be reset for the given elementpublic void saveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException
IDocumentProvider
saveDocument
in interface IDocumentProvider
monitor
- a progress monitor to report progress and request cancelationelement
- the element, or null
document
- the documentoverwrite
- indicates whether overwrite should be performed
while saving the given element if necessaryCoreException
- if document could not be stored to the given elementpublic long getModificationStamp(Object element)
IDocumentProvider
getModificationStamp
in interface IDocumentProvider
element
- the elementpublic long getSynchronizationStamp(Object element)
IDocumentProvider
getSynchronizationStamp
in interface IDocumentProvider
element
- the elementpublic boolean isDeleted(Object element)
IDocumentProvider
isDeleted
in interface IDocumentProvider
element
- the elementtrue
if the element has been deletedpublic boolean mustSaveDocument(Object element)
IDocumentProvider
mustSaveDocument
in interface IDocumentProvider
element
- the element, or null
true
if the document must be saved, and
false
otherwise (including the element is null
)public boolean canSaveDocument(Object element)
IDocumentProvider
canSaveDocument
in interface IDocumentProvider
element
- the element, or null
true
if the document can be saved, and
false
otherwise (including the element is null
)public IAnnotationModel getAnnotationModel(Object element)
IDocumentProvider
getAnnotationModel
in interface IDocumentProvider
element
- the element, or null
null
if nonepublic void aboutToChange(Object element)
IDocumentProvider
aboutToChange
has been and before changed
is 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 IResource
the notification
is a resource delta.
aboutToChange
in interface IDocumentProvider
element
- the element, or null
public void changed(Object element)
IDocumentProvider
IResource
the notification is a resource delta.changed
in interface IDocumentProvider
element
- the element, or null
public void addElementStateListener(IElementStateListener listener)
IDocumentProvider
addElementStateListener
in interface IDocumentProvider
listener
- the listenerpublic void removeElementStateListener(IElementStateListener listener)
IDocumentProvider
removeElementStateListener
in interface IDocumentProvider
listener
- the listenerpublic boolean isReadOnly(Object element)
IDocumentProviderExtension
true
, saveDocument
could 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.isReadOnly
in interface IDocumentProviderExtension
element
- the elementtrue
if the given element is read-only, false
otherwisepublic boolean isModifiable(Object element)
IDocumentProviderExtension
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.isModifiable
in interface IDocumentProviderExtension
element
- the elementtrue
if the given element is modifiable, false
otherwisepublic void validateState(Object element, Object computationContext) throws CoreException
IDocumentProviderExtension
isReadOnly
and isModifiable
. If the
given element is not connected to this document provider, the effect is undefined.validateState
in interface IDocumentProviderExtension
element
- the elementcomputationContext
- the context in which the computation is performed, e.g., a SWT shellCoreException
- if validating failspublic boolean isStateValidated(Object element)
IDocumentProviderExtension
isStateValidated
in interface IDocumentProviderExtension
element
- the elementtrue
if the state has been validatedpublic void updateStateCache(Object element) throws CoreException
IDocumentProviderExtension
isReadOnly
and isModifiable
. If the given element is not
connected to this document provider, the effect is undefined.updateStateCache
in interface IDocumentProviderExtension
element
- the elementCoreException
- if validating failspublic void setCanSaveDocument(Object element)
IDocumentProviderExtension
canBeSaved(element)
will return true
afterwards.setCanSaveDocument
in interface IDocumentProviderExtension
element
- the elementpublic IStatus getStatus(Object element)
IDocumentProviderExtension
getStatus
in interface IDocumentProviderExtension
element
- the elementpublic void synchronize(Object element) throws CoreException
IDocumentProviderExtension
getSynchronizationTimeStamp
and getModificationTimeStamp
return the same value.synchronize
in interface IDocumentProviderExtension
element
- the elementCoreException
- if the synchronization could not be performedpublic void setProgressMonitor(IProgressMonitor progressMonitor)
IDocumentProviderExtension2
setProgressMonitor
in interface IDocumentProviderExtension2
progressMonitor
- the progress monitorpublic IProgressMonitor getProgressMonitor()
IDocumentProviderExtension2
getProgressMonitor
in interface IDocumentProviderExtension2
public boolean isSynchronized(Object element)
IDocumentProviderExtension3
isSynchronized
in interface IDocumentProviderExtension3
element
- the elementtrue
if the information is in sync with the element, false
otherwisepublic boolean isNotSynchronizedException(Object element, CoreException ex)
IDocumentProviderExtension5
isNotSynchronizedException
in interface IDocumentProviderExtension5
element
- the elementex
- the core exceptiontrue
iff the given core exception is exactly the
exception which is thrown for a non-synchronized elementpublic IContentType getContentType(Object element) throws CoreException
IDocumentProviderExtension4
null
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.getContentType
in interface IDocumentProviderExtension4
element
- the elementnull
CoreException
- if reading or accessing the underlying store
failspublic String getDefaultEncoding()
IStorageDocumentProvider
getDefaultEncoding
in interface IStorageDocumentProvider
public String getEncoding(Object element)
IStorageDocumentProvider
null
if the element is not managed by this provider.getEncoding
in interface IStorageDocumentProvider
element
- the elementpublic void setEncoding(Object element, String encoding)
IStorageDocumentProvider
encoding
is null
the workbench's character encoding should be used.setEncoding
in interface IStorageDocumentProvider
element
- the elementencoding
- the encoding to be used
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.