using dynamic API to insert an EList item [message #64959] |
Tue, 19 December 2006 20:30 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: dkrebs.tibco.com
Hi,
I'm going insane over here because I know this can't be that hard. I'm
trying to dynamically introspect an EObject and add an EMF object to the
list. Using regular code it would be something like
person.getBuddies().add(johny); However I get lost when figuring out how
to get a reference to the buddies EList using the dynamic API, could
anyone provide a simple example? Thanks - Duncan
|
|
|
Re: using dynamic API to insert an EList item [message #64973 is a reply to message #64959] |
Tue, 19 December 2006 20:38 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: merks.ca.ibm.com
This is a multi-part message in MIME format.
--------------090109010000060207040207
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Duncan,
This implementation of replace in EcoreUtil will probably help you get
the idea:
/**
* Replaces the old value in the object's feature with the new value.
* @param eObject the object holding the values.
* @param eStructuralFeature the feature of the object holding the
values.
* @param oldValue the value to replace.
* @param newValue the replacement value.
*/
public static void replace(EObject eObject, EStructuralFeature
eStructuralFeature, Object oldValue, Object newValue)
{
if (FeatureMapUtil.isMany(eObject, eStructuralFeature))
{
@SuppressWarnings("unchecked") List<Object> list =
(List<Object>)eObject.eGet(eStructuralFeature);
list.set(list.indexOf(oldValue), newValue);
}
else
{
eObject.eSet(eStructuralFeature, newValue);
}
}
You need to cast the result of eGet to a list if the feature isMany...
Duncan Krebs wrote:
> Hi, I'm going insane over here because I know this can't be that hard.
> I'm trying to dynamically introspect an EObject and add an EMF object
> to the list. Using regular code it would be something like
> person.getBuddies().add(johny); However I get lost when figuring out
> how to get a reference to the buddies EList using the dynamic API,
> could anyone provide a simple example? Thanks - Duncan
>
>
--------------090109010000060207040207
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Duncan,<br>
<br>
This implementation of replace in EcoreUtil will probably help you get
the idea:<br>
<blockquote><small>
|
|
|
Re: using dynamic API to insert an EList item [message #64985 is a reply to message #64973] |
Tue, 19 December 2006 21:40 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: dkrebs.tibco.com
Ed,
Thanks for the example. The EClass structure is a little hard to grasp at
first. Been a while since I've posted here, have gone from failed startup
to TIBCO engineer in Palo Alto, doing some cool things with eclipse. -
Duncan
|
|
|
Re: using dynamic API to insert an EList item [message #597137 is a reply to message #64959] |
Tue, 19 December 2006 20:38 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Ed Merks![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=ed.merks%40gmail.com) Messages: 33201 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------090109010000060207040207
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Duncan,
This implementation of replace in EcoreUtil will probably help you get
the idea:
/**
* Replaces the old value in the object's feature with the new value.
* @param eObject the object holding the values.
* @param eStructuralFeature the feature of the object holding the
values.
* @param oldValue the value to replace.
* @param newValue the replacement value.
*/
public static void replace(EObject eObject, EStructuralFeature
eStructuralFeature, Object oldValue, Object newValue)
{
if (FeatureMapUtil.isMany(eObject, eStructuralFeature))
{
@SuppressWarnings("unchecked") List<Object> list =
(List<Object>)eObject.eGet(eStructuralFeature);
list.set(list.indexOf(oldValue), newValue);
}
else
{
eObject.eSet(eStructuralFeature, newValue);
}
}
You need to cast the result of eGet to a list if the feature isMany...
Duncan Krebs wrote:
> Hi, I'm going insane over here because I know this can't be that hard.
> I'm trying to dynamically introspect an EObject and add an EMF object
> to the list. Using regular code it would be something like
> person.getBuddies().add(johny); However I get lost when figuring out
> how to get a reference to the buddies EList using the dynamic API,
> could anyone provide a simple example? Thanks - Duncan
>
>
--------------090109010000060207040207
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Duncan,<br>
<br>
This implementation of replace in EcoreUtil will probably help you get
the idea:<br>
<blockquote><small>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.04092 seconds