Access Widget in Script

widgetController

The widget to which a script is attached can be accessed in the script via widgetController object. widgetController object provided the methods to get or set any of its properties, host external objects or special methods to a speific widget.

Common methods to all widgets

Common methods to all container widgets

Container widgets includes Display, Grouping Container, Linking Container and Tabbed Container.

getPropertyValue

public java.lang.Object getPropertyValue(java.lang.String prop_id)
Get property value of the widget.
Parameters:
prop_id - the property id. In most cases, it is the lower case of the property name.
Returns:
the property value.
Example:
var x = widgetController.getPropertyValue("x"); //get x position of the widget

setPropertyValue

public void setPropertyValue(java.lang.String prop_id,
                             java.lang.Object value)
Set the property value of the widget.

Parameters:
prop_id - the property id. In most cases, it is the lower case of the property name.
value - the value. It must be the allowed input type corresponding to the property type. See Property Type
Example:
widgetController.setPropertyValue("x", 20); //set x position of the widget to 20.

setPropertyValue

public void setPropertyValue(java.lang.String prop_id,
                             java.lang.Object value,
                             boolean forceFire)
Set the property value of the widget.

Parameters:
prop_id - the property id.
value - the value.
forceFire - If true, the property will be set again even if the new value is same as old value. If false and the new value is same as the old value, it will be ignored.
Example:
widgetController.setPropertyValue(
	"opi_file", widgetController.getPropertyValue("opi_file"), true); //reload OPI in linking container.

setExternalObject

public void setExternalObject(java.lang.String name,
                              java.lang.Object var)
Add/modify an external object from javascript.

Parameters:
name - the name of the object.
var - the object.

getExternalObject

public java.lang.Object getExternalObject(java.lang.String name)
Get the external object by name.

Returns:
the external object. null if no such an object was set before.
Example:

This is an example which uses these two methods to remember if the dialog has been poped before.

importPackage(Packages.org.eclipse.jface.dialogs);
importPackage(Packages.org.csstudio.platform.data);
importPackage(Packages.java.lang);

var flagName = "popped";

if(widgetController.getExternalObject(flagName) == null){
	widgetController.setExternalObject(flagName, false);	
}

var b = widgetController.getExternalObject(flagName);

if(ValueUtil.getDouble(pvArray[0].getValue()) > 80){		
		if( b == false){
			widgetController.setExternalObject(flagName, true);
			MessageDialog.openWarning(
				null, "Warning", "The temperature you set is too high!");
		}
		
}else if (b == true){
	widgetController.setExternalObject(flagName, false);
}

executeAction

public void executeAction(int index)
Run a widget action which is attached to the widget.

Parameters:
index - the index of the action in the actions list.

Common methods to all container widgets


getChild

public AbstractBaseEditPart getChild(java.lang.String name)
Get a child of this container by name.

Parameters:
name - the name of the child widget
Returns:
the widgetController of the child. Or null if the widget doesn't exist.
Example:
var child = widgetController.getChild("gauge_2"); //get the gauge widget whose name is gauge_2
child.setPropertyValue("enable", false); //child is a widgetController