Home
Categories
Dictionnary
Download
Project Details
Changes Log
Who We Are
FAQ
License

EditorScript Plugin


    1  Executing a Script
    2  Scripts interface
    3  Script concepts
       3.1  Order of operation
       3.2  Script Context
       3.3  Echoing messages
          3.3.1  Echoing simple messages
          3.3.2  Echoing messages with hyperlinks
          3.3.3  Tabulations
       3.4  Script Helper
       3.5  Printing in a File
       3.6  Accessing a Plugin
          3.6.1  Example
       3.7  Accessing an Editor extension
          3.7.1  Example
       3.8  Aborting a Script
       3.9  Local variables
       3.10  Imports
       3.11  Useful notions
          3.11.1  Getting the ID of a widget
          3.11.2  Getting the type of a widget
          3.11.3  Determination if a widget is a container
          3.11.4  Getting the parent of a widget
          3.11.5  Getting and Setting a property value
    4  Examples
    5  Editor Settings
    6  Notes

EditorScript
Type Editor Scripting
Jar File EditorScripts.jar
Applies to editor

The EditorScript Plugin allows to execute Scripts on the Editor using the Groovy scripting language.
These Scripts allows to navigate in one or several Definition Files and their Layers, and even modify their content programmatically.

Executing a Script

To execute a Script in the Editor, select Tools => Editor Scripting, and one of the two possible options:

Scripts interface

A Script must implement the EditorScript interface and can contain the following methods:

      public void start() {
      // called at the start of the Script
      }

      public void process(ServerLayer layer) {
      // called at the start of a Layer
      }

      public void process(ServerWidget widget) {
      // process a widget
      }

      public void endLayer() {
      // called at the end of a Layer
      }

      public void end() {
      // called at the end of the Script
      }

Note: All these methods have a default empty implementation, so you don't need to implement all of them, only those you need. You can also add your own methods if you wish.

Script concepts

Order of operation

Each Definition File tree will be visited following its structure. For example; for the following Definition File:
      Layer
      ==> Container 1
      ==> Child 1
      ==> Child 2
      ==> Container 2
      ==> Child 3
      ==> Child 4
The process(ServerWidget widget) method will be called in this order:
This means that you are sure that containers will be called before their children.

Script Context

The script always have access to an instance of the EditorScriptContext class called context. The user can use this object to:

Echoing messages

Echoing simple messages

The ScriptContext class has several methods allowing to echo messages. The simplest way to echo a message is by calling ScriptContext.echo(java.lang.String) (or ScriptContext.echo(java.lang.String, java.lang.String) for a message with a specific foreground). For example:

      public void process(ServerLayer layer) {
      context.echo("layer " + layer.getName(), "blue");
      }

      public void process(ServerWidget widget) {
      context.echo("widget " + widget.getName());
      }

It is also possible to echo a message with an hyperlink to the associated element in the Definition File tree in the Editor. To perfom this, use EditorScriptContext.echoWithLink(java.lang.String) or the EditorScriptContext.echoWithLink(java.lang.String, java.lang.String) for a message with a specific foreground). For example:

      public void process(ServerLayer layer) {
      context.echoWithLink("layer " + layer.getName(), "blue");
      }

      public void process(ServerWidget widget) {
      context.echoWithLink("widget " + widget.getName());
      }


Note that when using these methods in respectively the EditorScript.process(arinc661.server.model.core.ServerLayer) or EditorScript.process(arinc661.server.model.core.ServerWidget) methods will ensure to hyperlink to the associated Layer or Widget in the Definition File tree. If you want to hyperlink in another method, you should use the versions of these methods which define explicitely a Widget to link: EditorScriptContext.echoWithLink(java.lang.String, java.lang.String, arinc661.server.model.core.ServerWidget). For example:

      public void process(ServerWidget widget) {
      context.echoWithLink("widget " + widget.getName(), widget);
      }

Tabulations

By default, all messages will appear at the beginning of each line, without tabulations. It is possible to control tabulations by using the methods ScriptContext.setTab(int) and ScriptContext.clearTab(). Setting a tab to a value less or equal to zero is equivalent to clear the tab.

The tabulation will be used until a new tab command is issued in the Script.

Script Helper

The script always have access to an instance of the EditorScriptHelper class called helper. The user can use this object to ask the user for properties which can be used to configure the computing. For example the following script will ask for a name.

      String shortName;

      public void start() {
      shortName = helper.askForProperty("Short Name");
      }

Printing in a File

See PrintScript Plugin for information on how to save content in a text file, XML file, or Excel file[1] .

Accessing a Plugin

It is possible to access Plugins by the following code:
      Plugin plugin = helper.getPlugin("name_of_the_Plugin");

Note that you will have to add the following import for the Plugin interface:

      import org.mdi.plugins.Plugin;

Example

