The <if> tag adds components to its parent component if a given condition is satisfied. If the condition is not satisfied, the components are not added.
Name | Description | Legal Values | Default |
eval |
The expression to evaluate. The expression must use the format described in Expression Syntax . This expression must return true or false. Note that this expression should NOT be enclosed in backticks. This is one case where the value must always be an expression, so backticks are not necessary. |
an expression returning true or false |
false |
The <if>tag contains a number of components to add to the parent container. The <if> tag may also optionally contain an <else> tag. The <else> tag contains a number of components to add the parent container if the eval condition is not satisfied.
It's important to understand that the <if> tag adds zero or more components to its parent container. Therefore, the if tag can only be used in places where one or more components could be added. Because of this constraint, the following layout is illegal:
<xmllayout>
<panel>
<if
eval="true">
<west>
<component id="DAG"/>
</west>
<center>
<component
id="TEXTEDIT"/>
</center>
</if>
</panel>
</xmllayout>
This layout is illegal for two reasons. First, components cannot be added directly to a panel. Second, the <west> and <center> tags do not define components, so they cannot appear inside an <if> tag.
This layout could be rewritten as:
<xmllayout>
<panel>
<west>
<if
eval="true">
<component id="DAG"/>
</if>
</west>
<center>
<if
eval="true">
<component
id="TEXTEDIT"/>
</if>
</center>
</panel>
</xmllayout>
The <if> tag may contain multiple tags. If the tag expression is true, all of these tags will be added to the parent component if the parent component allows multiple tags as well. A few tags (like <grid>, <box>, and <compactgrid>) allow multiple child tags, but most (like <panel>, <divider>, <tabs>, <window> and <if>) allow only a single child tag.s
The <if> tag is re-evaluated when the guiupdate event occurs. Currently, a guiupdate event occurs when a term is selected, the ontology is reloaded, or an edit occurs. In the future, a guiupdate may occur in other circumstances as well.
<xmllayout>
<divider orientation="HORZ">
<first>
<component id="DAG" width="300"/>
</first>
<second>
<if eval="GUI.getSubSelection() != null">
<component id="TEXTEDIT" width="320"/>
<else>
<label text="NOTHING SELECTED!"/>
</else>
</if>
</second>
</divider>
</xmllayout>