org.eclipse.emf.ecore.change.util
Class ChangeRecorder

java.lang.Object
  extended byorg.eclipse.emf.ecore.change.util.ChangeRecorder
All Implemented Interfaces:
Adapter, Adapter.Internal

public class ChangeRecorder
extends Object
implements Adapter.Internal

A change recorder for the tree contents of a collection of EObjects. It monitors the specified objects and then produces a change model representing the changes needed to reverse (undo) all the model changes made while recording.


Nested Class Summary
 
Nested classes inherited from class org.eclipse.emf.common.notify.Adapter
Adapter.Internal
 
Field Summary
protected  ChangeDescription changeDescription
           
protected  boolean loadingTargets
           
protected  List originalTargetObjects
           
protected  boolean recording
           
protected  boolean resolveProxies
           
protected  List targetObjects
           
 
Constructor Summary
ChangeRecorder()
           
ChangeRecorder(Collection rootObjects)
           
ChangeRecorder(EObject rootObject)
           
ChangeRecorder(Resource resource)
           
ChangeRecorder(ResourceSet resourceSet)
           
 
Method Summary
protected  void addAdapter(Notifier notifier)
           
 void beginRecording(ChangeDescription changeDescription, Collection rootObjects)
          Begins recording any changes made to the elements of the specifed collection, adding the changes to and existing ChangeDescription.
 void beginRecording(Collection rootObjects)
          Begins recording any changes made to the elements of the specifed collection.
protected  void consolidateChanges()
          Consolidates the changes that have happen since the last consolidation.
protected  void createAddListChange(EList oldList, EList changesList, Object newObject, int index)
          Convenience method added to allow subclasses to modify the default implementation for the scenario in which an element was added to the monitored list.
protected  ChangeDescription createChangeDescription()
           
protected  FeatureChange createFeatureChange(EObject eObject, EStructuralFeature eStructuralFeature, Object value, boolean isSet)
           
protected  ListChange createListChange(EList changesList, ChangeKind kind, int index)
           
protected  void createListChanges(EList oldList, EList newList, EList changesList)
           
protected  void createMoveListChange(EList oldList, EList changesList, Object newObject, int index, int toIndex)
          Convenience method added to allow subclasses to modify the default implementation for the scenario in which an element was moved in the monitored list.
protected  void createRemoveListChange(EList oldList, EList changesList, Object newObject, int index)
          Convenience method added to allow subclasses to modify the default implementation for the scenario in which an element was removed from the monitored list.
protected  ResourceChange createResourceChange(Resource resource, EList value)
           
 void dispose()
          Disposes this change recorder by detaching it from its targets, clearing the collections attributes and setting the internal reference to the change description to null.
 ChangeDescription endRecording()
          Ends the recording.
protected  void finalizeChange(FeatureChange change, EObject eObject)
           
protected  void finalizeChange(ResourceChange change)
           
protected  FeatureChange getFeatureChange(List featureChanges, EStructuralFeature eStructuralFeature)
           
protected  List getFeatureChanges(EObject eObject)
           
protected  ResourceChange getResourceChange(Resource resource)
           
protected  EList getResourceChanges()
           
 Notifier getTarget()
          Returns the target from which the adapter receives notification.
protected  void handleFeature(EStructuralFeature feature, EReference containment, Notification notification, EObject eObject)
           
protected  void handleResource(Notification notification)
           
 boolean isAdapterForType(Object type)
          Returns whether the adapter is of the given type.
 boolean isRecording()
           
 boolean isResolveProxies()
           
 void notifyChanged(Notification notification)
          Notifies that a change to some feature has occurred.
protected  void prepareChangeDescriptionForResume()
          Prepares this ChangeRecorder's changeDescription for the scenarios where the user is resumming a previous recording.
protected  void removeAdapter(Notifier notifier)
           
 void setResolveProxies(boolean resolveProxies)
           
 void setTarget(Notifier target)
          Handles installation of the adapter by adding the adapter to each of the directly contained objects.
 ChangeDescription summarize()
          Summarizes the changes made to the analysed objects on the change description returned by the endRecording() without ending the recording.
 void unsetTarget(Notifier oldTarget)
          Unsets the target from which the adapter will receive notification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

recording

protected boolean recording

changeDescription

protected ChangeDescription changeDescription

targetObjects

protected List targetObjects

originalTargetObjects

protected List originalTargetObjects

loadingTargets

protected boolean loadingTargets

resolveProxies

protected boolean resolveProxies
Constructor Detail

ChangeRecorder

public ChangeRecorder()

ChangeRecorder

public ChangeRecorder(EObject rootObject)

ChangeRecorder

public ChangeRecorder(Resource resource)

ChangeRecorder

public ChangeRecorder(ResourceSet resourceSet)

ChangeRecorder

public ChangeRecorder(Collection rootObjects)
Method Detail

isRecording

public boolean isRecording()
Returns:
true if this change recorder is recording or false otherwise.

isResolveProxies

public boolean isResolveProxies()

setResolveProxies

public void setResolveProxies(boolean resolveProxies)

dispose

public void dispose()
Disposes this change recorder by detaching it from its targets, clearing the collections attributes and setting the internal reference to the change description to null.

This method ends a recording without consolidating the changes.


removeAdapter

protected void removeAdapter(Notifier notifier)

beginRecording

