FileDocCategorySizeDatePackage
Lesson5.javaAPI DocExample4727Thu Feb 17 20:00:56 GMT 2000com.togethersoft.modules.tutorial

Lesson5

public class Lesson5 extends Object implements com.togethersoft.openapi.ide.IdeScript
This script shows the easiest way to include your scripts in popup menus for certain elements. This can be done by specifying a string "PopupMenuItem = true" in the script's manifest file (a file with the .def extension). By default, this script is "disabled" in the popup menus. To "enable" it, open the Lesson5.def file and uncomment the following line ";PopupMenuItem = true" (just remove the semicolon). After that restart Together, and you will see that all classes, interfaces, operations, and attributes now have a submenu "Scripts" containing the Lesson5 name. Using the "PopupMenuItem = true" is a great solution for those scripts that must appear in a popup menu for classes, interfaces, operations, and attributes, since it doesn't require to add _anything_ to the implementation of the script - all the work is done by Together. Moreover, you can enable the appearance of the script only for elements having the specified shapetype. To do this, uncomment the line ";PopupMenuItem = true" AND (for example) the line ";PopupConstraints = "shapeType=Operation"" in the .def file. This will make the script appear only for operations. The drawback of this manifest file-based registration approach is that you can't specify a different name of a menu (for example, "My menu" instead of "Scripts") or put any conditions on the appearance of the command (for example, you won't be able to make it disabled for public or void operations, or make it visible only for classes, or interfaces with no declared methods etc). All these features can be done using the functionality of com.togethersoft.openapi.ide.command package. Next lesson contains a sample of such a script. This script will write the name of the selected element in the message pane. When it is invoked via the "Scripts" pane, it can be applied to any element. If you uncomment the line "PopupMenuItem = true" in the .def file, it will be visible in the popup menus only for classes/interfaces/operations/attributes. (if you uncomment ";PopupConstraints = ..." line, it will be visible only for elements with the specified shapetype)
author
TogetherSoft LLC

Fields Summary
Constructors Summary
Methods Summary
public voidrun(com.togethersoft.openapi.ide.IdeContext context)

        IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson5 script: started");
        //checking if project is opened.
        if (IdeProjectManagerAccess.getProjectManager().getActiveProject() == null) {
            IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL, "No open project");
            IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson5 script: finished");
            return;
        }
        //the array of selected RwiElements
        RwiElement[] selectedRwiElements = context.getRwiElements();
        if (selectedRwiElements == null || selectedRwiElements.length == 0) {
            IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL, "No selection was made.");
            IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson5 script: finished");
            return;
        }
        if (selectedRwiElements.length > 1) {
            IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL, "Please select only one element");
            IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson5 script: finished");
            return;
        }
        RwiElement rwiElement = selectedRwiElements[0];
        IdeMessageManagerAccess.getMessageManager().setPaneVisible(true); //making the message pane visible
        IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,
            "Lesson5: the name of the element is " + rwiElement.getProperty(RwiProperty.NAME) +
            ". See the text of this script, it contains a description");
        IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson5 script: finished");