Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Unordered list of children
Unordered list of children [message #1744734] Thu, 29 September 2016 18:16 Go to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 561
Registered: November 2009
Senior Member
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 20:07]

Report message to a moderator

Re: Unordered list of children [message #1744756 is a reply to message #1744734] Fri, 30 September 2016 04:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
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.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Unordered list of children [message #1744838 is a reply to message #1744756] Fri, 30 September 2016 16:37 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 561
Registered: November 2009
Senior Member
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 19:31 Go to previous messageGo to next message
Aurélien Mora is currently offline Aurélien MoraFriend
Messages: 38
Registered: July 2014
Member
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 19:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
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);
          } 


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Unordered list of children [message #1744856 is a reply to message #1744852] Fri, 30 September 2016 20:05 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 561
Registered: November 2009
Senior Member
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 20:09 Go to previous message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 561
Registered: November 2009
Senior Member
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: Thu Mar 28 20:01:50 GMT 2024

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

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

Back to the top