Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Customizing the outline
Customizing the outline [message #912290] Thu, 13 September 2012 09:19 Go to next message
Roberto Jimenez is currently offline Roberto JimenezFriend
Messages: 17
Registered: March 2012
Junior Member
How can a customize the outline??

I need it to get something like this with this objects:


if
AbstractElements
else if
AbstractElements


Object:

IfExp:
block=CondBlock ('else' blocks+=CondBlock)* ('else' defaultBlock=Block)?;

CondBlock:
name='if' cond=TerminalBoolExpression action=Block;

Block:
{Block}
name='{'
sta+=AbstractElement*
'}';


But what I get something like this:

if
unnamed
AbstractElement
unnamed



Someone can help me??


Thanks a lot
Re: Customizing the outline [message #912378 is a reply to message #912290] Thu, 13 September 2012 13:02 Go to previous messageGo to next message
Jens Kuenzer is currently offline Jens KuenzerFriend
Messages: 28
Registered: October 2009
Junior Member
I would not use the special member "name" for this.
It might be simpler to just customize the LabelProvider class.

For example to change the label of a conditional block you can try:
    String text(CondBlock ele) {
        return "If";
      }


I usually override the doGetText to get some more verbose defaults during development:
    @Override
    protected Object doGetText(Object element) {
            Object text = super.doGetText(element);
            String prefix = "";
            if(element instanceof EObject) {
                EObject e = (EObject) element;
                if(e.eContainingFeature()!=null) {
                    prefix = prefix + e.eContainingFeature().getName() + "="; 
                }
            }
            prefix = prefix + element.getClass().getSimpleName().replaceFirst("Impl$", "");
            if(text != null && text instanceof String) {
                return prefix +":"+text;
            } else {
                return prefix;
            }
    }


This is just meant as a starting point.
Re: Customizing the outline [message #912823 is a reply to message #912378] Fri, 14 September 2012 08:54 Go to previous messageGo to next message
Tu Do is currently offline Tu DoFriend
Messages: 21
Registered: August 2012
Junior Member
Hi Jens,

Where should I override doGetText() ? I tried to override in DefaultOutlineTreeProvider, but it does not work.
Re: Customizing the outline [message #912827 is a reply to message #912823] Fri, 14 September 2012 09:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

as said before the labels are ususally done in the Labelprovider - but not by overriding doGetText

String text(CondBlock ele) {
        return "If";
      }


you may find the dogettext in DefaultEObjectLabelProvider (superclass of MydslLabelProvider)

~Christian
Re: Customizing the outline [message #912845 is a reply to message #912827] Fri, 14 September 2012 09:28 Go to previous messageGo to next message
Jens Kuenzer is currently offline Jens KuenzerFriend
Messages: 28
Registered: October 2009
Junior Member
Maybe it was a little misleading to suggest the override of doGetText. It is not required in this case.
I meant this only as developing aid. I used this in several projects for a quick check of the results. I know there are other ways doing that, too.
Re: Customizing the outline [message #920840 is a reply to message #912845] Sun, 23 September 2012 14:07 Go to previous messageGo to next message
Roberto Jimenez is currently offline Roberto JimenezFriend
Messages: 17
Registered: March 2012
Junior Member
The text() method works, but I want to delete some nodes of the outline, but adding the children of this node to his parent.

I want just this:

if
element
if
element

But the blocks and the IfExp appears in my outline.

Any idea.
Re: Customizing the outline [message #920855 is a reply to message #920840] Sun, 23 September 2012 14:22 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi there are a lot of topics on the outline already the . Have a look
at the YourDslOutlineTreeProvider and adapt the code.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Previous Topic:Quickfix All
Next Topic:Python inspire language in Xtext?
Goto Forum:
  


Current Time: Sat Dec 20 21:02:24 GMT 2014

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

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