Skip to main content



      Home
Home » Modeling » EMF » Unordered list of children
Unordered list of children [message #1744734] Thu, 29 September 2016 14:16 Go to next message
Eclipse UserFriend
Hello,

I have the following ecore model:

...
 <eClassifiers xsi:type="ecore:EClass" name="Pipeline">
    <eStructuralFeatures xsi:type="ecore:EReference" name="source" lowerBound="1"
        eType="#//Source" containment="true" resolveProxies="false"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="cleanse" ordered="false"
        lowerBound="1" upperBound="-1" eType="#//Cleanse"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="transform" ordered="false"
        lowerBound="1" eType="#//Transform"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="target" lowerBound="1"
        eType="#//Target" containment="true"/>
  </eClassifiers>
...


Here the Cleanse and Transform elements will always preserve their order as defined in Ecore model, so if I added Transform, Cleanse, Transform, in the model I'll get

Pipeline
   + Cleanse
   + Transform
   + Transform


This is perfectly fine according to Ecore, but how should I change my Ecore model so that order of insertion would be preserved:

Pipeline
   + Transform
   + Cleanse
   + Transform


I tried this suggestion and the model updates how I want to, but my UI which uses one of the generated EMF editor does not function properly.

Thanks,
Alex

[Updated on: Thu, 29 September 2016 16:07] by Moderator

Re: Unordered list of children [message #1744756 is a reply to message #1744734] Fri, 30 September 2016 00:26 Go to previous messageGo to next message
Eclipse UserFriend
To preserve order the information needs to be represented in the model. That's only possible if you have a single feature that holds both the Transform and Cleanse instances and that's only possible if Transform and Cleanse have a common base class that can be used as the type of the one containment reference that will contain both the Transform and the Cleanse instances, in arbitrary interspersed order.
Re: Unordered list of children [message #1744838 is a reply to message #1744756] Fri, 30 September 2016 12:37 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Ed. I am sorry, I didn't fully understood your solution, is there an example ecore I can look at?
Re: Unordered list of children [message #1744852 is a reply to message #1744838] Fri, 30 September 2016 15:31 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

I think Ed describe something like this (in Xcore) :

class Pipeline
{
	contains AbstractOperation[] operations
}

abstract class AbstractOperation {}

class Cleanse extends AbstractOperation {}

class Transform extends AbstractOperation {}


=> Only one list, the order is kept.
Re: Unordered list of children [message #1744853 is a reply to message #1744852] Fri, 30 September 2016 15:38 Go to previous messageGo to next message
Eclipse UserFriend
Yes, EPackage.eClassifiers allow EClasses and EDataType to be referenced in arbitrary interspersed order. Similarly EClass.eStructuralFeatures allows EReferences and EAttributes to appear in interspersed order, and originally, in ancient history, it was modeled at two separate containment reference, so if you do getEAttribute().add(eAttribute) you'll hit this code:

          @Override
          public boolean add(EAttribute object)
          {
            System.err.println("Please fix your code to add using EClass.getEStructuralFeatures() instead of EClass.getEAttributes()");
            return getEStructuralFeatures().add(object);
          } 
Re: Unordered list of children [message #1744856 is a reply to message #1744852] Fri, 30 September 2016 16:05 Go to previous messageGo to next message
Eclipse UserFriend
Aurélien Mora wrote on Fri, 30 September 2016 15:31
Hello,

I think Ed describe something like this (in Xcore) :

class Pipeline
{
	contains AbstractOperation[] operations
}

abstract class AbstractOperation {}

class Cleanse extends AbstractOperation {}

class Transform extends AbstractOperation {}


=> Only one list, the order is kept.


Awesome! That's a nice pattern to know. Thank you!
Re: Unordered list of children [message #1744857 is a reply to message #1744853] Fri, 30 September 2016 16:09 Go to previous message
Eclipse UserFriend
Ed Merks wrote on Fri, 30 September 2016 15:38
Yes, EPackage.eClassifiers allow EClasses and EDataType to be referenced in arbitrary interspersed order. Similarly EClass.eStructuralFeatures allows EReferences and EAttributes to appear in interspersed order, and originally, in ancient history, it was modeled at two separate containment reference, so if you do getEAttribute().add(eAttribute) you'll hit this code:

          @Override
          public boolean add(EAttribute object)
          {
            System.err.println("Please fix your code to add using EClass.getEStructuralFeatures() instead of EClass.getEAttributes()");
            return getEStructuralFeatures().add(object);
          } 


I understand. Thanks again!
Previous Topic:[Databinding] Nested properties with master-observable
Next Topic:[EMF] Lower bound 0 vs lower bound 1 of Reference
Goto Forum:
  


Current Time: Sun Jul 27 02:29:53 EDT 2025

Powered by FUDForum. Page generated in 0.05157 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top