Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Creating an Outline
Creating an Outline [message #1030673] Sun, 31 March 2013 15:05 Go to next message
Annika Wießgügel is currently offline Annika WießgügelFriend
Messages: 11
Registered: January 2013
Junior Member
It's me again, this time having problems writing an OutlineTreeProvider for our Editor.
I already wrote a LabelProvider, but now i'm struggeling with a class extending DefaultOutlineTreeProvider. I already read the documentation and searched for tutorials that are not out of date. I still don't know what to do, since the documentation only seems to cover simple changes (or i'm too unexperienced to get it right) and nearly all tutorials deal with the old way of outlinewriting. The only thing i managed to to is writing the _isLeaf() method for my outline.

Perhaps you could help me with my Problem:

As default, all nodes lie beneath each other, as the picture shows.
Now i want to
1. Add Nodes that don't correspond to the grammar, at a certain place in the outline.(as default-Packages)
2. Give hierarchy to the outline, sorting everything into packages. Therefore i need to "put" everything exept Package-Node into child nodes of Packages.

The outline in the picture should look like:

Note: Changing the grammar is no possible option!

Is this possible with DefaultOutlineProvider and how is it done? I'd be happy with some code snippets, since i don't really know how to work with _createNode and _createChildren.
Or is this done by writing Filter and Sorter?

Re: Creating an Outline [message #1037653 is a reply to message #1030673] Tue, 09 April 2013 21:20 Go to previous messageGo to next message
Annika Wießgügel is currently offline Annika WießgügelFriend
Messages: 11
Registered: January 2013
Junior Member
So, 6k views and not one answer... sad.
I suppose those were 6000 other people who did not really knot how to change the outline.

After two weeks of trying, editing, saving, starting and retrying i found out a way to influence the Outline the way i wanted it.
I think its best to share it, even if it may not be the best way to do it:

I wrote the _createChildren method new, iterating over my Model. Since my top level node on being created already created all other nodes, i did a workaround by creating an AbstractOutlineNode for it. (i did this by writing AbstractOutlineNode name = new AbstractOutlineNode(parameters){ }; ,don't really know if it's the right way, but anyway it works fine.)
The next thing i noticed is that simply call "createNode(...)" for an Element is not the way to change the outline the way i wanted it.
I had to write EObjectNode name = new EObjectNode(parameters), only then could I put some childnodes there. That was the hardest part to figure out since there is the method createEObjectNode which i tried to use and which did not work. You can then reference to the Node by its name.
For Some Nodes i wanted to add new childnodes that don't respond to parts of the grammar, so I did another _createNode(IOutlineNode parentNode, GrammarElement elementForWhichtheNodeShouldBeCreated). There i also created an EObjectNode and added an AbstractOutlineNode.
For alle this custom images can be used by using swt.

I hope i could help everyone who looks at this in search of an answer on how to create a certain outline. As I already said, i'm a beginner and figured it out all by myself, so it may not be the right or best way to do it. My ouline, however, now looks as it should Smile

And again i have to state that the documentation is quite difficult to understand for beginners which may not have 20 years of experience...



Re: Creating an Outline [message #1037753 is a reply to message #1037653] Wed, 10 April 2013 01:02 Go to previous messageGo to next message
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
Hi Annika - I'm pretty new at this myself.

For images, I've found the easiest way is this (in MyDSLOutlineTreeProvider.class):
	private IImageHelper imageHelper;

	protected Image _image(MyType o) {
		return imageHelper.getImage("cog.png");

The _image function is called for each grammar type that's displayed on the outline view, so for each type, simply declare a new function. The actual image files, I placed in my (new) icons directory. and I edited the in plugin.xml as follows:
bin.includes = META-INF/,\

From what I've gathered, a series of polymorphic functions will be called to build the tree nodes if they exist, otherwise a default nodebuilder is called:
	protected void _createChildren(IOutlineNode parentNode, MyCustomType rootElement) {

I've used that structure to eliminate a few items from my outline (abstractions). This code eliminates the in-between elements:
	protected void _createChildren(IOutlineNode parentNode, MyType rootElement) {

		for (EObject content : rootElement.eContents()) {
			for(EObject grandchild : content.eContents()){
				createNode(parentNode, grandchild);

I imagine inserting extra nodes is really kind of the opposite of this function. Instead of skipping a layer, add an extra one. Something like
protected void _createChildren(IOutlineNode parentNode, MyType rootElement) {
        EObject gropuObject = new EObject(...);
        EObjectNode groupNode = new EObjectNode(groupObject, parentNode, getImage("group.png"), "My Grouping", true);
    } else {
        EObjectNode groupNode = getGroupNode();
    createNode(groupNode, rootElement);

I know, I know... Too little, too late... but hey... now you have 6001 views Smile
Re: Creating an Outline [message #1037961 is a reply to message #1030673] Wed, 10 April 2013 08:24 Go to previous message
Annika Wießgügel is currently offline Annika WießgügelFriend
Messages: 11
Registered: January 2013
Junior Member
Hi Steve,

thanks for your answer anyway Smile

I did the images a bit different, by injecting my SyntaxLabelProvider for Elements that are part of my model. For Nodes that are not part of my model i did it by writing
Image name = ImageDescriptor.createFromURL( 
				getClass().getResource("realativePathtoImage (normally /icons/name)")).createImage();

Then i can add the image to my nodes by name.

Our grammar was quite strange so iterating over the rootElement or root.getChildren was not really the way to do it. Anyway I think my workaround was ok.


Previous Topic:Support for refactoring in EmbeddedEditor
Next Topic:Referring to user-defined variables from Xbase expressions
Goto Forum:

Current Time: Wed Jan 22 04:34:09 GMT 2020

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

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

Back to the top