|
Re: IProject base type for property? [message #804556 is a reply to message #804199] |
Wed, 22 February 2012 19:22 |
Konstantin Komissarchik Messages: 1077 Registered: July 2009 |
Senior Member |
|
|
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
|
|
|
|
Re: IProject base type for property? [message #804941 is a reply to message #804772] |
Thu, 23 February 2012 07:01 |
Greg Amerson Messages: 119 Registered: March 2010 |
Senior Member |
|
|
So I'm getting very close to getting this working but I'm having some problems with getting the annotations compiler to write out the Impl. When I specify 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 );
It won't write out the Impl on save, but if I comment out the @Type(base=IProject.class) and the two services and then re-save the processor will generate the Impl file. Any idea why those annotations are breaking the sapphire processor?
[Updated on: Thu, 23 February 2012 07:08] Report message to a moderator
|
|
|
|
Re: IProject base type for property? [message #805024 is a reply to message #804996] |
Thu, 23 February 2012 08:59 |
Greg Amerson Messages: 119 Registered: March 2010 |
Senior Member |
|
|
Ok, Got the project working nicely, now I want to have a property where the user can select a sub-folder in this project. Here is my annotation
@Type( base = Path.class )
@Label( standard = "&folder" )
@ProjectRelativePath
@MustExist
ValueProperty PROP_FOLDER = new ValueProperty( TYPE, "Folder" );
Value<Path> getFolder();
void setFolder( String value );
void setFolder( Path value );
For this property I'm attaching a
ProjectRelativePathBrowseActionHandler
However, when this handler is invoked it does thisfinal IProject project = getPart().getModelElement().adapt( IProject.class ); in the getBasePaths() call. So in my case of a new file wizard, my IModelElement is just in memory, no resource file that is really backing it. So it is using the default MemoryResource.
What is the recommended way to supply the IProject to the handler? One way I thought about was subclassing MemoryResource to override the adapt() method to return the project in my wizard context, but MemoryResource is final. Any other thoughts?
[Updated on: Thu, 23 February 2012 09:01] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04974 seconds