Provide access to the values that existed previous to the application of

events that change values.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1837 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-10-27 01:33:43 +00:00
parent bb489caf39
commit 76ba2840c4
3 changed files with 40 additions and 3 deletions
@@ -1,5 +1,5 @@
// //
// $Id: AttributeChangedEvent.java,v 1.12 2002/07/23 05:52:48 mdb Exp $ // $Id: AttributeChangedEvent.java,v 1.13 2002/10/27 01:33:43 mdb Exp $
package com.threerings.presents.dobj; package com.threerings.presents.dobj;
@@ -63,6 +63,15 @@ public class AttributeChangedEvent extends DEvent
return _value; return _value;
} }
/**
* Returns the value of the attribute prior to the application of this
* event.
*/
public Object getOldValue ()
{
return _oldValue;
}
/** /**
* Returns the new value of the attribute as a short. This will fail * Returns the new value of the attribute as a short. This will fail
* if the attribute in question is not a short. * if the attribute in question is not a short.
@@ -114,6 +123,8 @@ public class AttributeChangedEvent extends DEvent
public boolean applyToObject (DObject target) public boolean applyToObject (DObject target)
throws ObjectAccessException throws ObjectAccessException
{ {
// grab the previous value
_oldValue = target.getAttribute(_name);
// pass the new value on to the object // pass the new value on to the object
target.setAttribute(_name, _value); target.setAttribute(_name, _value);
return true; return true;
@@ -161,4 +172,5 @@ public class AttributeChangedEvent extends DEvent
protected String _name; protected String _name;
protected Object _value; protected Object _value;
protected transient Object _oldValue;
} }
@@ -1,5 +1,5 @@
// //
// $Id: ElementUpdatedEvent.java,v 1.2 2002/07/23 05:52:48 mdb Exp $ // $Id: ElementUpdatedEvent.java,v 1.3 2002/10/27 01:33:43 mdb Exp $
package com.threerings.presents.dobj; package com.threerings.presents.dobj;
@@ -68,6 +68,15 @@ public class ElementUpdatedEvent extends DEvent
return _value; return _value;
} }
/**
* Returns the value of the element prior to the application of this
* event.
*/
public Object getOldValue ()
{
return _oldValue;
}
/** /**
* Returns the index of the element. * Returns the index of the element.
*/ */
@@ -138,6 +147,9 @@ public class ElementUpdatedEvent extends DEvent
throw new Exception(msg); throw new Exception(msg);
} }
// grab the previous value to provide to interested parties
_oldValue = Array.get(field.get(target), _index);
// we don't do any magical expansion or any funny business; // we don't do any magical expansion or any funny business;
// the array should be big enough to contain the value being // the array should be big enough to contain the value being
// updated or we'll throw an ArrayIndexOutOfBoundsException // updated or we'll throw an ArrayIndexOutOfBoundsException
@@ -197,4 +209,5 @@ public class ElementUpdatedEvent extends DEvent
protected String _name; protected String _name;
protected Object _value; protected Object _value;
protected int _index; protected int _index;
protected transient Object _oldValue;
} }
@@ -1,5 +1,5 @@
// //
// $Id: EntryUpdatedEvent.java,v 1.7 2002/07/23 05:52:48 mdb Exp $ // $Id: EntryUpdatedEvent.java,v 1.8 2002/10/27 01:33:43 mdb Exp $
package com.threerings.presents.dobj; package com.threerings.presents.dobj;
@@ -63,6 +63,14 @@ public class EntryUpdatedEvent extends DEvent
return _entry; return _entry;
} }
/**
* Returns the entry that was in the set prior to being updated.
*/
public DSet.Entry getOldEntry ()
{
return _oldEntry;
}
/** /**
* Applies this event to the object. * Applies this event to the object.
*/ */
@@ -71,6 +79,9 @@ public class EntryUpdatedEvent extends DEvent
{ {
DSet set = (DSet)target.getAttribute(_name); DSet set = (DSet)target.getAttribute(_name);
// fetch the previous value for interested callers
_oldEntry = set.get(_entry.getKey());
// update the entry // update the entry
if (!set.update(_entry)) { if (!set.update(_entry)) {
// complain if we didn't update anything // complain if we didn't update anything
@@ -124,4 +135,5 @@ public class EntryUpdatedEvent extends DEvent
protected String _name; protected String _name;
protected DSet.Entry _entry; protected DSet.Entry _entry;
protected transient DSet.Entry _oldEntry;
} }