Component behaviors for Java developers

A behavior is a component "add-on" that adds properties and events to a component. For example, you can add a behavior that adds a button to the toolbar of a PresentBlox and generates an event when you click the button. The behavior has properties for the button's name and icon and the name of the toolbar that you want to add the button to.

You specify a behavior for a component in the report definition. You also define the values for the behavior's properties and the actions to perform for the behavior's events in the report definition.

Behaviors have a descriptor XML file and a Java™ class. A behavior's descriptor file is like a component's descriptor file; they both define the properties and events the object has. In addition, both define the display name, description, and icon the object will have in Blox Builder.

The following example shows a behavior's descriptor file. The behavior has two properties and can generate an onClickEvent. The value of the classname attribute in <bbbhv:behavior-descriptor> is the corresponding Java class.

<bbbhv:behavior-descriptor classname="MyBehavior">
  <tooling-descriptor palette-category-id="AlphabloxBehaviors"
      omit-from-layout="false">
    <display-name>My Behavior</display-name>
    <description>This is my behavior.</description>
    <palette-icon>myBehavior.gif</palette-icon>
  </tooling-descriptor>

  <property-descriptors>
    <property-descriptor>
      <property-name>Label</property-name>
      <property-type>String</property-type>
    </property-descriptor>
    <property-descriptor>
      <property-name>Tooltip</property-name>
      <property-type>String</property-type>
    </property-descriptor>
  </property-descriptors>

  <events>
    <event type="onClickEvent"/>
  </events>
</bbbhv:behavior-descriptor>

A behavior's Java class implements the Behavior interface. Every property defined in the behavior's descriptor file must have a Get and Set method in the Java class.