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 org.csstudio.utility.pv.PV getPVByName(java.lang.String pvName)
pvName
- name of the PV.
public void setVar(java.lang.String varName, java.lang.Object varValue)
varName
- name of the variable.varValue
- value of the variable, which can be any type.public java.lang.Object getVar(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.getVar(flagName) == null){ widget.setVar(flagName, false); } var b = widget.getVar(flagName); if(ValueUtil.getDouble(pvs[0].getValue()) > 80){ if( b == false){ widget.setVar(flagName, true); MessageDialog.openWarning( null, "Warning", "The temperature you set is too high!"); } }else if (b == true){ widget.setVar(flagName, false); }
public java.lang.String getMacroValue(java.lang.String macroName)
macroName
- The name of the macro.
var macroValue = widget.getMacroValue("m1"); //get the macro value of "m1"
public void executeAction(int index)
index
- the index of the action in the actions list.public void setEnabled(boolean enable)
enable
- true if the widget should be enabled.public void setVisible(boolean visible)
enable
- true if the widget should be visible.public void setX(java.lang.Number x)
x
- x position in pixel which is relative to its parent.public void setY(java.lang.Number y)
y
- y position in pixel which is relative to its parent.public void setWidth(java.lang.Number width)
width
- width in pixel.public void setHeight(java.lang.Number height)
height
- height in pixel.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 removeChild(AbstractBaseEditPart child)
child
- the child widget.public void removeChild(int index)
index
- index of the child.public void removeAllChildren()
public void performAutosize()
public java.lang.Object getValue()
setValue(Object)
was called with a non Object[] input value, it
will return the value of its first child.getValue
in class AbstractBaseEditPart
public void setValue(java.lang.Object value)
setValue
in class AbstractBaseEditPart
value
- the value to be set. It must be the compatible type for the widget.
For example, a boolean widget only accept boolean or number.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.public void setValueInUIThread(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.