Now that I'm going through and trying to tighten validation a bit, I'm finding a few odds-n-ends. So please forgive the rash of forum messages that may appear in the next day or so.
The next issue I've hit is with constraining a list to requiring one item or zero or 1 item.
So I found the section in the Sapphire doc on @CountConstraint and tried using that. If I want one and only one item, I've tried this:
@Type( base = IComposite.class )
@XmlListBinding( mappings = @XmlListBinding.Mapping( element = "sca:composite", type = IComposite.class ) )
@CountConstraint( min = 1, max = 1 )
ListProperty PROP_COMPOSITES = new ListProperty( TYPE, "Composites" );
ModelElementList<IComposite> getComposites();
And that doesn't work. I can still create as many of these as I want and it doesn't complain. Same with this:
@Type( base = ITransforms.class )
@XmlListBinding( mappings = @XmlListBinding.Mapping( element = "transforms", type = ITransforms.class ) )
@CountConstraint( max = 1 )
ListProperty PROP_TRANSFORMS = new ListProperty( TYPE, "Transforms" );
ModelElementList<ITransforms> getTransforms();
I'm sure I'm missing something obvious, but I wasn't able to find an example of @CountConstraint being used in any of the samples.
Are you presenting this list in the content outline (as opposed to as a property editor in a section)? Could you try placing it in a section to see if you get the validation message? It is possible that content outline presentation doesn't surface all validation messages.
If you are looking at min=1/max=1 scenario, perhaps you need an ElementProperty rather than a ListProperty or maybe even ImpliedElementProperty.
An ImpliedElementProperty lets you have a child element in the model that you don't need to create explicitly. Whenever the child element's properties are set, the XML element associated with the implied element is created as well.
An ElementProperty gives you explicit control over when the child element and the corresponding XML element is created.
There are examples of both in the samples project. See the contacts sample in particular.