Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community Forums[EMF Forms] How to select specific view model for view
https://www.eclipse.org/forums/index.php/mv/msg/1082132/1746371/#msg_1746371
I have defined several view models for one of my model elements. I want to specify which one should actually be used in a view depending on the context, but don't know how best to achieve this.
I can see that the TreeMasterDetail view is effectively doing this. It appears to achieve it by setting properties on the view registration extension point, then also setting properties in the view context.
So i suppose my question breaks down like this:
Is the TreeMasterDetail approach the best way of achieving "selecting" a view model at render time, or are there other approaches?
If so, how exactly are the provided properties used to select which view model to use?
Thanks in advance for your help!]]>Bob Bobson2016-10-27T16:23:34-00:00Re: [EMF Forms] How to select specific view model for view
https://www.eclipse.org/forums/index.php/mv/msg/1082132/1746400/#msg_1746400
The way the TreeMasterDetail does this is the easiest one. In this case when you request a View Model using the ViewProviderHelper, you can pass in VViewModelProperties which are basically Key-Value Pairs.
You can pass in multiple such properties and when you register you view models then the one that satisfies most of the properties will be taken.
The alternative would be to provide you own IViewProvider (As an OSGi-Service or register it on an extension point). Here you will have to load/create the view models by yourself and return the correct one based on the passed in EObject and VViewModelProperties.
I would only recommend to do this, if you want to filter your view models based on some attribute value, so in a dynamic way.