Attribute binding

Because a JViews TGO attribute (IlpAttribute) may correspond to multiple SDM model (IlvSDMModel) object properties, it must be bound to an SDM property individually if it is relevant to a JViews Diagrammer component.
A JViews TGO business object (IlpObject) must be associated with a JViews TGO class (IlpClass). The SDM model defines a symbolic property called 'tag' that is used to categorize different SDM objects. The TGO-SDM adapter automatically maps the String representation of a JViews TGO class to the 'tag' symbolic property.
IlpObject tgoObject = ...
String tag = tgoObject.getIlpClass().getName();
The binding process allows for name mapping (attribute name to property name) as well as bidirectional type conversion (from attribute to property and from property to attribute).
Examples of binding
The position attribute of the predefined business object IltNetworkElement is represented by a point (IlpPoint) with x and y coordinates. Conversely, the positioning in JViews Diagrammer is defined by the SDM object properties x and y. The JViews TGO attribute position must therefore be mapped to two SDM properties, x and y.
In this case, the conversion is trivial and can be performed in both ways: from attribute to property or from property to attribute, at nearly no cost.
In the case of the predefined business object IltPolyGroup, the position attribute is defined by an array of points (IlpPolygon). JViews Diagrammer does not support this type of representation, which means that the binding process has to convert a polygon into a point and vice versa. Although it is possible, this conversion is no longer trivial and may result in performance penalties.

How to implement attribute binding

The abstract class IlpAbstractAttributeBinding defines the base for an attribute binding. It requires a binding type (READ-ONLY or READ-WRITE), the JViews TGO attribute name and corresponding data type, and the SDM property name and corresponding data type. The class provides APIs that must be extended to implement the logic behind attribute binding.
The default binding implementation (IlpDefaultAttributeBinding) defines a pass-through READ-WRITE binding type between a given attribute and an SDM property of the same name and data type. For example, the default binding can be used to map the JViews TGO name attribute (type String) to the SDM name property (type String).

Binding context

The following binding method is available for subclasses to access contextual information about the current binding:
protected IlpAttributeBindingContext getBindingContext()
The IlpAttributeBindingContext is set to the binding object right before performing a type conversion. It is used to provide the following required information:
  • JViews TGO context (IlpContext)
  • Java Logger for message and error logging
  • Current attribute holder (JViews TGO object) to which the conversion applies
  • Current attribute value
  • Current property value
After the conversion, the context object is removed from the binding object.
Object convertToProperty(Object): This method applies READ-WRITE and READ-ONLY binding types. It must be extended to implement the conversion of a JViews TGO attribute to an SDM property. The given argument is the current JViews TGO attribute and the returned value corresponds to the new SDM property value. The method getBindingContext() can be invoked inside this method to retrieve contextual information that might be valuable for the conversion.
Object convertToAttribute(Object): This method only applies to READ-WRITE binding types. It must be extended to implement the conversion of an SDM property to a JViews TGO attribute. The given argument is the current SDM property value and the returned value corresponds to the new JViews TGO attribute value. The method getBindingContext() can be invoked inside this method to retrieve contextual information that might be valuable for the conversion.

How to set bindings to different JViews TGO classes

// Get the reference to your bindings
IlpAbstractAttributeBinding bindingOne = ...
IlpAbstractAttributeBinding bindingTwo = ...

// Get the reference to your adapter
IlpAbstractSDMAdapter adapter = ...

// Add 'bindingOne' to all predefined business objects
adapter.addAttributeBinding(IltObject.GetIlpClass(), bindingOne);

// Add 'bindingTwo' only to predefined 'network element' objects
adapter.addAttributeBinding(IltNetworkElement.GetIlpClass(), bindingTwo);

Predefined attribute bindings

You can use the following predefined bindings:
  • IlpDefaultAttributeBinding: Defines a pass-through binding (it supports READ_WRITE).
  • IlpEnumBinding: Defines a binding between IlEnum and String (it supports READ_WRITE).
  • IlpPointPositionBinding: Defines a binding between IlpPoint and either “x” or “y” property (it supports READ_WRITE).
  • IlpPolylinePositionBinding: Defines a binding between IlpPolyline and either “x” or “y” property, based on the center of gravity of the polyline (it supports READ_WRITE).
  • IlpPolygonePositionBinding: Defines a binding between IlpPolygone and either “x” or “y” property, based on the center of gravity of the polygon (it supports READ_WRITE).
  • IlpRectPositionBinding: Defines a binding between IlpRect and either “x” or “y” property, based on the center of gravity of the rectangle (it supports READ_WRITE).
  • IlpRelativePointPositionBinding: Defines a binding between the position of a card item (IltLed or IltPort) and either “x” or “y” property. Because relative positioning has no meaning within JViews Diagrammer, this binding will convert IlpRelativePoint to “null” when the element is inside a card.
  • IlpShelfItemPositionBinding: Defines a binding between the position of a shelf item (IltCard or IltCardCarrier) and either “x” or “y” property. Because relative positioning has no meaning within JViews Diagrammer, this binding will convert IlpShelfItemPosition to “null”.
  • IlpSlotSizesBinding: Defines a binding between IlpSlotSizes and either “width” or “height” property. Because shelf dimensions have no meaning within JViews Diagrammer, this binding will only stretch slots (it supports READ_WRITE).
Example
The following example illustrates how to use IlpDefaultAttributeBinding to create a binding between the JViews TGO attribute name (available for all predefined business objects) and the SDM property label.
// Create the binding
IlpDefaultAttributeBinding nameBinding = 
   new IlpDefaultAttributeBinding(IlpDefaultAttributeBinding.Type.READ_WRITE,
                                  ”name”, String.class, ”label”);

// Add binding to adapter
IlpAbstractSDMAdapter adapter = ...
adapter.addAttributeBinding(IltObject.GetIlpClass(), nameBinding);
The method IlpDefaultAttributeBinding.addDefaultBindings() can be used to automatically set all default bindings at once.
Note
The TGO-SDM adapter does not provide any default binding for JViews TGO geographic positions, but this kind of binding can be achieved by extending IlpAbstractAttributeBinding to implement a position converter that fits the user needs.
Note
JViews TGO relative positions such as IlpSlotSizes, IlpShelfItemPosition, and IlpRelativePoint are specific to the way JViews TGO renders them. The TGO-SDM adapter does not convert these positions to the SDM model as these values have no meaning for a JViews Diagrammer view. Users can customize the predefined position attribute bindings to perform a position conversion that fits their needs.

Binding performance

Each binding represents a conversion from one type to another. Some conversions may be stateless, fast, and efficient. Others may depend on previous attribute and property values and may be more demanding in terms of computational power. For that reason it is important to plan ahead and only bind the attributes that must be available as SDM properties (usually for JViews Diagrammer CSS styling purposes). The SDM model provided by the TGO-SDM adapter is populated with JViews TGO business objects (IlpObject) so that it is always possible to query JViews TGO attribute values from the JViews Diagrammer component, as illustrated by the following code example:
// Get SDM Model from Adapter
IlvSDMModel model = adapter.getSDMModel();
IlpObject tgoObject = (IlpObject)model.getObject(”myObjectID”);

// Get TGO attribute from model object
Object value = tgoObject.getAttributeValue(”myAttribute”);