Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sapphire » List Constraints
List Constraints [message #663912] Wed, 06 April 2011 15:12 Go to next message
Brian Fitzpatrick is currently offline Brian Fitzpatrick
Messages: 495
Registered: July 2009
Senior Member
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.

Thanks in advance for any and all help. Smile

--Fitz
Re: List Constraints [message #663938 is a reply to message #663912] Wed, 06 April 2011 17:12 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin Komissarchik
Messages: 923
Registered: July 2009
Senior Member
Hmm... That should work.

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.

- Konstantin
Re: List Constraints [message #663955 is a reply to message #663938] Wed, 06 April 2011 18:50 Go to previous messageGo to next message
Brian Fitzpatrick is currently offline Brian Fitzpatrick
Messages: 495
Registered: July 2009
Senior Member
I went back and looked again and the validation is showing up... It's just not very visible and lets the user do it anyway.

I need to look into some of the additional validation options in the framework to see if I can make this more visible.

Thanks Konstantin. Back to the drawing board. Smile
Re: List Constraints [message #663959 is a reply to message #663955] Wed, 06 April 2011 19:01 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin Komissarchik
Messages: 923
Registered: July 2009
Senior Member
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.

- Konstantin
Re: List Constraints [message #663962 is a reply to message #663959] Wed, 06 April 2011 19:28 Go to previous message
Brian Fitzpatrick is currently offline Brian Fitzpatrick
Messages: 495
Registered: July 2009
Senior Member
Ok, I'll poke around in there soon.

Thanks!
Previous Topic:Relative File Path Browsing
Next Topic:BooleanValue/IntegerValue
Goto Forum:
  


Current Time: Sat Apr 19 00:45:17 EDT 2014

Powered by FUDForum. Page generated in 0.01717 seconds