Defining scpecific references? [message #625778] |
Wed, 22 September 2010 06:26  |
Eclipse User |
|
|
|
Hello,
I'm working on a generic client, based on a XML configuration file. I started with an XSD model and generated a model editor with EMF.
In my meta model there are so called 'ActionDescriptors' which contain a sequence of 'ToolDescriptors'. For reusing purposes I want to offer the possibility to override some 'Parameter' attributes of a ToolDescriptor in relationship to an ActionDescriptor. Whad I did was referencing the 'Parameter' type in an 'ParameterOverride' class. This works, but the model editor shows me a list of ALL parameters, not only these of the referenced ToolDescriptor.
Is there a way to specify the reference more accurate? Just like X-Path expressions?
Sure I could do this by editing the code of the generated edit-PlugIn, but something says me that I can simply define it in the Ecore-editor or even my XSD.
Thank you in anticipation!
[Updated on: Wed, 22 September 2010 06:58] by Moderator
|
|
|
|
Re: Defining scpecific references? [message #628149 is a reply to message #625778] |
Thu, 23 September 2010 05:36   |
Eclipse User |
|
|
|
Thanks for the hint, Ed! But this seems to be a lot more tricky than I thought!
The only two interesting classes which are used to create an ItemPropertyDescriptor are "ComposedAdapterFactory" and "EStructuralFeature" (see below), which will be an EReference in my case (subclass). The other parameters are genmodel options. Do I really have to set up an own item provider adapter factory (implementing ComposeableAdapterFactory)?
Here's the method which creates an ItemPropertyDescriptor:
// In the EMF implementation 'AdapterFactory' will be casted into 'ComposedAdapterFactory'
protected ItemPropertyDescriptor createItemPropertyDescriptor(AdapterFactory adapterFactory,
ResourceLocator resourceLocator,
java.lang.String displayName,
java.lang.String description,
EStructuralFeature feature,
boolean isSettable,
boolean multiLine,
boolean sortChoices,
java.lang.Object staticImage,
java.lang.String category,
java.lang.String[] filterFlags)
|
|
|
Re: Defining scpecific references? [message #628245 is a reply to message #628149] |
Thu, 23 September 2010 06:43   |
Eclipse User |
|
|
|
Ralph,
No, you'd override the AbcItemProvider.addFooPropertyDescriptor. See
ETypedElementItemProvider.addETypePropertyDescriptor as an example.
Ralph wrote:
> Thanks for the hint, Ed! But this seems to be a lot more tricky than I
> thought!
> The only two interesting classes which are used to create an
> ItemPropertyDescriptor are "ComposedAdapterFactory" and
> "EStructuralFeature" (see below), which will be an EReference in my
> case (subclass). The other parameters are genmodel options. Do I
> really have to set up an own item provider adapter factory
> (implementing ComposeableAdapterFactory)?
>
> Here's the method which creates an ItemPropertyDescriptor:
>
> // In the EMF implementation 'AdapterFactory' will be casted into
> 'ComposedAdapterFactory'
> protected ItemPropertyDescriptor
> createItemPropertyDescriptor(AdapterFactory adapterFactory,
>
> ResourceLocator resourceLocator,
>
> java.lang.String displayName,
>
> java.lang.String description,
>
> EStructuralFeature feature,
> boolean
> isSettable,
> boolean
> multiLine,
> boolean
> sortChoices,
>
> java.lang.Object staticImage,
>
> java.lang.String category,
>
> java.lang.String[] filterFlags)
|
|
|
Re: Defining scpecific references? [message #628647 is a reply to message #625778] |
Thu, 23 September 2010 10:24  |
Eclipse User |
|
|
|
Wow thanks, it works great now! Although it took me some time to figure out what I have to customize.
For those who also have this Problem:
I got me the ETypedElementItemProvider source from an Open Source web page, copied the addETypePropertyDescriptor (...) method it into my XyzItemProvider and edited it. Instead of deleting every Object that's in the "results" ArrayList, I created a new one and returned that one.
Luckily there's a getParent(Object object) mehtod you can use while overriding the getChoiceOfValues(...) method, making it easy to find the values you want.
Finally you need to override the setPropertyValue(...) method so your selection in the model editor will be applied. For me, some simple modification did the job (see below).
@Override
public void setPropertyValue(Object object, Object value) {
EditingDomain editingDomain = getEditingDomain(object);
if (editingDomain == null) {
super.setPropertyValue(object, value);
} else {
editingDomain
.getCommandStack()
.execute(
SetCommand
.create(
editingDomain,
object,
MyPackage.Literals.RACTION_PARM_FROM_OVERRIDE__PARM_TO_OVERRIDE, // selected property
value));
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.09543 seconds