View[] subviews = view.getSubviews();
// remove views for fields that no longer exist
outer: for (int i = 0; i < subviews.length; i++) {
final FieldContent fieldContent = ((FieldContent) subviews[i].getContent());
for (int j = 0; j < flds.size(); j++) {
final ObjectAssociation field = flds.get(j);
if (fieldContent.getField() == field) {
continue outer;
}
}
view.removeView(subviews[i]);
}
// update existing fields if needed
subviews = view.getSubviews();
for (int i = 0; i < subviews.length; i++) {
final View subview = subviews[i];
final ObjectAssociation field = ((FieldContent) subview.getContent()).getField();
final ObjectAdapter value = field.get(object);
if (field.isOneToManyAssociation()) {
subview.update(value);
} else if (field.isOneToOneAssociation()) {
final ObjectAdapter existing = subview.getContent().getAdapter();
// if the field is parseable then it may have been modified; we
// need to replace what was
// typed in with the actual title.
if (!field.getSpecification().isParseable()) {
final boolean changedValue = value != existing;
final boolean isDestroyed = existing != null && existing.getResolveState().isDestroyed();
if (changedValue || isDestroyed) {
View fieldView;
fieldView = createFieldView(view, axes, object, i, field);
if (fieldView != null) {
view.replaceView(subview, decorateSubview(axes, fieldView));
} else {
view.addView(new FieldErrorView("No field for " + value));
}
}
} else {
if (AdapterUtils.exists(value) && !AdapterUtils.wrappedEqual(value, existing)) {
final View fieldView = createFieldView(view, axes, object, i, field);
view.replaceView(subview, decorateSubview(axes, fieldView));
} else {
subview.refresh();
}
}
} else {
throw new UnknownTypeException(field.getName());
}
}
// add new fields
outer2: for (int j = 0; j < flds.size(); j++) {
final ObjectAssociation field = flds.get(j);
for (int i = 0; i < subviews.length; i++) {
final FieldContent fieldContent = ((FieldContent) subviews[i].getContent());
if (fieldContent.getField() == field) {
continue outer2;
}
}
addField(view, axes, object, field, j);
}