Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Re-using OutlineTreeProvider??
Re-using OutlineTreeProvider?? [message #780601] Wed, 18 January 2012 18:07 Go to next message
Romain  Aïssat is currently offline Romain AïssatFriend
Messages: 16
Registered: June 2011
Junior Member
Hi all,

Let's suppose I have two Dsl LangA and LangB of this kind :

A returns A : // entry rule for LangA
    Afeature1 = ARuleForFeature1
    Afeature2 = ARuleForFeature2
             ...
    AfeatureN = ARuleForFeatureN;


import 'blablabla/LangA.ecore' as LangA

B returns B :
    Bfeature1 = BRuleForFeature1
             ...
    a = [LangA::A]
             ...
    BfeatureM = BRuleForFeatureM;


My problem is that I'd like to display, in the outline view for LangB, the same datas for the feature a (of type A) as in the outline view for an object of type A in LangA.

So I could rewrite the necessary code in the LangBOutlineTreeProvider, but i'd like to know if there is a way to re-use what was made for the LangAOutlineTreeProvider.

I don't know if I made myself clear...

thanks in advance, Romain
Re: Re-using OutlineTreeProvider?? [message #780672 is a reply to message #780601] Wed, 18 January 2012 23:16 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You could inherit from the outline tree provider of langA or
alternativels grab the injector of langA by means of the
IResourceUiServiceRegistry and use it to get an instance of the outline
tree provider in langB.

Am 18.01.12 19:07, schrieb Romain ïssat:
> Hi all,
>
> Let's suppose I have two Dsl LangA and LangB of this kind :
>
> A returns A : // entry rule for LangA
> Afeature1 = ARuleForFeature1
> Afeature2 = ARuleForFeature2
> ...
> AfeatureN = ARuleForFeatureN;
>
> import 'blablabla/LangA.ecore' as LangA
>
> B returns B :
> Bfeature1 = BRuleForFeature1
> ...
> a = [LangA::A]
> ...
> BfeatureM = BRuleForFeatureM;
>
> My problem is that I'd like to display, in the outline view for LangB,
> the same datas for the feature a (of type A) as in the outline view for
> an object of type A in LangA.
>
> So I could rewrite the necessary code in the LangBOutlineTreeProvider,
> but i'd like to know if there is a way to re-use what was made for the
> LangAOutlineTreeProvider.
>
> I don't know if I made myself clear...
>
> thanks in advance, Romain


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Re-using OutlineTreeProvider?? [message #780849 is a reply to message #780672] Thu, 19 January 2012 15:54 Go to previous message
Romain  Aïssat is currently offline Romain AïssatFriend
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 :/
Previous Topic:how to extract STRING content?
Next Topic:Maven configuration for Xtext
Goto Forum:
  


Current Time: Thu Apr 25 14:13:51 GMT 2024

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

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

Back to the top