handleMasterMapChange(initMasterDiff);
}
private void handleMasterMapChange(MapDiff diff) {
// Collect the detail values for the master values in the input diff.
IdentityMap oldValues = new IdentityMap();
IdentityMap newValues = new IdentityMap();
// Handle added master values.
Set addedKeys = diff.getAddedKeys();
for (Iterator iter = addedKeys.iterator(); iter.hasNext();) {
Object addedKey = iter.next();
// For added master values, we set up a new detail observable.
addDetailObservable(addedKey);
// Get the value of the created detail observable for the new diff.
IObservableValue detailValue = getDetailObservableValue(addedKey);
newValues.put(addedKey, detailValue.getValue());
}
// Handle removed master values.
Set removedKeys = diff.getRemovedKeys();
for (Iterator iter = removedKeys.iterator(); iter.hasNext();) {
Object removedKey = iter.next();
// First of all, get the current detail value and add it to the set
// of old values of the new diff.
IObservableValue detailValue = getDetailObservableValue(removedKey);
oldValues.put(removedKey, detailValue.getValue());
// For removed master values, we dispose the detail observable.
removeDetailObservable(removedKey);
}
// Handle changed master values.
Set changedKeys = diff.getChangedKeys();
for (Iterator iter = changedKeys.iterator(); iter.hasNext();) {
Object changedKey = iter.next();
// Get the detail value prior to the change and add it to the set of
// old values of the new diff.
IObservableValue oldDetailValue = getDetailObservableValue(changedKey);
oldValues.put(changedKey, oldDetailValue.getValue());
// Remove the old detail value for the old master value and add it
// again for the new master value.
removeDetailObservable(changedKey);
addDetailObservable(changedKey);
// Get the new detail value and add it to the set of new values.
IObservableValue newDetailValue = getDetailObservableValue(changedKey);
newValues.put(changedKey, newDetailValue.getValue());
}
// The different key sets are the same, only the values change.
fireMapChange(Diffs.createMapDiff(addedKeys, removedKeys, changedKeys,
oldValues, newValues));