Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » containment and emf treenode model(Using containment with an emf treenode model)
containment and emf treenode model [message #559525] Fri, 17 September 2010 01:53 Go to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
I'm attempting to use containment in a few exercises in order to restrict the stored model to a single xsi file. A second objective is to have the tree nodes displayed in the generated editor as a tree. I haven't been able to solve this. The closest I get is the ecore model below, which does have a container for the treenodes, and does let me specify the node parent and child relationships, but the generated editor unfortunately just displays as a list. Is there some easy way that I'm missing that would allow you to specify a tree display of contained objects? Thanks, Jay

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="nodes"
nsURI="http:///my/nodes.ecore" nsPrefix="my.nodes">
<eClassifiers xsi:type="ecore:EClass" name="Node">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="label" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//Node"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="parent" eType="#//Node"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Nodes">
<eStructuralFeatures xsi:type="ecore:EReference" name="NodeStore" upperBound="-1"
eType="#//Node" containment="true"/>
</eClassifiers>
</ecore:EPackage>

Re: containment and emf treenode model [message #559544 is a reply to message #559525] Fri, 17 September 2010 06:01 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Hi Jay,

If you would get your containments being structured you need to declare
it structured:
You have an element Nodes containing all Node elements


<eStructuralFeatures xsi:type="ecore:EReference" name="NodeStore"
upperBound="-1"
eType="#//Node" containment="true"/>


and let the nodes just refer each other

<eStructuralFeatures xsi:type="ecore:EReference" name="children"
upperBound="-1"
eType="#//Node"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="parent"
eType="#//Node"/>
..

For self structured you should let contain the parent node the child nodes:

<eStructuralFeatures xsi:type="ecore:EReference" name="children"
upperBound="-1"
eType="#//Node" containment="true"/>

The parent relationship might become obsolete node.eContainer() == Node
or Nodes.

Sven


Am 17.09.2010 03:53, schrieb Jay Norwood:
> I'm attempting to use containment in a few exercises in order to
> restrict the stored model to a single xsi file. A second objective is to
> have the tree nodes displayed in the generated editor as a tree. I
> haven't been able to solve this. The closest I get is the ecore model
> below, which does have a container for the treenodes, and does let me
> specify the node parent and child relationships, but the generated
> editor unfortunately just displays as a list. Is there some easy way
> that I'm missing that would allow you to specify a tree display of
> contained objects? Thanks, Jay
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="nodes"
> nsURI="http:///my/nodes.ecore" nsPrefix="my.nodes">
> <eClassifiers xsi:type="ecore:EClass" name="Node">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="label"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="children"
> upperBound="-1"
> eType="#//Node"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="parent"
> eType="#//Node"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Nodes">
> <eStructuralFeatures xsi:type="ecore:EReference" name="NodeStore"
> upperBound="-1"
> eType="#//Node" containment="true"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
Re: containment and emf treenode model [message #559692 is a reply to message #559544] Fri, 17 September 2010 15:20 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
Yes, thank you. The combination of removing the parent and setting the containment in the node works well. So this ecore model below works well, and "children" seems to be a magical attribute name which causes the editor display as a tree, without it requiring an entry for children in the properties page. Now I'm wondering if this Node can be made an abstract class so that I can have different derived node types appear in the tree. I'll try that next. Thanks again.

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="nodes2"
nsURI="http:///my/nodes2.ecore" nsPrefix="my.nodes2">
<eClassifiers xsi:type="ecore:EClass" name="Node">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="label" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//Node" containment="true"/>
</eClassifiers>
</ecore:EPackage>
Re: containment and emf treenode model [message #559702 is a reply to message #559692] Fri, 17 September 2010 16:02 Go to previous message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
Yes, this seems to work well. A small ecore tree model with Root, Inner and Leaf nodes, along with abstract classes to limit the children available, i.e. no children available for the leaf node, and only the single Root node.

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="nodes2"
nsURI="http:///my/nodes2.ecore" nsPrefix="my.nodes2">
<eClassifiers xsi:type="ecore:EClass" name="Node" abstract="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="label" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Root" eSuperTypes="#//Node">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="RootData" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//LeafOrInnerNode" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="InnerNode" eSuperTypes="#//LeafOrInnerNode">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="InnerNodeData" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//LeafOrInnerNode" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="LeafNode" eSuperTypes="#//LeafOrInnerNode">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="LeafNodeData" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="LeafOrInnerNode" abstract="true" eSuperTypes="#//Node"/>
</ecore:EPackage>
Previous Topic:Emf->Xsd->Java code to serialize deserialize xml
Next Topic:When is a resource created in the workspace or a file?
Goto Forum:
  


Current Time: Wed Oct 16 06:03:07 GMT 2019

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

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

Back to the top