Using data model expressions
Explains an advanced feature for inserting references to the data model or expressions in certain property values.
Explains what references and expressions are.
Explains how to define a text property by using an expression or reference to the data model.
Explains how to define a numeric or fixed-value property using an expression or reference to the data model.
Provides hints to use the Expression Assist facility to enter expressions.
Explains what are variables with regard to expressions and how to work with them.
Explains what are custom functions in relation to expressions and how to work with them.
Explains how to obtain details about the format of expressions.
About references and expressions
It is possible to use the values of data model attributes for styling. You can also use an expression involving one or more data property values for styling.
A reference to a model attribute is the name of the attribute preceded by the at sign (@), for example, @id.
An expression is signaled by the initial symbols
@| for example,
@|"name is: "+@id. Note that this example uses the concatenation operator,
+, and that literal strings must be enclosed in quotation marks. A further example is
@|@firstname+" "+@name, which is used in the genealogical tree example, see
Customizing genealogy nodes by type. For full details of the expression syntax, see
Expressions in
Developing with the JViews Diagrammer SDK.
The way to enter references or expressions in the Designer depends on whether the styling property you want to set is a text property.
Using expressions in text properties
In the Styling Customizer, for styling properties with a text value, you can directly enter references to model attributes or expressions containing references to model attributes.
1. If you do not have the ArizonaLogical example open, click File > Open and navigate to the ArizonaLogical.idpr file.
2. Click Open.
3. Select the node rule.
4. Change the value of the name parameter to @id in the Styling Customizer.
5. Press Enter.
The names of the cities appear in the nodes, see the following figure.
Data model attribute values in a diagram
By default, name is set to @name, but in the Arizona data model, there is no attribute called name, instead the city names are mapped to the attribute called id.
Note that if you create property in Diagram Editing Mode, it is a text property.
Using expressions in numeric or fixed-value properties
For styling properties which usually have a fixed type of value (for example, numeric) or a fixed list of possible values (for example, true and false), you cannot enter a data model reference or expression directly. Instead, you must use the right-click menu.
1. In the ArizonaLogical example, select the link rule.
2. Click the Width tab in the Styling Customizer.
The styling properties in this tab are numeric.
3. Increase the value in the Line width max. field to 50.
4. Click in the Line width field.
5. Clear the value.
6. Right-click and select Enter an Expression.
7. Enter @Traffic.
8. Press Enter.
9. Click in the canvas to see the result better.
The line widths reflect the volume of traffic on the link, see the following figure.
Numeric data model attribute value used in a diagram
If the thickness of the lines is not sufficient, try entering @|@Traffic*2 instead.
Using Expression Assist
The Expression Assist is a utility feature that provides a quick way to enter expressions in the Expression text field by opening a scrollable list of available options.
Following are a few tips on how to use the Expression Assist:
You can use the mouse or the keyboard to navigate and select a line in the list of options. Click or press Enter to insert the selected expression into the text field.
The list of options opens when the cursor is placed at a location where expression completion makes sense, for example, after a separator.
The proposed expression options are syntactically correct, but might not be semantically correct.
The list of expression options displays the expression options followed by a short description of the options.
Example:
1. Create a new diagram by clicking File > New.
2. In the diagram window, click one of the blue boxes.
3. In the Styling Customizer, at the right of the name field, type +.
The Expression Assist displays the list of expression options. First in line are the model attributes, followed by the variables, then the functions.
Using variables
Variables allow you to define shareable values like a color or a number. Variables can be used in an expression, where they are substituted by their value at run time.
To create or edit a variable:
1. Click Edit > Variables.
The Variable definitions dialog opens with the list of currently defined variables.
a. To add a variable, click Add.
A new row is created.
Edit the name and value to set the variable.
b. To change a variable, edit its name or value directly in the list.
c. To remove a variable, select its row in the list and click Remove.
2. Click Apply to accept the changes.
The Expression Assist is automatically updated with the new variable set.
To use a variable in an expression:
Use the Expression Assist to select the right variable.
Using custom functions
Custom functions can be registered to be used inside an expression.
To register custom functions:
1. Click Edit > Functions.
The Custom functions dialog opens with the list of currently registered custom functions.
a. To add a function, click Add and type the fully qualified Java™ class name in the text field.
The new function is added to the list.
If the function is valid, its name and description can be seen in the details area.
To be valid, a custom function must meet the following two criteria:
b. It must be a Java class implementing ilog.views.sdm.renderer.IlvSDMCSSFunction.
c. It must be already in the CLASSPATH of the Designer.
If the function name cannot be loaded into the JVM™, a red warning is displayed in place of the name and short description.
d. To remove a function, select it in the list and click Remove.
2. To accept the changes, click Apply.
Note that only valid functions will be registered and shown by the Expression Assist. Any others will be removed.
Example:
1. Create a new diagram by clicking File > New.
2. Click Edit > Functions.
3. Click Add.
4. Type ilog.views.sdm.renderer.IlvSDMCSSFunction$Test in the ““Add a new function”” dialog box.
5. Click OK.
The new function appears in the list.
The function is only for testing. It returns its first argument.
6. Click Apply.
7. In the diagram window, click one of the blue boxes.
8. In the Styling Customizer, at the right of the name property field, type +.
The Expression Assist displays a list of expression options.
9. Select testFunction.
The function is added in the expression.
10. Inside the brackets, type :up.
11. Press Enter to validate the expression.
All nodes have now :up appended to their label, for example Node 1:up.
Displaying help on expressions
You can display a help window about expressions.
1. Right-click a property field of the Styling Customizer.
2. Select Help about expression.
This help explains the format of expressions, lists the data model properties that you can use, and gives some examples of expressions.
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.