use of eu.esdihumboldt.hale.ui.util.groovy.ast.viewer.ASTViewer in project hale by halestudio.
the class GroovyASTTray method createContents.
@Override
protected Control createContents(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(page);
final ASTViewer viewer = new ASTViewer(page, groovyViewer);
GridDataFactory.fillDefaults().grab(true, true).hint(400, SWT.DEFAULT).applyTo(viewer.getControl());
if (groovyViewer != null) {
// current AST
try {
GroovyAST ast = groovyViewer.getCompiled().get();
if (ast != null) {
viewer.setInput(ast.getNodes());
viewer.getTreeViewer().expandAll();
} else {
viewer.setInput(null);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// listen to AST changes
final IPropertyChangeListener listener = new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (CompilingSourceViewer.PROPERTY_COMPILED.equals(event.getProperty())) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (event.getNewValue() instanceof GroovyAST) {
viewer.setInput(((GroovyAST) event.getNewValue()).getNodes());
viewer.getTreeViewer().expandAll();
} else {
viewer.setInput(null);
}
}
});
}
}
};
groovyViewer.addPropertyChangeListener(listener);
// ensure listener is removed
page.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
groovyViewer.removePropertyChangeListener(listener);
}
});
}
return page;
}
Aggregations