Change the outline, part 2: appendix

What if you really want to create virtual outline nodes? Just call the constructor of ContentOutlineNode directly, without passing through any IContentOutlineNodeFactory. You still need to be in one of the createNode method of the Transformer (MyDslTransformer), so you can insert the virtual node in the outline structure.
Suppose that we want to insert a node under each node that represent a FurnitureDeclaration, that display the line number of the element, just write something like this:

public ContentOutlineNode createNode(FurnitureDeclaration semanticNode,
                                                             ContentOutlineNode outlineParentNode)
   ContentOutlineNode node = super.newOutlineNode(semanticNode, outlineParentNode);
   //Retrieve the line number of the EObject.
   int line = NodeUtil.getNode(semanticNode).getLine();
   //Call the constructor directly.
   ContentOutlineNode fake = new ContentOutlineNode(""+line);
   return node;

And here are the virtual nodes:

Virtual outline nodes

Of course, if you click on one the virtual nodes, nothing happens because we didn’t give them any IRegion to link to the source code.
ContentOutlineNode has several constructors and setter methods to fully customize it. Also note that it holds a StyledString, a particular that will come in handy in a future post… ;).


About Luong

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s