void run(ContentNode node) {
if (!isActive()) {
log("Element change event in removed node: ignoring.");
return;
}
StateMap oldState = StateMap.create();
oldState.copyFrom(state);
final StateMap oldPrefs = StateMap.create();
oldPrefs.copyFrom(userPrefs);
processChange(node);
if (!state.compare(oldState)) {
gadgetStateSubmitter.submit();
}
// TODO(user): Optimize prefs updates.
if (!userPrefs.compare(oldPrefs)) {
userPrefs.each(new StateMap.Each() {
@Override
public void apply(String key, String value) {
if (!oldPrefs.has(key) || !value.equals(oldPrefs.get(key))) {
setGadgetPref(key, value);
}
}
});
}