public void beginRecording(Collection rootObjects)
Begins recording any changes made to the elements of the specifed collection.

Parameters:
rootObjects - A collecion of instances of Notifier

beginRecording

public void beginRecording(ChangeDescription changeDescription,
                           Collection rootObjects)
Begins recording any changes made to the elements of the specifed collection, adding the changes to and existing ChangeDescription. This allows clients to resume a previous recording.

Unpredictable (and probably bad) results may happen if the change descrition is inconsistent with the current state of the application.

Parameters:
changeDescription - A change description with changes made during a previous recording or null if a new change description should be instantiated.
rootObjects - A collecion of instances of Notifier
Since:
2.1.0

summarize

public ChangeDescription summarize()
Summarizes the changes made to the analysed objects on the change description returned by the endRecording() without ending the recording.

This method doesn't do anything if this ChangeRecorder is not recording.

Returns:
the ChangeDescription or null if there is nothing being recorded.

endRecording

public ChangeDescription endRecording()
Ends the recording.

Returns:
the ChangeDescription or null if there is nothing being recorded.

prepareChangeDescriptionForResume

protected void prepareChangeDescriptionForResume()
Prepares this ChangeRecorder's changeDescription for the scenarios where the user is resumming a previous recording.

Since:
2.1.0
See Also:
beginRecording(ChangeDescription, Collection)

consolidateChanges

protected void consolidateChanges()
Consolidates the changes that have happen since the last consolidation.


notifyChanged

public void notifyChanged(Notification notification)
Description copied from interface: Adapter
Notifies that a change to some feature has occurred.

Specified by:
notifyChanged in interface Adapter
Parameters:
notification - a description of the change.

handleFeature

protected void handleFeature(EStructuralFeature feature,
                             EReference containment,
                             Notification notification,
                             EObject eObject)

handleResource

protected void handleResource(Notification notification)

setTarget

public void setTarget(Notifier target)
Handles installation of the adapter by adding the adapter to each of the directly contained objects.

Specified by:
setTarget in interface Adapter
Parameters:
target - the new notifier.
See Also:
Adapter.getTarget()

unsetTarget

public void unsetTarget(Notifier oldTarget)
Description copied from interface: Adapter.Internal
Unsets the target from which the adapter will receive notification. This method is only to be called by a notifier when this adapter is removed from its adapter list. In general, an adapter may be shared by more than one notifier, so this mechanism allows the adapter to know specifically which notifier will no longer be notifying.

Specified by:
unsetTarget in interface Adapter.Internal
Parameters:
oldTarget - the old notifier.
See Also:
Adapter.getTarget(), Adapter.setTarget(org.eclipse.emf.common.notify.Notifier)

addAdapter

protected void addAdapter(Notifier notifier)

getTarget

public Notifier getTarget()
Description copied from interface: Adapter
Returns the target from which the adapter receives notification. In general, an adapter may be shared by more than one notifier.

Specified by:
getTarget in interface Adapter
Returns:
the target notifier.
See Also:
Adapter.setTarget(org.eclipse.emf.common.notify.Notifier)

isAdapterForType

public boolean isAdapterForType(Object type)
Description copied from interface: Adapter
Returns whether the adapter is of the given type. In general, an adapter may be the adapter for many types.

Specified by:
isAdapterForType in interface Adapter
Parameters:
type - the type.
Returns:
whether the adapter is of the given type.
See Also:
AdapterFactory.isFactoryForType(java.lang.Object)

getResourceChanges

protected EList getResourceChanges()

getResourceChange

protected ResourceChange getResourceChange(Resource resource)

getFeatureChanges

protected List getFeatureChanges(EObject eObject)

getFeatureChange

protected FeatureChange getFeatureChange(List featureChanges,
                                         EStructuralFeature eStructuralFeature)

finalizeChange

protected void finalizeChange(ResourceChange change)

finalizeChange

protected void finalizeChange(FeatureChange change,
                              EObject eObject)

createListChanges

protected void createListChanges(EList oldList,
                                 EList newList,
                                 EList changesList)

createAddListChange

protected void createAddListChange(EList oldList,
                                   EList changesList,
                                   Object newObject,
                                   int index)
Convenience method added to allow subclasses to modify the default implementation for the scenario in which an element was added to the monitored list.

See Also:
createListChanges(EList, EList, EList)

createRemoveListChange

protected void createRemoveListChange(EList oldList,
                                      EList changesList,
                                      Object newObject,
                                      int index)
Convenience method added to allow subclasses to modify the default implementation for the scenario in which an element was removed from the monitored list.

See Also:
createListChanges(EList, EList, EList)

createMoveListChange

protected void createMoveListChange(EList oldList,
                                    EList changesList,
                                    Object newObject,
                                    int index,
                                    int toIndex)
Convenience method added to allow subclasses to modify the default implementation for the scenario in which an element was moved in the monitored list.

See Also:
createListChanges(EList, EList, EList)

createListChange

protected ListChange createListChange(EList changesList,
                                      ChangeKind kind,
                                      int index)

createFeatureChange

protected FeatureChange createFeatureChange(EObject eObject,
                                            EStructuralFeature eStructuralFeature,
                                            Object value,
                                            boolean isSet)

createResourceChange

protected ResourceChange createResourceChange(Resource resource,
                                              EList value)

createChangeDescription

protected ChangeDescription createChangeDescription()

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.