Enum (element)

From JRapid

Jump to: navigation, search

enum is an element child of property or child of enumset.


Contents

Description

An enum element defines a constant value during development for a property of type enum.

A property of type enum can define the enum values as children elements of the property or reuse a global enumset.

The enum elements may specify the value attribute or not. If not, the label is used as the value. Keep in mind that values for enum elements should be valid Java identifiers and that, in order to follow naming best practices, these names should be uppercase. Remember you cannot begin an identifier name with a number.

Usage

<enumset
    name = NAME >
        <enum value = VALUE > LABEL </enum>
        ...
</enumset>
...

<entity
   name = NAME
   ... >
   <property
      ...
      name = NAME
      type = "enum"
      enumset = ENUMSET_NAME
   />
/>

or

 <property
    name = NAME
    type = "enum" >
        <enum value = VALUE > LABEL </enum>
        ...
</property>

Example

  • An example using an enumset to define the option values.
    <enumset name="CompassDirection">
        <enum value="N">North</enum>
        <enum value="E">East</enum>
        <enum value="S">South</enum>
        <enum value="W">West</enum>
    </enumset>

    <entity label="Path" menu="Menu" name="Path">
        <property display="primary" label="Name" name="name"/>
        <property enumset="CompassDirection" label="Direction" name="direction" type="enum"/>
        <property label="Distance" name="distance" type="integer"/>
    </entity>

The direction property shows the available options for the property.

Path entity using enum type with CompassDirection enumset

  • Now, lets create a property of enum type but this time we'll define the options inline as child elements for that property.
    <entity label="Product" menu="Menu" name="Product">
        <property display="primary" label="Name" name="name"/>
        <property label="Color" name="color" type="enum">
            <enum value="R">Red</enum>
            <enum value="B">Blue</enum>
            <enum value="W">White</enum>
            <enum value="G">Green</enum>
        </property>
    </entity>

Product entity using enum type

See also

Personal tools