Home » Modeling » GMF (Graphical Modeling Framework) » Automatically set a property according to another property value
Automatically set a property according to another property value [message #193879] |
Fri, 20 June 2008 09:01 |
Eclipse User |
|
|
|
Originally posted by: mickael.istria.openwide.fr
Hello,
I am trying to add a feature into JWT plugin, but since I don't know
enough about EMF and GMF and I couldn't find an answer to my question by
navigating on Eclipse.org, I decided to ask this newsgroup.
This is my use case and the feature I want to implement:
In JWT EMF metamodel, there is a class "Application", that contains a
"javaClass" attribute. There is also a class "WebServiceApplication",
that inherits from "Application", and that contains an attribute called
"wsdlLocation".
The behavior I wish to get is that when the user changes the
"wsdlLocation" attribute if "WebServiceApplication" by changing this
property in the property sheet, the matching "javaClass" is found and
the "Application::javaClass" attribute is set in consequence.
Of course, I don't want to add such _application_ logic into the _model_
impelmentation... (although I verified it works)
I have a few questions that would allow me to implement this:
1. How to change a property value programmatically?
2. In which method "wsdlLocation" property is set, so that I just have
to call the method responsible of changing "javaClass" from there?
Thanks in advance
Mickael
|
|
| |
Re: Automatically set a property according to another property value [message #193909 is a reply to message #193895] |
Fri, 20 June 2008 11:33 |
Eclipse User |
|
|
|
Originally posted by: mickael.istria.openwide.fr
Thanks Alex,
I must admit that I have no idea of how to deal with GMF listeners to an
EMF instance... Do you have a page to point me on this topic?
I also noticed a setPropertyValue in my
WebServiceApplicationItemProvider, that is described as a delegate to
PropertySource instance.setPropertyValue...
However, I don't if it is what I am looking for, and how it works.
Do you have any knowledge about that?
Thanks again!
Mickael
Alex Shatalin a écrit :
> Hello Mickael,
>
> I think you have to add corresponding listeners to all the
> WebServiceApplication instances and set javaClass attribute from this
> listener (if you are not going to change the model and implement this
> logic there).
>
> -----------------
> Alex Shatalin
>
>
|
|
|
Re: Automatically set a property according to another property value [message #193931 is a reply to message #193909] |
Fri, 20 June 2008 12:23 |
Eclipse User |
|
|
|
Originally posted by: mickael.istria.openwide.fr
Hello,
I solved my problem! (it makes me really happy!)
In fact, I have a WebServiceApplicationItemProvider class that has been
generated by EMF. That class contains a notification handler (I think
that is the listener Alex was telling about) called notifyChanged.
This method is called each time something happens on a property of
WebServiceApplication, and it is easy to get the WebServiceApplication
from a notification (simply call notification.getNotifier()). Then I
just had to add a line in the notifyChanged method:
this.setPropertyValue(notification.getNotifier(), "javaClass", "value").
I now think it was a basic question about EMF/GMF and apologize for the
spam I produced.
Mickael
Mickael Istria a écrit :
> Thanks Alex,
>
> I must admit that I have no idea of how to deal with GMF listeners to an
> EMF instance... Do you have a page to point me on this topic?
>
> I also noticed a setPropertyValue in my
> WebServiceApplicationItemProvider, that is described as a delegate to
> PropertySource instance.setPropertyValue...
> However, I don't if it is what I am looking for, and how it works.
> Do you have any knowledge about that?
>
> Thanks again!
> Mickael
>
> Alex Shatalin a écrit :
>> Hello Mickael,
>>
>> I think you have to add corresponding listeners to all the
>> WebServiceApplication instances and set javaClass attribute from this
>> listener (if you are not going to change the model and implement this
>> logic there).
>>
>> -----------------
>> Alex Shatalin
>>
>>
|
|
|
Re: Automatically set a property according to another property value [message #193940 is a reply to message #193909] |
Fri, 20 June 2008 12:28 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
This is a multi-part message in MIME format.
--------------020500060804030103070102
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Mickael,
It seems to me you'd want to specialize the actual setting of the
property. Here's an example from ETypedElementItemProvider that's
illustrative:
protected void addETypePropertyDescriptor(Object object)
{
itemPropertyDescriptors.add
(new ItemPropertyDescriptorWithUniqueChoiceOfValueLabels
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
getResourceLocator(),
getString("_UI_ETypedElement_eType_feature"),
getString("_UI_ETypedElement_eType_description"),
EcorePackage.Literals.ETYPED_ELEMENT__ETYPE,
true,
false,
true,
null,
null,
null)
{
// ...
@Override
public void setPropertyValue(Object object, Object value)
{
EditingDomain editingDomain = getEditingDomain(object);
if (editingDomain == null)
{
super.setPropertyValue(object, value);
}
else
{
EGenericType eGenericType = null;
if (value instanceof EClassifier)
{
EClassifier eClassifier = (EClassifier)value;
eGenericType =
EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(eClassifier);
for (int i = 0, size =
eClassifier.getETypeParameters().size(); i < size; ++i)
{
eGenericType.getETypeArguments().add(EcoreFactory.eINSTANCE. createEGenericType());
}
}
else if (value instanceof ETypeParameter)
{
eGenericType =
EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setETypeParameter((ETypeParameter)value);
}
editingDomain.getCommandStack().execute
(SetCommand.create(editingDomain, object,
EcorePackage.Literals.ETYPED_ELEMENT__EGENERIC_TYPE, eGenericType));
}
}
});
}
So it seems to me you'd want to create a compound command that sets both
features as part of a single command execution.
Mickael Istria wrote:
> Thanks Alex,
>
> I must admit that I have no idea of how to deal with GMF listeners to
> an EMF instance... Do you have a page to point me on this topic?
>
> I also noticed a setPropertyValue in my
> WebServiceApplicationItemProvider, that is described as a delegate to
> PropertySource instance.setPropertyValue...
> However, I don't if it is what I am looking for, and how it works.
> Do you have any knowledge about that?
>
> Thanks again!
> Mickael
>
> Alex Shatalin a écrit :
>> Hello Mickael,
>>
>> I think you have to add corresponding listeners to all the
>> WebServiceApplication instances and set javaClass attribute from this
>> listener (if you are not going to change the model and implement this
>> logic there).
>>
>> -----------------
>> Alex Shatalin
>>
>>
--------------020500060804030103070102
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Mickael,<br>
<br>
It seems to me you'd want to specialize the actual setting of the
property. Here's an example from ETypedElementItemProvider that's
illustrative:<small><br>
</small>
<blockquote><small> protected void addETypePropertyDescriptor(Object
object)</small><br>
<small> {</small><br>
<small> itemPropertyDescriptors.add</small><br>
<small> (new ItemPropertyDescriptorWithUniqueChoiceOfValueLabels</small> <br>
<small>
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(), </small><br>
<small> getResourceLocator(),</small><br>
<small> getString("_UI_ETypedElement_eType_feature"),</small><br >
<small> getString("_UI_ETypedElement_eType_description"),</small> <br>
<small> EcorePackage.Literals.ETYPED_ELEMENT__ETYPE,</small><br>
<small> true,</small><br>
<small> false,</small><br>
<small> true,</small><br>
<small> null,</small><br>
<small> null,</small><br>
<small> null)</small><br>
<small> {</small><br>
// ...<small></small><br>
<small> </small><br>
<small> @Override</small><br>
<small> public void setPropertyValue(Object object, Object
value)</small><br>
<small> {</small><br>
<small> EditingDomain editingDomain =
getEditingDomain(object);</small><br>
<small> if (editingDomain == null)</small><br>
<small> {</small><br>
<small> super.setPropertyValue(object, value);</small><br>
<small> }</small><br>
<small> else </small><br>
<small> {</small><br>
<small> </small><br>
<small> EGenericType eGenericType = null;</small><br>
<small> if (value instanceof EClassifier)</small><br>
<small> {</small><br>
<small> EClassifier eClassifier = (EClassifier)value;</small><br>
<small> eGenericType =
EcoreFactory.eINSTANCE.createEGenericType();</small><br>
<small> eGenericType.setEClassifier(eClassifier);</small><br>
<small> for (int i = 0, size =
eClassifier.getETypeParameters().size(); i < size; ++i)</small><br>
<small> {</small><br>
<small>
eGenericType.getETypeArguments().add(EcoreFactory.eINSTANCE. createEGenericType()); </small><br>
<small> }</small><br>
<small> }</small><br>
<small> else if (value instanceof ETypeParameter)</small><br>
<small> {</small><br>
<small> eGenericType =
EcoreFactory.eINSTANCE.createEGenericType();</small><br>
<small>
eGenericType.setETypeParameter((ETypeParameter)value);</small ><br>
<small> }</small><br>
<small> editingDomain.getCommandStack().execute</small><br>
<small> (SetCommand.create(editingDomain, object,
EcorePackage.Literals.ETYPED_ELEMENT__EGENERIC_TYPE, eGenericType));</small><br>
<small> }</small><br>
<small> }</small><br>
<small> });</small><br>
<small> }</small><br>
</blockquote>
So it seems to me you'd want to create a compound command that sets
both features as part of a single command execution.<br>
<br>
<br>
Mickael Istria wrote:
<blockquote cite="mid:g3g4hs$jmi$1@build.eclipse.org" type="cite">Thanks
Alex,
<br>
<br>
I must admit that I have no idea of how to deal with GMF listeners to
an EMF instance... Do you have a page to point me on this topic?
<br>
<br>
I also noticed a setPropertyValue in my
WebServiceApplicationItemProvider, that is described as a delegate to
PropertySource instance.setPropertyValue...
<br>
However, I don't if it is what I am looking for, and how it works.
<br>
Do you have any knowledge about that?
<br>
<br>
Thanks again!
<br>
Mickael
<br>
<br>
Alex Shatalin a écrit :
<br>
<blockquote type="cite">Hello Mickael,
<br>
<br>
I think you have to add corresponding listeners to all the
WebServiceApplication instances and set javaClass attribute from this
listener (if you are not going to change the model and implement this
logic there).
<br>
<br>
-----------------
<br>
Alex Shatalin
<br>
<br>
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>
--------------020500060804030103070102--
|
|
|
Re: Automatically set a property according to another property value [message #193947 is a reply to message #193931] |
Fri, 20 June 2008 12:30 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Mickael,
Comments below.
Mickael Istria wrote:
> Hello,
>
> I solved my problem! (it makes me really happy!)
>
> In fact, I have a WebServiceApplicationItemProvider class that has
> been generated by EMF. That class contains a notification handler (I
> think that is the listener Alex was telling about) called notifyChanged.
> This method is called each time something happens on a property of
> WebServiceApplication, and it is easy to get the WebServiceApplication
> from a notification (simply call notification.getNotifier()). Then I
> just had to add a line in the notifyChanged method:
> this.setPropertyValue(notification.getNotifier(), "javaClass", "value").
The problem with this approach is that you've executed two separate
command and the user could undo just one of them. Just try playing with
undo/redo after you've done this and you'll probably be unpleasantly
surprised.
>
> I now think it was a basic question about EMF/GMF and apologize for
> the spam I produced.
Asking questions isn't spam. The frameworks are complex and it isn't
always clear where to do what...
>
> Mickael
>
>
> Mickael Istria a écrit :
>> Thanks Alex,
>>
>> I must admit that I have no idea of how to deal with GMF listeners to
>> an EMF instance... Do you have a page to point me on this topic?
>>
>> I also noticed a setPropertyValue in my
>> WebServiceApplicationItemProvider, that is described as a delegate to
>> PropertySource instance.setPropertyValue...
>> However, I don't if it is what I am looking for, and how it works.
>> Do you have any knowledge about that?
>>
>> Thanks again!
>> Mickael
>>
>> Alex Shatalin a écrit :
>>> Hello Mickael,
>>>
>>> I think you have to add corresponding listeners to all the
>>> WebServiceApplication instances and set javaClass attribute from
>>> this listener (if you are not going to change the model and
>>> implement this logic there).
>>>
>>> -----------------
>>> Alex Shatalin
>>>
>>>
|
|
|
Goto Forum:
Current Time: Fri Apr 26 15:06:23 GMT 2024
Powered by FUDForum. Page generated in 0.03446 seconds
|