Home » Modeling » TMF (Xtext) » Outline Tree Provider
Outline Tree Provider [message #720463] |
Tue, 30 August 2011 16:09 |
David Struck 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 |
Jan Koehnlein 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
|
|
| |
Goto Forum:
Current Time: Tue Apr 23 08:35:12 GMT 2024
Powered by FUDForum. Page generated in 0.02795 seconds
|