Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » Property Custom Parser?
Property Custom Parser? [message #1268315] Mon, 10 March 2014 10:44 Go to next message
Hazem ELRAFFIEE is currently offline Hazem ELRAFFIEEFriend
Messages: 61
Registered: September 2012
Member
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 12:52 Go to previous messageGo to next message
Greg Amerson is currently offline Greg AmersonFriend
Messages: 119
Registered: March 2010
Senior Member
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 13:19]

Report message to a moderator

Re: Property Custom Parser? [message #1268455 is a reply to message #1268391] Mon, 10 March 2014 14:16 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
+1 to Greg's answer.
Re: Property Custom Parser? [message #1268964 is a reply to message #1268455] Tue, 11 March 2014 07:46 Go to previous messageGo to next message
Hazem ELRAFFIEE is currently offline Hazem ELRAFFIEEFriend
Messages: 61
Registered: September 2012
Member
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 08:35 Go to previous messageGo to next message
Hazem ELRAFFIEE is currently offline Hazem ELRAFFIEEFriend
Messages: 61
Registered: September 2012
Member
well, I tried it and didn't work Smile
Re: Property Custom Parser? [message #1269621 is a reply to message #1268987] Wed, 12 March 2014 03:15 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
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 06:52 Go to previous message
Hazem ELRAFFIEE is currently offline Hazem ELRAFFIEEFriend
Messages: 61
Registered: September 2012
Member
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 06:53]

Report message to a moderator

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


Current Time: Tue Oct 15 19:15:33 GMT 2024

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

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

Back to the top