Implement ElementUpdateListener for ObjectRecord so calls to set*At on arrays on ConfigObjects update the config db as well as set*
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4745 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -27,6 +27,8 @@ import java.lang.reflect.Field;
|
|||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.swing.JEditorPane;
|
||||||
|
|
||||||
import com.samskivert.io.ByteArrayOutInputStream;
|
import com.samskivert.io.ByteArrayOutInputStream;
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
@@ -39,6 +41,8 @@ import com.threerings.presents.dobj.AttributeChangeListener;
|
|||||||
import com.threerings.presents.dobj.AttributeChangedEvent;
|
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||||
import com.threerings.presents.dobj.DObject;
|
import com.threerings.presents.dobj.DObject;
|
||||||
import com.threerings.presents.dobj.DSet;
|
import com.threerings.presents.dobj.DSet;
|
||||||
|
import com.threerings.presents.dobj.ElementUpdateListener;
|
||||||
|
import com.threerings.presents.dobj.ElementUpdatedEvent;
|
||||||
import com.threerings.presents.dobj.EntryAddedEvent;
|
import com.threerings.presents.dobj.EntryAddedEvent;
|
||||||
import com.threerings.presents.dobj.EntryRemovedEvent;
|
import com.threerings.presents.dobj.EntryRemovedEvent;
|
||||||
import com.threerings.presents.dobj.EntryUpdatedEvent;
|
import com.threerings.presents.dobj.EntryUpdatedEvent;
|
||||||
@@ -122,7 +126,7 @@ public abstract class ConfigRegistry
|
|||||||
* Contains all necessary info for a configuration object registration.
|
* Contains all necessary info for a configuration object registration.
|
||||||
*/
|
*/
|
||||||
protected abstract class ObjectRecord
|
protected abstract class ObjectRecord
|
||||||
implements AttributeChangeListener, SetListener
|
implements AttributeChangeListener, SetListener, ElementUpdateListener
|
||||||
{
|
{
|
||||||
public DObject object;
|
public DObject object;
|
||||||
|
|
||||||
@@ -172,11 +176,33 @@ public abstract class ConfigRegistry
|
|||||||
serializeAttribute(event.getName());
|
serializeAttribute(event.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void elementUpdated (ElementUpdatedEvent event)
|
||||||
|
{
|
||||||
|
Object value;
|
||||||
|
try {
|
||||||
|
value = object.getAttribute(event.getName());
|
||||||
|
} catch (ObjectAccessException oae) {
|
||||||
|
Log.warning("Exception getting field [name=" + event.getName() + "exception=" +
|
||||||
|
oae + "].");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateValue(event.getName(), value);
|
||||||
|
}
|
||||||
|
|
||||||
public void attributeChanged (AttributeChangedEvent event)
|
public void attributeChanged (AttributeChangedEvent event)
|
||||||
{
|
{
|
||||||
// mirror this configuration update to the persistent config
|
// mirror this configuration update to the persistent config
|
||||||
String key = nameToKey(event.getName());
|
|
||||||
Object value = event.getValue();
|
Object value = event.getValue();
|
||||||
|
if (value instanceof DSet) {
|
||||||
|
serializeAttribute(event.getName());
|
||||||
|
} else {
|
||||||
|
updateValue(event.getName(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateValue (String name, Object value)
|
||||||
|
{
|
||||||
|
String key = nameToKey(name);
|
||||||
if (value instanceof Boolean) {
|
if (value instanceof Boolean) {
|
||||||
setValue(key, ((Boolean)value).booleanValue());
|
setValue(key, ((Boolean)value).booleanValue());
|
||||||
} else if (value instanceof Short) {
|
} else if (value instanceof Short) {
|
||||||
@@ -197,8 +223,6 @@ public abstract class ConfigRegistry
|
|||||||
setValue(key, (String[])value);
|
setValue(key, (String[])value);
|
||||||
} else if (value instanceof long[]) {
|
} else if (value instanceof long[]) {
|
||||||
setValue(key, (long[]) value);
|
setValue(key, (long[]) value);
|
||||||
} else if (value instanceof DSet) {
|
|
||||||
serializeAttribute(event.getName());
|
|
||||||
} else {
|
} else {
|
||||||
Log.info("Unable to flush config object change " +
|
Log.info("Unable to flush config object change " +
|
||||||
"[cobj=" + object.getClass().getName() +
|
"[cobj=" + object.getClass().getName() +
|
||||||
|
|||||||
Reference in New Issue
Block a user