IProject base type for property? [message #804199] |
Wed, 22 February 2012 05:05  |
Eclipse User |
|
|
|
Hey everybody,
I'd like to do this:
@Type( base = IProject.class )
@Service(impl=ProjectPossibleValuesService.class)
@Label( standard = "&project" )
@Required
ValueProperty PROP_PROJECT = new ValueProperty( TYPE, "Project" );
Value<IProject> getProject();
void setProject( IProject project );
void setProject( String project );
Is this possible?
|
|
|
Re: IProject base type for property? [message #804556 is a reply to message #804199] |
Wed, 22 February 2012 14:22   |
Eclipse User |
|
|
|
You can do this if you implement ValueSerializationService for IProject. In order for an object to be held by a value property, Sapphire needs to know how to convert it to/from string. You want to avoid holding non-immutable objects in value properties. That's because if the object changes internally, Sapphire model would not be aware of this change and things can get out of sync. In your scenario, you may be able to get away with using IProject, since the data that you would use for serialization (project name) never changes.
Another way to do this is via reference value properties. This approach makes it more explicit that what you are storing is something that represents a reference to a more complex object that needs to be resolved via a separate call. The declaration would look like this:
@Reference( target = IProject.class )
@Services( { @Service( impl = ProjectReferenceService.class ), @Service( impl = ProjectNamesPossibleValuesService.class ) } )
@Label( standard = "&project" )
@Required
ValueProperty PROP_PROJECT = new ValueProperty( TYPE, "Project" );
ReferenceValue<String,IProject> getProject();
void setProject( String project );
ProjectReferenceService in above would be implementation of ReferenceService API.
Then to access the project, you would make this call...
IProject pj = element.getProject().resolve();
Let me know if anything in the above is unclear.
Thanks,
- Konstantin
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.27497 seconds