FileDocCategorySizeDatePackage
Lesson2.javaAPI DocExample3098Thu Feb 17 20:00:56 GMT 2000com.togethersoft.modules.tutorial

Lesson2.java

/*----------------------------------------------------------------------------
Copyright (c)2000 TogetherSoft LLC. Patents pending. All rights reserved.
----------------------------------------------------------------------------*/

package com.togethersoft.modules.tutorial;

import com.togethersoft.openapi.ide.IdeContext;
import com.togethersoft.openapi.ide.IdeScript;
import com.togethersoft.openapi.ide.window.IdeWindowManager;
import com.togethersoft.openapi.ide.window.IdeWindowManagerAccess;
import com.togethersoft.openapi.ide.message.IdeMessageManagerAccess;
import com.togethersoft.openapi.ide.project.IdeProjectManagerAccess;
import com.togethersoft.openapi.ide.message.IdeMessageType;
import com.togethersoft.openapi.rwi.RwiProperty;
import com.togethersoft.openapi.rwi.RwiElement;

/**
 * This script goes through the selection and outputs the names and shapetypes of elements.
 * The shapetype property is one of the most important properties in RWI - you will see how
 * it is used in the next lessons. For now it is useful just to run this script several times to see
 * the shapetypes of the elements in a diagram. See RwiProperty interface description in the API docs for information about
 * RwiProperty.SHAPE_TYPE property.
 * @author TogetherSoft LLC
 */
public class Lesson2 implements IdeScript {
    public void run(IdeContext context) {
        IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson2 script: started");
        //checking if project is opened.
        if (IdeProjectManagerAccess.getProjectManager().getActiveProject() == null) {
            IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL, "No open project");
            IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson2 script: finished");
            return;
        }
        //now let's work with the selection.
        //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, "Lesson2 script: finished");
            return;
        }
        IdeMessageManagerAccess.getMessageManager().setPaneVisible(true); //making the message pane visible
        IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Selection contains the following elements:");
        //iterating the selection
        for (int i = 0; i < selectedRwiElements.length; i++) {
            RwiElement rwiElement = selectedRwiElements[i];
            IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,
                "ShapeType: " + rwiElement.getProperty(RwiProperty.SHAPE_TYPE) + ", full name: " +
                rwiElement.getProperty(RwiProperty.FULL_NAME));
        }
        IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson2 script: finished");
    }
}