FileDocCategorySizeDatePackage
ShowCallTree.javaAPI DocExample22345Thu Feb 17 20:00:56 GMT 2000com.togethersoft.modules.showcalltree

ShowCallTree

public class ShowCallTree extends Object implements com.togethersoft.openapi.ide.IdeStartup, com.togethersoft.openapi.ide.IdeScript
This sample script shows the call tree of the selected operation. The list of method calls done within selected operation is displayed as a treeview in the separate tab of the bottom pane. Each call to a method is represented with a node. Each call to a method with availale source file is displayed as an expandable node, if there are calls made from this method. Selecting a line with such method also positions text editor to it. The treeview is implemented as JTree with redefined cell renderer component.
author
TogetherSoft LLC

Fields Summary
private com.togethersoft.openapi.ide.command.IdeCommandItem
myItem
Constructors Summary
Methods Summary
public voidautorun()
This method is called at start up time and menu item initialization is put here, so that the script would also be available from elements' context menu.

        IdeCommandManager commandManager = IdeCommandManagerAccess.getCommandManager();
        // create a command listener with instance of anonymous inner class
        // to easily implement event processing
        myItem = commandManager.createItem("CallTreeItem",
            new IdeCommandConstraints("context = element, shapeType = Operation, location = popupMenu, parent = Scripts"), new IdeCommandListener() {
                public void checkStatus(IdeCommandEvent event) {
                    // make the menu item enabled or disabled depending on context
                    IdeContext context = event.getElementContext();
                    if (context != null) { // the command can only be command executed on selected element
                        RwiElement[] selectedRwiElements = context.getRwiElements();
                        if (selectedRwiElements != null) {
                            for (int i = 0; i < selectedRwiElements.length; i++) {
                                SciElement selectedElement = (SciElement)selectedRwiElements[i].getCodeElement();
                                // make the command enabled only for non-abstract methods
                                if (selectedElement != null && selectedElement instanceof SciOperation &&
                                    !((SciOperation)selectedElement).hasProperty(SciProperty.ABSTRACT)) {
                                        myItem.setEnabled(true);
                                        return;
                                }
                            }
                        }
                    }
                    myItem.setEnabled(false);
                }
                public void actionPerformed(IdeCommandEvent event) {
                    // actually process the command
                    (new ShowCallTree()).run(event.getElementContext());
                }
            });
        myItem.setText("Show call tree"); // text to be displayed as menu command
    
public voidrun(com.togethersoft.openapi.ide.IdeContext context)

        // check if project is open
        if (IdeProjectManagerAccess.getProjectManager().getActiveProject() == null) {
            IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL, "No open project.");
            return;
        }
        // the script can only be executed with one or more selected elements
        RwiElement[] selectedRwiElements = context.getRwiElements();
        if (selectedRwiElements == null || selectedRwiElements.length == 0) {
            IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL, "No selection was made.");
            return;
        }
        for (int i = 0; i < selectedRwiElements.length; i++) {
            Object selectedElement = selectedRwiElements[i].getCodeElement();
            if (selectedElement == null) { // does this element contain any code?
                IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR, "Operation not found.");
                continue;
            }
            if (!(selectedElement instanceof SciOperation)) { // is the element an operator?
                IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR, "Selected object isn't an operation");
                continue;
            }
            if (((SciOperation)selectedElement).hasProperty(SciProperty.ABSTRACT)) { // is the operation not abstract?
                IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR, "Selected operation is abstract");
                continue;
            }
            new OperationPage((SciOperation)selectedElement);
        }