The widget to which a script is attached can be accessed in the script via widget object. It is the controller(or EditPart in GEF) of the widget. widget object provided the methods to get or set any of its properties, store external objects or provide special methods for a particular widget.
The widget controller of the display is accessible in all scripts as display object. To get the controller of any widget in the display, you can call its method getWidget(name). For example:
display.getWidget("myLabel").setPropertyValue("x", 20); //set x position of the widget myLabel to 20.
Container widgets includes Display, Grouping Container, Linking Container and Tabbed Container.
Any widget that has PV Name
property is PV widget.
For example, Text Update, Combo Box, XY Graph and so on.
Some widget may have special methods. See the document for each widget.
public java.lang.Object getPropertyValue(java.lang.String prop_id)
prop_id
- the property id. In most cases, it is the lower case of the property name.
var x = widget.getPropertyValue("x"); //get x position of the widget
public void setPropertyValue(java.lang.String prop_id, java.lang.Object value)
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 Typewidget.setPropertyValue("x", 20); //set x position of the widget to 20.
public void setPropertyValue(java.lang.String prop_id, java.lang.Object value, boolean forceFire)
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.widget.setPropertyValue( "opi_file", widget.getPropertyValue("opi_file"), true); //reload OPI in linking container.
public void setExternalObject(java.lang.String name, java.lang.Object var)
name
- the name of the object.var
- the object.public java.lang.Object getExternalObject(java.lang.String name)
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(widget.getExternalObject(flagName) == null){ widget.setExternalObject(flagName, false); } var b = widget.getExternalObject(flagName); if(ValueUtil.getDouble(pvs[0].getValue()) > 80){ if( b == false){ widget.setExternalObject(flagName, true); MessageDialog.openWarning( null, "Warning", "The temperature you set is too high!"); } }else if (b == true){ widget.setExternalObject(flagName, false); }
public void executeAction(int index)
index
- the index of the action in the actions list.public AbstractBaseEditPart getChild(java.lang.String name)
name
- the name of the child widget
var child = widget.getChild("gauge_2"); //get the gauge widget whose name is gauge_2 child.setPropertyValue("enable", false); //child is a widget
public AbstractBaseEditPart getWidget(java.lang.String name)
name
- the name of the widget which is a descendant of the container
var gauge2 = widget.getWidget("gauge_2"); //get the gauge widget whose name is gauge_2 gauge2.setPropertyValue("enable", false); //child is a widget
public void addChild(org.csstudio.opibuilder.model.AbstractWidgetModel widgetModel)
widgetModel
- model of the widget to be added.WidgetUtil.createWidgetModel(String)
public void addChildToRight(org.csstudio.opibuilder.model.AbstractWidgetModel widgetModel)
widgetModel
- model of the widget to be added.WidgetUtil.createWidgetModel(String)
public void addChildToBottom(org.csstudio.opibuilder.model.AbstractWidgetModel widgetModel)
widgetModel
- model of the widget to be added.WidgetUtil.createWidgetModel(String)
public void removeChildByName(java.lang.String widgetName)
widgetName
- name of the widget.
java.lang.RuntimeException
- if the widget name does not exist.public void removeAllChildren()
public PV getPV()
PV Name
property.
It is same as calling getPV("pv_name")
.
PV Name
property.
null if PV Name is not configured for this widget.importPackage(Packages.org.csstudio.opibuilder.scriptUtil); var pv = widget.getPV(); var value = PVUtil.getDouble(pv); //Get its double value
public PV getPV(java.lang.String pvPropId)
pvPropId
- the PV property id.
For example, pv_name
, trace_0_y_pv
for XY Graph.
public Object getValue()
public void setValue(Object value)
value
- the value to be set.
It must be compatible with the widget.
For example, a boolean widget only accept boolean or number.
java.lang.RuntimeException
- if the type of the value is not an acceptable type.