Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Outline Tree Provider
Outline Tree Provider [message #720463] Tue, 30 August 2011 16:09 Go to next message
David Struck is currently offline David StruckFriend
Messages: 29
Registered: July 2010
Junior Member
Hi all, I'm just starting out with Xtext and had a question about how to build a custom tree in the Outline view. I'm starting with one of the grammars I found in the online Xtext documentation:

grammar org.xtext.example.stateMachine.FSM with org.eclipse.xtext.common.Terminals

generate fSM "[link removed]"

Statemachine :
   'events'
      (events+=Event)+
   'end'
   ('resetEvents'
      (resetEvents+=[Event])+
   'end')?
   'commands'
      (commands+=Command)+
   'end'
   (states+=State)+;
  
 Event :
   (isResetting?='resetting')? name=ID code=ID;
  
 Command :
   name=ID code=ID;
  
 State :
   'state' name=ID
      ('actions' '{' (actions+=[Command])+ '}')?
      (transitions+=Transition)*
   'end';
  
 Transition :
   event=[Event] '=>' state=[State]; 


(Note where it says [link removed] -- that was a namespace I had to remove since the forum rules don't allow me to use a link until I've posted more than 5 messages.)

When I run the MWE2 Workflow run configuration, I end up with a class named FSMOutlineTreeProvider that extends DefaultOutlineTreeProvider. Additionally, I have an EMF object named Statemachine with four getters: getEvents, getResetEvents, getCommands, and getStates.

As a first pass, I want to create a tree that has three "folder" nodes, one each for Events, Commands, and States. The folder nodes would then each have the relevant EMF objects (Events, Commands, States) as children. If I override _createChildren in FSMOutlineTreeProvider like this:

	protected void _createChildren(DocumentRootNode parentNode, Statemachine statemachine) {
		for(Event event : statemachine.getEvents()) {
			createNode(parentNode, event);
		}
		for(Command command : statemachine.getCommands()) {
			createNode(parentNode, command);
		}
		for(State state : statemachine.getStates()) {
			createNode(parentNode, state);
		}
	}


I get an Outline tree with all the Events, Commands, and States listed in a row as sibling nodes. How do I add an intermediate level so that Events are held under a parent node named "Events", etc.?

Thanks,

David
Re: Outline Tree Provider [message #720753 is a reply to message #720463] Wed, 31 August 2011 08:04 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Have a look at
org.eclipse.xtext.ui.editor.outline.impl.EStructuralFeatureNode

org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider.createEStructuralFeatureNode(IOutlineNode,
EObject, EStructuralFeature, Image, Object, boolean)
helbs you create one.

We use it in several of our languages, e.g. MWE2, Xtend2, if you need
examples.

Am 30.08.11 18:09, schrieb David Struck:
> Hi all, I'm just starting out with Xtext and had a question about how to
> build a custom tree in the Outline view. I'm starting with one of the
> grammars I found in the online Xtext documentation:
>
>
> grammar org.xtext.example.stateMachine.FSM with
> org.eclipse.xtext.common.Terminals
>
> generate fSM "[link removed]"
>
> Statemachine :
> 'events'
> (events+=Event)+
> 'end'
> ('resetEvents'
> (resetEvents+=[Event])+
> 'end')?
> 'commands'
> (commands+=Command)+
> 'end'
> (states+=State)+;
>
> Event :
> (isResetting?='resetting')? name=ID code=ID;
>
> Command :
> name=ID code=ID;
>
> State :
> 'state' name=ID
> ('actions' '{' (actions+=[Command])+ '}')?
> (transitions+=Transition)*
> 'end';
>
> Transition :
> event=[Event] '=>' state=[State];
>
> (Note where it says [link removed] -- that was a namespace I had to
> remove since the forum rules don't allow me to use a link until I've
> posted more than 5 messages.)
>
> When I run the MWE2 Workflow run configuration, I end up with a class
> named FSMOutlineTreeProvider that extends DefaultOutlineTreeProvider.
> Additionally, I have an EMF object named Statemachine with four getters:
> getEvents, getResetEvents, getCommands, and getStates.
>
> As a first pass, I want to create a tree that has three "folder" nodes,
> one each for Events, Commands, and States. The folder nodes would then
> each have the relevant EMF objects (Events, Commands, States) as
> children. If I override _createChildren in FSMOutlineTreeProvider like
> this:
>
>
> protected void _createChildren(DocumentRootNode parentNode, Statemachine
> statemachine) {
> for(Event event : statemachine.getEvents()) {
> createNode(parentNode, event);
> }
> for(Command command : statemachine.getCommands()) {
> createNode(parentNode, command);
> }
> for(State state : statemachine.getStates()) {
> createNode(parentNode, state);
> }
> }
>
>
> I get an Outline tree with all the Events, Commands, and States listed
> in a row as sibling nodes. How do I add an intermediate level so that
> Events are held under a parent node named "Events", etc.?
>
> Thanks,
>
> David


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


---
Get professional support from the Xtext committers at www.typefox.io
Re: Outline Tree Provider [message #899273 is a reply to message #720753] Tue, 31 July 2012 10:03 Go to previous message
Latha Shankara is currently offline Latha ShankaraFriend
Messages: 33
Registered: June 2012
Member
Hi,

I have a similar scenario like as David. I have followed Jan's suggestion of using createEStructuralFeatureNode() method and was able to create node'Events' for events.

The problem is, now the individual events appear directly under the "Statemachine" node as well as under "Events" node which I have created. But I want the individual events to be displayed only under the "Events" node and not under "Statemachine" node.

Could anyone please help me? And let me know where I might have gone wrong.

Thanks,
Latha
Previous Topic:Ecore model generation - merge custom and generated java code
Next Topic:NPE during serializing
Goto Forum:
  


Current Time: Sun Sep 27 07:26:02 GMT 2020

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

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

Back to the top