BeanProxy oldVariant =
(BeanProxy) (event == null ? null : event.getOldSelection());
BeanProxy newVariant = context.getSelectedVariant();
Proxy oldType = null;
if (oldVariant != null) {
oldVariant.removeListener(readOnlyListener);
oldType = oldVariant.getPropertyProxy(PolicyModel.VARIANT_TYPE);
oldType.removeListener(typeListener);
}
if (newVariant == null) {
composite.clear();
setEnabled(false);
} else {
// Assume that all the controls are enabled.
setEnabled(true);
// The variant type has changed then make sure that the controls
// are enabled properly.
Proxy newType =
newVariant.getPropertyProxy(PolicyModel.VARIANT_TYPE);
boolean newTypeIsNull = newType.getModelObject() == VariantType.NULL;
BeanProxy metadata = getMetadataProxy();
if (metadata == null || newTypeIsNull) {
composite.clear();
setEnabled(false);
} else {
composite.updateFromProxy(metadata);
// Update the state of the image preserve controls if
// necessary.
ImageConversionMode conversionMode = (ImageConversionMode)
composite.getProperty(PolicyModel.CONVERSION_MODE);
if (conversionMode != null) {
updateImagePreserveControlState(conversionMode);
}
}
// Note: Enable state should not be set to true after this point
// as otherwise it blows away the work done in
// updateImagePreserveControls.
// If the variant is read only then disable all controls.
if (newVariant.isReadOnly()) {
setEnabled(false);
}
newVariant.addListener(readOnlyListener, false);
newType.addListener(typeListener, false);
}
handlingPropertyChanges = true;
}