Chapter 6. Custom attribute editor

Table of Contents
1. A sample attribute editor
2. Compiling and testing the sample attribute editor

What is a custom attribute editor?

A custom attribute editor extends the Attributes tool. There are two kinds of such extensions:

  1. An extension which returns the list of all possible values for a given attribute. Example:

    <attributeEditor attribute="f:remove" elementMatches="f:filter"
      xmlns:f="urn:namespace:filter">
      <list>
        <item>red</item>
        <item>green</item>
        <item>blue</item>
      </list>
    </attributeEditor>

    Note that implementing this first kind of attribute editor may be done without any Java™ programming, by the means of the list child element of an attributeEditor configuration element. This is the case of the above example. More information in Section 1, “attributeEditor” in XMLmind XML Editor - Configuration and Deployment.

  2. An extension which creates a modal dialog box allowing to edit the value of a given attribute. This dialog box is passed the initial attribute value (or the empty string if the attribute has not yet been specified). The dialog box is then expected to return a possibly modified value for this attribute. XHTML example described in this tutorial:

    <attributeEditor attribute="bgcolor" 
      elementMatches="html:table|html:tr|html:th|html:td|html:body"
      xmlns:html="http://www.w3.org/1999/xhtml">
      <class>HexColorChooser</class>
    </attributeEditor>

The Attributes tool invokes such extension as follows:

  1. The Value field which supports auto-completion will display the items of the list.

  2. When you click the Edit button or right-click on an attribute, this displays a popup menu. The first entry of this menu is also called Edit and displays a dialog box allowing to edit the attribute more comfortably than with the Value field. The dialog box displayed in this case comes from the attributeEditor configuration element.

Where to declare a custom attribute editor?

A custom attribute editor is declared in an XXE configuration file by the means of the attributeEditor configuration element in XMLmind XML Editor - Configuration and Deployment. See above examples.

How to implement a custom attribute editor?

In the case of an attribute editor of the first kind, implement interface SetAttribute.ChoicesFactory or SetAttribute.RefChoicesFactory. In the case of an attribute editor of the second kind, implement interface SetAttribute.EditorFactory.