[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Use of ChoiceFormat in View/Edit Pattern on Labels

Hello,

I'm having a problem trying to conditionally format the content of labels on GMF diagrams.

Basically, I have a Cardinality attribute on a Reference concept in my Meta Model, this is modelled as an Integer. I model one-to-many references as -1, many-to-one as -2 and many-to-many as -3. Non-negative cardinalities are left as is. When labelling a Reference in my GMF diagram I wish it to convert the string I give it to the correct underlying format as such:

"1..*" -> -1
"*..1" -> -2
"*..*" -> -3
"3" -> 3

In order to accomplish this I'm trying to use View and Edit Patterns however there isn't a huge amount of documentation on these. For my View/Edit/Editor Pattern I currently use the expression:

{0,choice,-3#*..*|-2#*..1|-1#1..*|-1<{0}}

This is a ChoiceFormat expression in the form as described here: http://java.sun.com/javase/6/docs/api/java/text/MessageFormat.html

However, I cannot seem to get the format correct. Using the above expression, although correct for the View, I don't think it's quite right for the Edit/Editor patterns. Consequently, the current behaviour allows me to enter the first 3 rules from earlier but fails to change the label value when I enter regular values such as "10" or "5".

It's quite difficult to explain the behaviour as it varies only slightly for each adjustment, but I hope you can understand what I'm trying to do. Essentially I just want to pretty print certain values (-1, -2, -3) such that if I type 1..*, *..1, *..* (respectively) into a label, it converts the underlying value into the correct Integer so I can then process it later on.

Any advice would be very much appreciated. If View/Edit/Editor Patterns are not the best way to solve the problem then I am keen to hear suggestions on other possible solutions.

Thanks in advance,

Mark