Skip to main content



      Home
Home » Archived » Sapphire » Property Custom Parser?
Property Custom Parser? [message #1268315] Mon, 10 March 2014 06:44 Go to next message
Eclipse UserFriend
Hello all Smile

I use Sapphire 0.7, and I have a property called "Resolution" which user should be allowed to write a Matlab Expression in it like:
10+(16*2^-12)


I already made a function called "parseResolution" that takes a String input and returns either a valid double or null if parsing failed.

The problem is, many other properties validation is based upon this "Resolution" property, and I would like to avoid calling my custom "parseResolution" each time I implement a new Validation Service. Also I would like to make use of the new @Validation for all other properties that are dependent upon "Resolution".

What I'm thinking of is somehow changing how ".content()" works. Is there anything like that?
Re: Property Custom Parser? [message #1268391 is a reply to message #1268315] Mon, 10 March 2014 08:52 Go to previous messageGo to next message
Eclipse UserFriend
Yes you sure can do that with the type conversion system assuming that your custom type can be converted from a String and back again. So for your property you can set the Base type like this:
@Type( base = MatlabExpression.class )
@Label(...)
ValueProperty PROP_RESOLUTION = new ValueProperty( TYPE, "Resolution" );

Value<MatlabExpression> getResolution();
setResolution( MatlabExpression resolution );
setResolution( String resolution );


Where MatlabExpression.java is just a POJO that has a method called "doubleValue()" or something that gives the double value. Then you need to use the META-INF/sapphire-extension.xml file to register two service classes that will be used for the conversion using ConversionService<String, MatlabExpression>, one for StringToMatlabExpressionService.java and another for MatlabExpressionToStringService.java. You can see in the sapphire samples plugin some examples of how to exactly how to wire this up. http://git.eclipse.org/c/sapphire/org.eclipse.sapphire.git/tree/plugins/org.eclipse.sapphire.samples/META-INF/sapphire-extension.xml

Once you have this working you can do something like this:
 element.getResolution().content().doubleValue();


Would that work for you?

[Updated on: Mon, 10 March 2014 09:19] by Moderator

Re: Property Custom Parser? [message #1268455 is a reply to message #1268391] Mon, 10 March 2014 10:16 Go to previous messageGo to next message
Eclipse UserFriend
+1 to Greg's answer.
Re: Property Custom Parser? [message #1268964 is a reply to message #1268455] Tue, 11 March 2014 03:46 Go to previous messageGo to next message
Eclipse UserFriend
That looks great, but then, can I use "Resolution" in an EL like that?
${ Decimal == ((Physical - Offset)/Resolution.Content.doubleValue) }


Re: Property Custom Parser? [message #1268987 is a reply to message #1268964] Tue, 11 March 2014 04:35 Go to previous messageGo to next message
Eclipse UserFriend
well, I tried it and didn't work Smile
Re: Property Custom Parser? [message #1269621 is a reply to message #1268987] Tue, 11 March 2014 23:15 Go to previous messageGo to next message
Eclipse UserFriend
You are going to need to be more specific. Include your property definition, the conversion service implementations and their registrations in the extensions file.

Quote:
That looks great, but then, can I use "Resolution" in an EL like that?

${ Decimal == ((Physical - Offset)/Resolution.Content.doubleValue) }


You cannot access an arbitrary method in Sapphire EL, but you should be able to write a conversion service implementation from your Resolution object to whatever is the data type of (Physical - Offset). Then it's just...

${ Decimal == ((Physical - Offset)/Resolution.Content) }
Re: Property Custom Parser? [message #1269757 is a reply to message #1269621] Wed, 12 March 2014 02:52 Go to previous message
Eclipse UserFriend
http://www.i2clipart.com/cliparts/8/5/9/5/clipart-thumbs-up-happy-smiley-emoticon-8595.png

That helped a lot, thank you very much for your help Smile

[Updated on: Wed, 12 March 2014 02:53] by Moderator

Previous Topic:User custom method in EL?
Next Topic:@DefaultValue never tells if value is empty!
Goto Forum:
  


Current Time: Mon May 05 14:41:30 EDT 2025

Powered by FUDForum. Page generated in 0.04763 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top