The following code access the UIProperties Plugin:
      import org.mdi.plugins.Plugin;
      import plugin.editor.uiprop.UIPropertiesPlugin;

      UIPropertiesPlugin uiPlugin uiPlugin = null;

      public void start() {
      Plugin plugin = helper.getPlugin("UIProperties");
      uiPlugin = (UIPropertiesPlugin)plugin;
      }

Accessing an Editor extension

If an extension has been installed for a layer in the Editor, it is possible to access it by the following code:
      EditorExtension extension = helper.getEditorExtension(layer, "name_of_the_extension");

This allows to use a Plugin associated EditorExtension for a Layer if this Plugin has installed an extension for the associated layer tab. Note that you will have to add the following import for the EditorExtension interface:

      import arinc661.appli.editor.engine.EditorExtension;

Example

For example, if the current Layer was associated in the Editor with an UCDSInterface, and you want to access the Layer UACDSInterface associated model, you can perform the following code:

      public void process(ServerLayer layer) {
      EditorExtension extension = helper.getEditorExtension(layer, "UACDS");
      if (extension != null) {
      UACDSExtension uacdsExtension = (UACDSExtension)extension;
      UACDSModel model = uacdsExtension.getUACDSModel();
      // do whatever you want to check the model
      }
      }

Aborting a Script

It is possible to abort the execution of a Script at any moment in ther Script itself by calling the ScriptContext.abort(java.lang.String) method. For example:

      String shortName;

      public void start() {
      shortName = helper.askForProperty("Short Name");
      if (shortName == null || shortName.isEmpty()) {
      context.abort("Incorrect parameter");
      }
      }

Local variables

Variables which are valid for all the Script life can be very simply defined as in other languages. For example, here we keep the name of the last encountered layer:

      String layerName;

      public void process(ServerLayer layer) {
      layerName = layer.getName();
      }

Imports

The plugin automaticaly add the following imports to the script:

Other imports should be added at the beginning of the script. For example:
      import java.awt.*;

      public void process(ServerLayer layer) {
      context.echo("widget " + layer.getName(), "blue");
      }

      public void process(ServerWidget widget) {
      String type = widget.getServerWidgetDefinition().getID();
      if (type.equals("A661_LABEL")) {
      String label = (String)widget.getPropertyValue("A661_STRING");
      long sizeX = (Long)widget.getPropertyValue("A661_SIZE_X");

      Dimension dim = context.getHelper().getStringBounds(widget, label);
      if (dim.width > sizeX) {
      context.warning("widget " + widget.getName() + "(" + widget.getID() + ") width too small, should be at least "+dim.width+", but is "+sizeX);
      }
      }
      }

Useful notions

Getting the ID of a widget

      public void process(ServerWidget widget) {
      int id = widget.getID();
      context.echo("widget " + widget.getName() + " widget ID " + id);
      }

Getting the type of a widget

      public void process(ServerWidget widget) {
      String widgetType = widget.getDefinition().getID();
      context.echo("widget " + widget.getName() + " widget type: " + widgetType);
      }

Determination if a widget is a container

      public void process(ServerWidget widget) {
      boolean isContainer = widget instanceof ServerContainer;
      if (isContainer) {
      ServerContainer cont = (ServerContainer)widget;
      context.echo("widget " + widget.getName() + " is a Container with " + cont.childCount() + " children");
      }
      }

Getting the parent of a widget

In the following code we get the parent of the widget (which can be another widget or the layer).
      public void process(ServerWidget widget) {
      ServerElement elt = widget.getParent();
      if (elt instanceof ServerWidget) {
      echo("Parent of " + widget.getName() + " is a Widget");
      // note that in that case the widget will be a Container, which means that the following code will work:
      // ServerContainer cont = (ServerContainer)parent;
      } else {
      echo("Parent of " + widget.getName() + " is the Layer");
      }
      }

Getting and Setting a property value

      public void process(ServerWidget widget) {
      String widgetType = widget.getDefinition().getID();
      if (widgetType.equals("A661_BASIC_CONTAINER") {
      int posX = helper.getPropertyValueAsInt(widget, "A661_POS_X");
      posX += 1000;
      helper.setParameter(widget, "A661_POS_X", posX);
      context.echo("widget " + widget.getName() + " new PosX: " + posX);
      }
      }

Examples

An example of a valid script could be:
      public void process(ServerLayer layer) {
      context.echo("layer " + layer.getName(), "blue");
      }

      public void process(ServerWidget widget) {
      context.echo("widget " + widget.getName());
      }

Editor Settings

This Plugin has the following Editor Settings:

Notes

  1. ^ Without the presence of the PrintScript Plugin, the EditorScript Plugin won't be able to save content

Category: editor Category: plugins Category: user

Copyright 2016 Dassault Aviation. All Rights Reserved. Documentation and source under the GPL v2 licence

Project Web Hosted by SourceForge.net Copyright 1999-2010 - Geeknet, Inc., All Rights Reserved About - Legal - Help