Creating a user-defined toolkit bean

Follow the steps below to develop a new visual bean to use in a toolkit application using the WebSphere(R) Studio Visual Editor For Java(TM). Building a visual bean in this way guarantees that consistency will be maintained between values in the context and values in the view.
  1. Create a Java class that inherits from either a Swing component or some other toolkit visual bean.
  2. Create a BeanInfo class with the same name as the Java class plus BeanInfo.
  3. Following the specifications of how to create a BeanInfo for visual classes in WebSphere Studio Application, add the following attributes and property editors:
    Table 1. Bean attributes and editors
    Bean Attribute Property Editor Setting
    CoordinationEventListener aCoordinationEventListener None
    String AlternativeDataName SpDataNameEditor
    String dataName SpDataNameEditor
    Object dataValue None
    boolean inError None
    boolean required None
    String helpID None
    String dataDirection DataDirectionEditor
    navigationParameters navigationParametersEditor
    String type SpButtonTypeEditor
  4. The Bean class must implement one of the following interfaces:
    • DataExchanger interface (which extends the PanelActions interface)
    • ErrorMessageGenerator interface (which extends DataExchanger)
    • DataExchangerWithList interface (which extends DataExchanger)
    Implement ErrorMessageGenerator if your visual component validates the user input; otherwise, implement the DataExchanger interface or the DataExchangerWithList. Implement the DataExchangerWithList if the bean uses a list from the context to show a list of values to select from. (For more information on implementing these interfaces see DataExchanger interface description.) If you use the DataExchangerWithList, the DSECoordinatedPanel will refresh the values from the model and also refresh the list in the view. To use the DataExchangerWithList, you must add the following additional bean attributes to your BeanInfo class:
    Table 2. Additional bean attributes
    Bean Attribute Property Editor Setting
    Object dataValueForList None
    String dataNameForList DataNameListEditor
    The PanelAction interface (or an extension of this interface) is implemented by all visual beans that fire a DSECoordinationEvent. The EventSourceType of the bean-fired events can be specified as one of the following DSECoordinationEvent constant values (and selected according to the type of bean you are creating):
    • EVENT_SOURCETYPE_CLEAR
    • EVENT_SOURCETYPE_HELP
    • EVENT_SOURCETYPE_OK
    • EVENT_SOURCETYPE_EURO
    • EVENT_SOURCETYPE_EMU
    • EVENT_SOURCETYPE_REPEAT
  5. If your bean is a visible class, it should implement the GUIComponent interface. (For more information on implementing this interface see GUIComponent interface definition.) The following additional bean attribute must be added to your BeanInfo class:
    Table 3. Additional bean attribute for visible beans
    Bean Attribute Property Editor Setting
    boolean activatedOkKey None
  6. To handle a DSECoordinationEvent, implement a fireCoordinationEvent() method as follows:
    fireDSECoordinationEvent (DSECoordinationEvent event){
    aCoordinatedEventListener.handleDSECoordinationEvent (event); } 
  7. Implement the code to invoke fireHandleDSECoordinationEvent (DSECoordinationEvent) method when data changes in the bean.
  8. To support the special keys OK, Tab, and Help, implement a processComponentKeyEvent() method, as follows:
    if (Settings.isSpecialKey(e)){ e.consume();}
    else{ super.processComponentKeyEvent();} 
    Consistency between values in the context and values in the view is guaranteed. When the end user changes some data in the view, the fireDSECoordinationEvent() method is invoked, passing the name of the particular DSECoordinationEvent. The operation panel is a listener for all the DSECoordinationEvents from the beans it contains, and therefore handles the DSECoordinationEvent and updates the context with the new value if the dataChanged flag in the event is true. This event must be created with the "type" and "navigationParameters" properties values (see NavigationParameters object description).

    When the view refresh is invoked, the operation panel invokes its refreshDataExchangers() method. For each data exchanger on the operation panel, it obtains the corresponding value from the context and calls the setDataValue(value) data exchanger method. If the interface is DataExchangerWithList, it also calls the setDataValueForList(value) method.

    Your new toolkit visual bean is now ready to be dropped onto a toolkit DSECoordinatedPanel or embedded panel.