Search in sources :

Example 21 with IErlFunction

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();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) IErlElement(org.erlide.engine.model.IErlElement) CallHierarchyView(org.erlide.ui.views.CallHierarchyView) ErlModelException(org.erlide.engine.model.ErlModelException) AsyncCaller(org.erlide.ui.jinterface.AsyncCaller) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) RpcFuture(org.erlide.runtime.rpc.RpcFuture) PartInitException(org.eclipse.ui.PartInitException) FunctionRef(org.erlide.engine.model.erlang.FunctionRef)

Example 22 with IErlFunction

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));
        }
    }
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PartInitException(org.eclipse.ui.PartInitException) ToolItem(org.eclipse.swt.widgets.ToolItem)

Aggregations

IErlFunction (org.erlide.engine.model.erlang.IErlFunction)22 IErlModule (org.erlide.engine.model.root.IErlModule)7 IErlElement (org.erlide.engine.model.IErlElement)6 ISelection (org.eclipse.jface.viewers.ISelection)5 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)5 ErlModelException (org.erlide.engine.model.ErlModelException)5 ErlangFunction (org.erlide.engine.model.erlang.ErlangFunction)4 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)4 TracePattern (org.erlide.tracing.core.mvc.model.TracePattern)4 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)3 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)3 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 PartInitException (org.eclipse.ui.PartInitException)2 IErlModel (org.erlide.engine.model.root.IErlModel)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1