use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class CallHierarchyAction method run.
@Override
public void run() {
if (module == null) {
return;
}
final IErlElement el = editor.getElementAt(editor.getViewer().getSelectedRange().x, false);
IErlFunction f = null;
if (el instanceof IErlFunction) {
f = (IErlFunction) el;
} else if (el instanceof IErlFunctionClause) {
f = (IErlFunction) el.getParent();
}
if (f == null) {
return;
}
String name = module.getName();
final int i = name.lastIndexOf('.');
if (i > 0) {
name = name.substring(0, i);
}
final FunctionRef ref = new FunctionRef(name, f.getFunctionName(), f.getArity());
final IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final IWorkbenchPage page = dw.getActivePage();
final AsyncCaller<CallHierarchyView> ac = new AsyncCaller<CallHierarchyView>(100) {
@Override
protected CallHierarchyView prepare() {
try {
final IViewPart p = page.showView("org.erlide.ui.callhierarchy");
final CallHierarchyView cvh = p.getAdapter(CallHierarchyView.class);
if (cvh == null) {
return null;
}
cvh.setMessage("<searching... project " + ErlangEngine.getInstance().getModelUtilService().getProject(module).getName() + ">");
return cvh;
} catch (final PartInitException e) {
ErlLogger.error("could not open Call hierarchy view: ", e.getMessage());
return null;
}
}
@Override
protected RpcFuture call() throws BackendException {
final RpcFuture result = xrefService.addProject(ErlangEngine.getInstance().getModelUtilService().getProject(module));
return result;
}
@Override
protected void handleResult(final CallHierarchyView context, final RpcFuture result) {
page.activate(context);
try {
context.setRoot(ErlangEngine.getInstance().getModel().findFunction(ref));
} catch (final ErlModelException e) {
ErlLogger.error(e);
}
}
};
ac.run();
}
use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class CallHierarchyView method createPartControl.
@Override
public void createPartControl(final Composite parent) {
{
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
{
lblRoot = new Label(composite, SWT.NONE);
lblRoot.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
lblRoot.setText("<no function>");
}
{
final ToolBar toolBar = new ToolBar(composite, SWT.FLAT);
toolBar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
{
final ToolItem tltmRefresh = new ToolItem(toolBar, SWT.NONE);
tltmRefresh.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
xrefService.update();
treeViewer.refresh();
}
});
tltmRefresh.setText("refresh");
}
}
{
treeViewer = new TreeViewer(composite, SWT.NONE);
treeViewer.setLabelProvider(new ViewerLabelProvider());
treeViewer.setContentProvider(new TreeContentProvider());
tree = treeViewer.getTree();
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(final MouseEvent e) {
final TreeItem[] sel = tree.getSelection();
final IErlFunction el = (IErlFunction) sel[0].getData();
final boolean activateOnOpen = getSite() != null ? true : OpenStrategy.activateOnOpen();
try {
EditorUtility.openElementInEditor(el, activateOnOpen);
} catch (final PartInitException e1) {
ErlLogger.error(e1);
}
}
});
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 2, 1));
}
}
}
Aggregations