Home » Modeling » TMF (Xtext) » Re-using OutlineTreeProvider??
| |
Re: Re-using OutlineTreeProvider?? [message #780849 is a reply to message #780672] |
Thu, 19 January 2012 15:54 |
Romain Aïssat Messages: 16 Registered: June 2011 |
Junior Member |
|
|
Hi Jan, thanks for your answer.
I looked for the two ways you said but in vain.
I give here two dsl filling the roles :
This is a dsl allowing to represent persons :
grammar org.xtext.Person with org.eclipse.xtext.common.Terminals
generate person "http://www.xtext.org/Person"
Person returns Person :
'name' name = ID
'age' age = INT;
And this one, allowing to represent a parent and his children by re-using the previous dsl :
grammar org.xtext.Parent with org.eclipse.xtext.common.Terminals
generate parent "http://www.xtext.org/Parent"
import 'platform:/resource/org.xtext.person/src-gen/org/xtext/Person.ecore' as person
Parent returns Parent :
'id' identity = [person::Person]
'children' children += [person::Person] (',' children += [person::Person])*;
Here are my two outlineTreeProviders, the second one inheriting from the first :
public class PersonOutlineTreeProvider extends DefaultOutlineTreeProvider {
public Image getImage(){
return labelProvider.getImage(null);
}
public void _createNode(IOutlineNode parentNode, Person p){
if(p != null)
new EObjectNode(p,parentNode,getImage(),new StyledString("Person"),false);
}
public void _createChildren(IOutlineNode parentNode, Person p){
if(p != null){
if(p.getName() != null)
new EObjectNode(p,parentNode,getImage(),new StyledString("name : " + p.getName()),true);
new EObjectNode(p,parentNode,getImage(),new StyledString("age : " + String.valueOf(p.getAge())),true);
}
}
}
public class ParentOutlineTreeProvider extends PersonOutlineTreeProvider {
public void _createNode(IOutlineNode parentNode, Parent p){
if(p != null)
new EObjectNode(p,parentNode,getImage(),new StyledString("Parent"),false);
}
public void _createChildren(IOutlineNode parentNode, Parent p){
if(p.getIdentity() != null)
createNode(parentNode, p.getIdentity());
if(!p.getChildren().isEmpty()){
EObjectNode childrenNode = new EObjectNode(p,parentNode,getImage(),new StyledString("children"),false);
for(Person child : p.getChildren()){
createNode(childrenNode,child);
}
}
}
}
Now when editing a parent file (from the parent dsl), if I expand a "Parent" node, two nodes, labelled "Person" and "children", appear, and if i expand the new "children" node, a new node labelled "Person" appears. This is what is expected.
But if i expand the "Person" node, two subnodes labelled "Person" and "children" appear : the polymorphicDispatcher calls _createChildren(IOutlineNode parentNode, Parent p) instead of _createChildren(IOutlineNode parentNode, Person p) and I can't figure why.
So I tried the stupid way, aka not to make the parentOutlineTreeProvider inherit from the personOutlineTreeProvider and rewrite the two necessary methods _createNode(IOutlineNode parentNode, Person p) and _createChildren(IOutlineNode parentNode, Person p) in the ParentOutlineTreeProvider, thus the code is now :
public class ParentOutlineTreeProvider extends DefaultOutlineTreeProvider {
public Image getImage(){
return labelProvider.getImage(null);
}
public void _createNode(IOutlineNode parentNode, Parent p){
if(p != null)
new EObjectNode(p,parentNode,getImage(),new StyledString("Parent"),false);
}
public void _createChildren(IOutlineNode parentNode, Parent p){
if(p.getIdentity() != null)
createNode(parentNode, p.getIdentity());
if(!p.getChildren().isEmpty()){
EObjectNode childrenNode = new EObjectNode(p,parentNode,getImage(),new StyledString("children"),false);
for(Person child : p.getChildren()){
createNode(childrenNode,child);
}
}
}
public void _createNode(IOutlineNode parentNode, Person p){
if(p != null){
new EObjectNode(p,parentNode,getImage(),new StyledString("Person"),false);
}
}
public void _createChildren(IOutlineNode parentNode, Person p){
if(p != null){
if(p.getName() != null)
new EObjectNode(p,parentNode,getImage(),new StyledString("name : " + p.getName()),true);
new EObjectNode(p,parentNode,getImage(),new StyledString("age : " + String.valueOf(p.getAge())),true);
}
}
}
This results in the same behaviour...
Any idea??
Thanks in advance!
PS : I looked to the ResourceUiServiceRegistry but really don't know how to use it :/
|
|
|
Goto Forum:
Current Time: Thu Apr 25 14:13:51 GMT 2024
Powered by FUDForum. Page generated in 0.04193 seconds
|