Extending : Client State Extension : Adding “Name” property in Client State
  
Adding “Name” property in Client State
UNICOM® Digital Transformation Toolkit (UDTT™) alpha developers could add “Name” property in Client State so that when using this Client state beta developers define its Name.
When developing new client state, the following steps must be followed to include a “Name” property:
1 Define “Name” property in the corresponding state xml file:
<property name="id" defaultValue="" hidden="false" displayName="%Name" required="true" description="%DescriptionName" editRule="RuleName"/>
2 Define the rule name class:
<extension
point="com.ibm.btt.tools.transaction.dominate.editorRules">
<rule
class="myPackage.MyRuleName" id="RuleName" description="description" >
</rule>
3 Create the rule class.
To make this task easy, UDTT provides a property editor called StateNamePropertyEditor. This class (or a subclass of it) should be invoked from the rule class createPropertyEditor method.
StateNamePropertyEditor has two constructors. Choose one of them depending on the needs:
StateNamePropertyEditor(Attribute attr, Taggable model). It should be invoked in case there is not a necessary initial value in “Name”.
StateNamePropertyEditor(Attribute attr, Taggable model, String initialValue). Constructor that has as third parameter the initial value to be set in the “Name” property. It should be invoked in case an initial value different from blank is necessary.
Then there is a method in the StateNamePropertyEditor API that should be overridden if necessary:
String getNewValueIfEmpty(). It should return the value to be set automatically in “Name” when it is set to blank by the user. By default it returns an empty String. So, it should be overridden at project-level in case a different value needs to be set when “Name” is deleted (as it happens in Operation state, where the “operation” property value is set in that case).
As an example, this is the code corresponding to a new state that sets “Name” property to “myInitial” value as well as it sets automatically the value in “MyProperty” new property to “Name” when it is emptied by the user.
public IPropertyEditor createPropertyEditor(Attribute attr, final Taggable model)
{
return new StateNamePropertyEditor(attr, model, “myInitial”)
{
public String getNewValueIfEmpty() {
return getModel().getValueAt(getModel().getAttributeAt("MyProperty"));
}
};
}
See also
Client State Extension