|
Re: Property Custom Parser? [message #1268391 is a reply to message #1268315] |
Mon, 10 March 2014 12:52 |
Greg Amerson 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
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.24436 seconds