| using dynamic API to insert an EList item [message #64959] | 
Tue, 19 December 2006 15:30   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 15:38    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 16:40   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 15:38   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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>
 |  
 |  
  | 
 | 
Powered by 
FUDForum. Page generated in 0.02941 seconds