Type | Editor Scripting |
Jar File | EditorScripts.jar |
Applies to | editor |
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.
Layer ==> Container 1 ==> Child 1 ==> Child 2 ==> Container 2 ==> Child 3 ==> Child 4The
process(ServerWidget widget)
method will be called in this order:EditorScriptContext
class called context
. The user can use this object to: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()); }
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()); }
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); }
ScriptContext.setTab(int)
and ScriptContext.clearTab()
. Setting a tab to a value less or equal to zero is equivalent to clear the tab.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"); }
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;
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; }
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;
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 } }
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"); } }
String layerName; public void process(ServerLayer layer) { layerName = layer.getName(); }
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); } } }
public void process(ServerWidget widget) { int id = widget.getID(); context.echo("widget " + widget.getName() + " widget ID " + id); }
public void process(ServerWidget widget) { String widgetType = widget.getDefinition().getID(); context.echo("widget " + widget.getName() + " widget type: " + widgetType); }
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"); } }
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"); } }
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); } }
public void process(ServerLayer layer) { context.echo("layer " + layer.getName(), "blue"); } public void process(ServerWidget widget) { context.echo("widget " + widget.getName()); }
Copyright 2016-2017 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v2 licence