Home » Modeling » TMF (Xtext) » Creating an Outline
|
Re: Creating an Outline [message #1037653 is a reply to message #1030673] |
Tue, 09 April 2013 21:20 |
Annika Wießgügel 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
And again i have to state that the documentation is quite difficult to understand for beginners which may not have 20 years of experience...
Greetings,
Annika
|
|
|
Re: Creating an Outline [message #1037753 is a reply to message #1037653] |
Wed, 10 April 2013 01:02 |
Steve Kallestad Messages: 62 Registered: March 2013 |
Member |
|
|
Hi Annika - I'm pretty new at this myself.
For images, I've found the easiest way is this (in MyDSLOutlineTreeProvider.class):
@Inject
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 build.properties in plugin.xml as follows:
bin.includes = META-INF/,\
.,\
plugin.xml,\
icons/
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) {
if(!(groupAlreadyCreated)){
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
|
|
| |
Goto Forum:
Current Time: Fri Apr 19 11:29:22 GMT 2024
Powered by FUDForum. Page generated in 0.02176 seconds
|