public class ElementChangeRecorder
extends java.lang.Object
This implementation caches locally the state of an element tree at the time
the recorder begins recording. When endRecording()
is called,
creates a delta tree over the cached state and the new state.
Clients can use this class as it stands or subclass it as circumstances warrant.
Constructor and Description |
---|
ElementChangeRecorder() |
Modifier and Type | Method and Description |
---|---|
void |
beginRecording(IElement inputElement)
Begins recording changes in the element tree rooted at the given
input element, reporting the changes to a new instance of default
delta builder.
|
void |
beginRecording(IElement inputElement,
IElementDeltaBuilder deltaBuilder)
Begins recording changes in the element tree rooted at the given
input element, reporting the changes to the given delta builder.
|
void |
beginRecording(IElement inputElement,
IElementDeltaBuilder deltaBuilder,
int maxDepth)
Begins recording changes in the element tree rooted at the given
input element for the specified maximum depth, reporting the changes
to the given delta builder.
|
IElementDeltaBuilder |
endRecording()
Ends the current recording and returns a delta builder with
the consolidated changes between the state of the element tree
at the time the recording was started and its current state.
|
protected void |
findContentChange(java.lang.Object oldBody,
java.lang.Object newBody,
IElement element)
Finds whether the given element has had a content change.
|
protected IElementDeltaBuilder |
getDeltaBuilder()
Returns the current delta builder.
|
protected IElement |
getInputElement()
Returns the current input element.
|
protected int |
getMaxDepth()
Returns the current maximum depth.
|
boolean |
isRecording()
Returns whether this change recorder is currently recording.
|
protected IElementDeltaBuilder |
newDeltaBuilder(IElement element)
Returns a new instance of default delta builder rooted at the given
element.
|
protected void |
recordBody(java.lang.Object body,
IElement element)
Remembers the given body for the given element.
|
public final boolean isRecording()
true
if this change recorder is recording,
and false
otherwisepublic final void beginRecording(IElement inputElement)
inputElement
- not null
public final void beginRecording(IElement inputElement, IElementDeltaBuilder deltaBuilder)
null
, in which case a new instance
of default delta builder rooted at the given input element will be
used.inputElement
- not null
deltaBuilder
- may be null
public void beginRecording(IElement inputElement, IElementDeltaBuilder deltaBuilder, int maxDepth)
null
,
in which case a new instance of default delta builder rooted at the
given input element will be used.inputElement
- not null
deltaBuilder
- may be null
maxDepth
- the maximum depth the recorder should look into
(>= 0)public IElementDeltaBuilder endRecording()
null
)java.lang.IllegalStateException
- if this recorder is not recordingprotected final IElement getInputElement()
protected final IElementDeltaBuilder getDeltaBuilder()
protected final int getMaxDepth()
protected IElementDeltaBuilder newDeltaBuilder(IElement element)
This implementation returns a new instance of ElementDelta.Builder
.
The root delta is created via the ElementDelta.Factory
registered
in the element's model context. If no delta factory is registered,
a new instance of ElementDelta
is used.
element
- never null
null
)protected void recordBody(java.lang.Object body, IElement element)
body
- never null
element
- never null
protected void findContentChange(java.lang.Object oldBody, java.lang.Object newBody, IElement element)
Implementations can compare the given bodies and, if there are
differences (excepting children), insert an appropriate change delta
(such as F_CONTENT
) for the given element into the delta
tree being built. Implementations should not take changes in children
into account.
This implementation invokes ((Body)newBody).
.
findContentChange
((Body)oldBody, element, getDeltaBuilder())
oldBody
- the old version of the element's body (never null
)newBody
- the new version of the element's body (never null
)element
- the element whose bodies are to be compared (never null
)Copyright (c) 2014, 2018 1C-Soft LLC and others. Made available under the Eclipse Public License 2.0