Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » IProject base type for property?
IProject base type for property? [message #804199] Wed, 22 February 2012 10:05 Go to next message
Greg Amerson is currently offline Greg AmersonFriend
Messages: 119
Registered: March 2010
Senior Member
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 19:22 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
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 #804772 is a reply to message #804556] Thu, 23 February 2012 01:25 Go to previous messageGo to next message
Greg Amerson is currently offline Greg AmersonFriend
Messages: 119
Registered: March 2010
Senior Member
Got it. The reference approach is exactly how I'll proceed, thanks!
Re: IProject base type for property? [message #804941 is a reply to message #804772] Thu, 23 February 2012 07:01 Go to previous messageGo to next message
Greg Amerson is currently offline Greg AmersonFriend
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 #804996 is a reply to message #804941] Thu, 23 February 2012 08:16 Go to previous messageGo to next message
Greg Amerson is currently offline Greg AmersonFriend
Messages: 119
Registered: March 2010
Senior Member
I think I'm hitting that JDT bug where it wont fire the annotations processor, sigh.
Re: IProject base type for property? [message #805024 is a reply to message #804996] Thu, 23 February 2012 08:59 Go to previous messageGo to next message
Greg Amerson is currently offline Greg AmersonFriend
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 this
final 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

Re: IProject base type for property? [message #805296 is a reply to message #805024] Thu, 23 February 2012 15:47 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Please open an enhancement request detailing this scenario. We clearly need to provide a way to enrich adapt targets, but I am not sure whether making MemoryResource public API and non-final is a good solution here.

- Konstantin
Re: IProject base type for property? [message #805301 is a reply to message #805296] Thu, 23 February 2012 15:56 Go to previous message
Greg Amerson is currently offline Greg AmersonFriend
Messages: 119
Registered: March 2010
Senior Member
Sure thing, https://bugs.eclipse.org/bugs/show_bug.cgi?id=372359
Previous Topic:ant clean-start fails for Sapphire building
Next Topic:Suppressing browse action handler
Goto Forum:
  


Current Time: Tue Mar 19 09:00:10 GMT 2024

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

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

Back to the top