public abstract class AbstractDocumentProvider extends Object implements IDocumentProvider, IDocumentProviderExtension, IDocumentProviderExtension2, IDocumentProviderExtension3, IDocumentProviderExtension4, IDocumentProviderExtension5
Subclasses must implement createDocument
,
createAnnotationModel
, and doSaveDocument
.
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractDocumentProvider.DocumentProviderOperation
Operation created by the document provider and to be executed by the providers runnable context.
|
protected class |
AbstractDocumentProvider.ElementInfo
Collection of all information managed for a connected element.
|
Modifier and Type | Field and Description |
---|---|
protected static boolean |
PR10806_UC5_ENABLED
Enables a certain behavior.
|
protected static boolean |
PR14469_ENABLED
Enables a certain behavior.
|
protected static IStatus |
STATUS_ERROR
Constant for representing the error status.
|
protected static IStatus |
STATUS_OK
Deprecated.
As of 3.6, replaced by
Status.OK_STATUS |
Modifier | Constructor and Description |
---|---|
protected |
AbstractDocumentProvider()
Creates a new document provider.
|
Modifier and Type | Method and Description |
---|---|
void |
aboutToChange(Object element)
The
AbstractDocumentProvider implementation of this
IDocumentProvider method does nothing. |
void |
addElementStateListener(IElementStateListener listener)
Adds the given element state listener to this document provider.
|
protected void |
addUnchangedElementListeners(Object element,
AbstractDocumentProvider.ElementInfo info)
Called on initial creation and when the dirty state of the element
changes to
false . |
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)
The
AbstractDocumentProvider implementation of this
IDocumentProvider method does nothing. |
void |
connect(Object element)
Connects the given element to this document provider.
|
protected void |
connected()
This hook method is called when this provider starts managing documents for
elements.
|
protected abstract IAnnotationModel |
createAnnotationModel(Object element)
Creates an annotation model for the given element.
|
protected abstract IDocument |
createDocument(Object element)
Creates the document for the given element.
|
protected AbstractDocumentProvider.ElementInfo |
createElementInfo(Object element)
Creates a new element info object for the given element.
|
void |
disconnect(Object element)
Disconnects the given element from this document provider.
|
protected void |
disconnected()
This hook method is called when this provider stops managing documents for
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 abstract 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 |
doUpdateStateCache(Object element)
Hook method for updating the state of the given element.
|
protected void |
doValidateState(Object element,
Object computationContext)
Hook method for validating the state of the given element.
|
protected void |
executeOperation(AbstractDocumentProvider.DocumentProviderOperation operation,
IProgressMonitor monitor)
Executes the given operation in the providers runnable context.
|
protected void |
fireElementContentAboutToBeReplaced(Object element)
Informs all registered element state listeners about an impending
replace of the given element's content.
|
protected void |
fireElementContentReplaced(Object element)
Informs all registered element state listeners about the just-completed
replace of the given element's content.
|
protected void |
fireElementDeleted(Object element)
Informs all registered element state listeners about the deletion
of the given element.
|
protected void |
fireElementDirtyStateChanged(Object element,
boolean isDirty)
Informs all registered element state listeners about a change in the
dirty state of the given element.
|
protected void |
fireElementMoved(Object originalElement,
Object movedElement)
Informs all registered element state listeners about a move.
|
protected void |
fireElementStateChangeFailed(Object element)
Informs all registered element state listeners about the failed
state change of the element
|
protected void |
fireElementStateChanging(Object element)
Informs all registered element state listeners about the current state
change of the element
|
protected void |
fireElementStateValidationChanged(Object element,
boolean isStateValidated)
Informs all registered element state listeners about a change in the state validation of the
given element.
|
IAnnotationModel |
getAnnotationModel(Object element)
Returns the annotation model for the given element.
|
protected Iterator |
getConnectedElements()
Enumerates the elements connected via this document provider.
|
IContentType |
getContentType(Object element)
Returns the content type of for the given element or
null if none could be determined. |
IDocument |
getDocument(Object element)
Returns the document for the given element.
|
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 abstract IRunnableContext |
getOperationRunner(IProgressMonitor monitor)
Returns the runnable context for this document provider.
|
IProgressMonitor |
getProgressMonitor()
Returns this providers progress monitor.
|
protected ISchedulingRule |
getResetRule(Object element)
Returns the scheduling rule required for executing
reset on the given element. |
protected ISchedulingRule |
getSaveRule(Object element)
Returns the scheduling rule required for executing
save on the given element. |
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.
|
protected ISchedulingRule |
getSynchronizeRule(Object element)
Returns the scheduling rule required for executing
synchronize on the given element. |
protected ISchedulingRule |
getValidateStateRule(Object element)
Returns the scheduling rule required for executing
validateState on the given element. |
protected boolean |
invalidatesState(Object element,
boolean wasReadOnly)
Returns whether the state of the element must be invalidated given its
previous read-only state.
|
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
validateState has been called for the given element
since the element's state has potentially been invalidated. |
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.
|
protected void |
removeUnchangedElementListeners(Object element,
AbstractDocumentProvider.ElementInfo info)
Called when the given element gets dirty.
|
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 |
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.
|
protected static final boolean PR10806_UC5_ENABLED
true
since 3.0protected static final boolean PR14469_ENABLED
PR10806_UC5_ENABLED
.
Current value: false
since 3.0protected static final IStatus STATUS_OK
Status.OK_STATUS
protected static final IStatus STATUS_ERROR
protected AbstractDocumentProvider()
protected abstract IDocument createDocument(Object element) throws CoreException
Subclasses must implement this method.
element
- the elementCoreException
- if the document could not be createdprotected abstract IAnnotationModel createAnnotationModel(Object element) throws CoreException
Subclasses must implement this method.
element
- the elementnull
if noneCoreException
- if the annotation model could not be createdprotected abstract void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException
Subclasses must implement this method.
monitor
- a progress monitor to report progress and request cancelationelement
- the elementdocument
- the documentoverwrite
- indicates whether an overwrite should happen if necessaryCoreException
- if document could not be stored to the given elementprotected abstract IRunnableContext getOperationRunner(IProgressMonitor monitor)
monitor
- a progress monitor to track the operationprotected ISchedulingRule getSynchronizeRule(Object element)
synchronize
on the given element. This default
implementation returns null
.element
- the elementsynchronize
protected ISchedulingRule getValidateStateRule(Object element)
validateState
on the given element. This default
implementation returns null
.element
- the elementvalidateState
protected ISchedulingRule getSaveRule(Object element)
save
on the given element. This default
implementation returns null
.element
- the elementsave
protected ISchedulingRule getResetRule(Object element)
reset
on the given element. This default
implementation returns null
.element
- the elementreset
protected AbstractDocumentProvider.ElementInfo getElementInfo(Object element)
element
- the elementnull
if noneprotected AbstractDocumentProvider.ElementInfo createElementInfo(Object element) throws CoreException
This method is called from connect
when an element info needs
to be created. The AbstractDocumentProvider
implementation
of this method returns a new element info object whose document and
annotation model are the values of createDocument(element)
and createAnnotationModel(element)
, respectively. Subclasses
may override.
element
- the elementCoreException
- if the document or annotation model could not be createdprotected void disposeElementInfo(Object element, AbstractDocumentProvider.ElementInfo info)
This method is called when an element info is disposed. The
AbstractDocumentProvider
implementation of this
method does nothing. Subclasses may reimplement.
element
- the elementinfo
- the element info objectprotected void addUnchangedElementListeners(Object element, AbstractDocumentProvider.ElementInfo info)
false
. Adds all listeners which must be
active as long as the element is not dirty. This method is called
before fireElementDirtyStateChanged
or
fireElementContentReplaced
is called.
Subclasses may extend.element
- the elementinfo
- the element info objectprotected void removeUnchangedElementListeners(Object element, AbstractDocumentProvider.ElementInfo info)
fireElementDirtyStateChanged
or fireElementContentReplaced
is called.
Subclasses may extend.element
- the elementinfo
- the element info objectprotected Iterator getConnectedElements()
Object
)public final 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 createdprotected void connected()
public final 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 elementprotected void disconnected()
public IDocument getDocument(Object element)
IDocumentProvider
getDocument
in interface IDocumentProvider
element
- the element, or null
null
if nonepublic 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 IAnnotationModel getAnnotationModel(Object element)
IDocumentProvider
getAnnotationModel
in interface IDocumentProvider
element
- the element, or null
null
if nonepublic 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
)protected void doResetDocument(Object element, IProgressMonitor monitor) throws CoreException
element
- the elementmonitor
- the progress monitorCoreException
- if resetting failsprotected void executeOperation(AbstractDocumentProvider.DocumentProviderOperation operation, IProgressMonitor monitor) throws CoreException
operation
- the operation to be executesmonitor
- the progress monitorCoreException
- the operation's core exceptionpublic final 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 final 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 void aboutToChange(Object element)
AbstractDocumentProvider
implementation of this
IDocumentProvider
method does nothing. Subclasses may
reimplement.aboutToChange
in interface IDocumentProvider
element
- the elementpublic void changed(Object element)
AbstractDocumentProvider
implementation of this
IDocumentProvider
method does nothing. Subclasses may
reimplement.changed
in interface IDocumentProvider
element
- the elementpublic void addElementStateListener(IElementStateListener listener)
IDocumentProvider
addElementStateListener
in interface IDocumentProvider
listener
- the listenerpublic void removeElementStateListener(IElementStateListener listener)
IDocumentProvider
removeElementStateListener
in interface IDocumentProvider
listener
- the listenerprotected void fireElementDirtyStateChanged(Object element, boolean isDirty)
element
- the elementisDirty
- the new dirty stateIElementStateListener.elementDirtyStateChanged(Object, boolean)
protected void fireElementContentAboutToBeReplaced(Object element)
element
- the elementIElementStateListener.elementContentAboutToBeReplaced(Object)
protected void fireElementContentReplaced(Object element)
element
- the elementIElementStateListener.elementContentReplaced(Object)
protected void fireElementDeleted(Object element)
element
- the elementIElementStateListener.elementDeleted(Object)
protected void fireElementMoved(Object originalElement, Object movedElement)
originalElement
- the element before the movemovedElement
- the element after the moveIElementStateListener.elementMoved(Object, Object)
public 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 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 boolean isStateValidated(Object element)
validateState
has been called for the given element
since the element's state has potentially been invalidated.isStateValidated
in interface IDocumentProviderExtension
element
- the elementvalidateState
has been called for the given elementprotected void doValidateState(Object element, Object computationContext) throws CoreException
element
- the elementcomputationContext
- the context in which validation happensCoreException
- in case validation failspublic 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 failsprotected void doUpdateStateCache(Object element) throws CoreException
element
- the elementCoreException
- in case state cache updating failsprotected boolean invalidatesState(Object element, boolean wasReadOnly)
element
- the elementwasReadOnly
- the previous read-only statetrue
if the state of the given element must be invalidatedpublic final 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 elementprotected void fireElementStateValidationChanged(Object element, boolean isStateValidated)
element
- the elementisStateValidated
- the flag indicating whether state validation is doneIElementStateListenerExtension.elementStateValidationChanged(Object, boolean)
protected void fireElementStateChanging(Object element)
element
- the elementIElementStateListenerExtension.elementStateChanging(Object)
protected void fireElementStateChangeFailed(Object element)
element
- the elementIElementStateListenerExtension.elementStateChangeFailed(Object)
public IStatus getStatus(Object element)
IDocumentProviderExtension
getStatus
in interface IDocumentProviderExtension
element
- the elementprotected void doSynchronize(Object element, IProgressMonitor monitor) throws CoreException
element
- the elementmonitor
- the progress monitorCoreException
- in the case that synchronization failspublic final 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 IProgressMonitor getProgressMonitor()
IDocumentProviderExtension2
getProgressMonitor
in interface IDocumentProviderExtension2
public void setProgressMonitor(IProgressMonitor progressMonitor)
IDocumentProviderExtension2
setProgressMonitor
in interface IDocumentProviderExtension2
progressMonitor
- the progress monitorpublic 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
fails
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.