On the UI side we needed a way to present the AST tree and synchronize it with the statement that is being entered. One way to do it is add a view that would synchronized with editor, however drawback in this approach is not seeing the view when editor is maximized. What I wanted to achieve is something that Eclipse Compare editor offers - and editor which is split into two parts. I started looking at org.eclipse.compare code. It's pretty involved and had a lot things that I really didn't need. I took a closer look at our DSL editor that extends TextEditor and decided to play with createPartControl(Composite parent) method since this is where UI elements were build. The result was just what I needed.
What I ended up doing is shown here:
public void createPartControl(Composite parent) {
SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
sashForm.setLayout(new FillLayout());
super.createPartControl(sashForm);
new ASTComposite(sashForm, SWT.BORDER);
}
As you can see SashForm is used to achieve split pane. Top pane is where editor is added, and bottom is where any Composite goes, in my case it's a specialized Composite that has TreeViewer holding AST of the expression. Pretty simple and effective.
No comments:
Post a Comment