Chapter 9. Form Component Interceptors

9.1. Introduction

Form Component Interceptors provide a way to intercept and add extra functionality to input components on a form.

The application context specifies the list of interceptors to attach to controls constructed by the platform. This allows for a declarative model for specifying "additional" functionality to be added to various components.

Examples are interceptors to overlay validation error images and background color changes, provide popup menus in text fields, and autocompletion (as you type) for comboboxes.

9.2. FormComponentInterceptor interface

public interface FormComponentInterceptor {
    public void processLabel(String propertyName, JComponent label);

    public void processComponent(String propertyName, JComponent component);
}        

To create your own FormComponentInterceptor, you have to provide both a FormComponentInterceptor and a FormComponentInterceptorFactory implementation.

TODO: write more

9.3. Configuration

The configuration of the interceptors in the application context is done by defining the FormComponentInterceptorFactory.

Sample configuration:

<bean id="formComponentInterceptorFactory" 
            class="org.springframework.richclient.form.builder.support.ChainedInterceptorFactory">
            <property name="interceptorFactories">
                    <list>
                            <bean class="org.springframework.richclient.form.builder.support.ColorValidationInterceptorFactory">
                                    <property name="errorColor" value="255,200,200"/>
                            </bean>
                            <bean class="org.springframework.richclient.form.builder.support.OverlayValidationInterceptorFactory"/>
                            <bean class="org.springframework.richclient.form.builder.support.DirtyIndicatorInterceptorFactory"/>
                            <bean class="org.springframework.richclient.text.TextComponentPopupInterceptorFactory"/>
                            <bean class="org.springframework.richclient.list.ComboBoxAutoCompletionInterceptorFactory"/>
                    </list>
            </property>
    </bean>

9.4. Built-in FormComponentInterceptors

There are a number of built-in interceptors provided with the framework.

9.4.1. OverlayValidationInterceptor

Shows an error image in the lower left corner of the component if the contents of the component is invalid. The image also has a tooltip showing the validation message.

[Factory class]: org.springframework.richclient.form.builder.support.OverlayValidationInterceptorFactory

9.4.2. ColorValidationInterceptor

Changes the background color of the form component.

[Factory class]: org.springframework.richclient.form.builder.support.ColorValidationInterceptorFactory

Properties:

  • errorColor: the background color

Sample configuration:

<!-- This sets the error color to a nice "reddish" tint -->
<bean class="org.springframework.richclient.form.builder.support.ColorValidationInterceptorFactory">
        <property name="errorColor" value="255,200,200"/>
</bean>

9.4.3. TextComponentPopupInterceptor

Adds more advanced text editing functionality to text components. It adds a popup menu with "undo/redo/cut/copy/paste/select all" items. It also adds the standard keyboard accelerators for these commands to the component.

[Factory class]: org.springframework.richclient.text.TextComponentPopupInterceptorFactory

9.4.4. ComboboxAutocompletionInterceptor

Adds autocompletion to a combobox.

[Factory class]: org.springframework.richclient.list.ComboBoxAutoCompletionInterceptorFactory

9.4.5. DirtyIndicatorInterceptor

Shows an image in the top left corder of the component if the contents of the component has been changed by the user. The image also has a tooltip showing the original value. To the right of the image is a small revert button. Pushing this button restores the original value in the component.

[Factory class]: org.springframework.richclient.form.builder.support.DirtyIndicatorInterceptorFactory

Properties:

  • includedFormModelIds: list of form models that should display the Dirty Indicator.

    Only one of includedFormModelIds or excludedFormModelIds can be specified.

  • excludedFormModelIds: list of form models that should not display the Dirty Indicator

    Only one of includedFormModelIds or excludedFormModelIds can be specified.

<!-- The login form will not show the Dirty Indicator -->
<bean class="org.springframework.richclient.form.builder.support.DirtyIndicatorInterceptorFactory">
        <property name="excludedFormModelIds">
                <list>
                        <value>loginForm</value>
                </list>
        </property>
</bean>

9.4.6. SelectAllFormComponentInterceptor

Selects all the text in text fields and spinners when they receive focus.

[Factory class]: org.springframework.richclient.text.SelectAllInterceptorFactory

9.4.7. TextCaretComponentInterceptor

If the text is set in a text component, the caret position is set to the end of the text.

This means the beginning of the text will not be visible if the text is too long to fit in the text component.

This FormComponentInterceptor "fixes" this behaviour, and sets the caret to position 0.

[Factory class]: org.springframework.richclient.text.TextCaretFormComponentInterceptorFactory

9.4.8. ToolTipInterceptor

If a form property has a caption defined in the messages.properties file it will be used as the tooltip for the form component.

[Factory class]: org.springframework.richclient.form.builder.support.ToolTipInterceptorFactory

Properties:

  • processComponent: default is true, determines whether the tooltip of the component is set.

  • processLabel: default is true, determines whether the tooltip of the label is set.

9.4.9. CheckBoxFormComponentInterceptor

Allows customization on how a CheckBox form property is rendered.

[Factory class]: org.springframework.richclient.form.builder.support.CheckBoxFormComponentInterceptorFactory

Properties:

  • showLabel: default is true, determines whether the label will be shown.

  • showText: default is false, determines whether the label text will be used as text for the checkbox itself.

  • textKey: default is "text", the key used to fetch the text to show.

9.4.10. ShowCaptionInStatusBarInterceptor

Shows the caption of the form component in the statusbar when the component is focused.

[Factory class]: org.springframework.richclient.form.builder.support.ShowCaptionInStatusBarInterceptorFactory

9.4.11. ShowDescriptionInStatusBarInterceptor

Shows the description of the form component in the statusbar when the component is focused.

[Factory class]: org.springframework.richclient.form.builder.support.ShowDescriptionInStatusBarInterceptorFactory