# Enum properties

**URL:** <https://forum.inductiveautomation.com/t/enum-properties/12626>\
**Category:** Module Development\
**Created:** [January 31, 2017, 1:26pm UTC](https://forum.inductiveautomation.com/t/enum-properties/12626 "2017-01-31T13:26:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JimBranKelly1](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@JimBranKelly1](https://forum.inductiveautomation.com/u/JimBranKelly1)\
**Post date:** [January 31, 2017, 1:26pm UTC](https://forum.inductiveautomation.com/t/enum-properties/12626/1 "2017-01-31T13:26:54Z")

</div>

Here is another one on which the vision of the three eyed raven is obscure:

In the bean info class how do you set an enum property. I tried setting the “dropMode” property as an int, but that didn’t work. In Designer, the property was blank and wouldn’t allow me enter a value.  
The following incantation is illegal:

` addEnumProp("dropMode", "Drop Mode", "Options: default, on, insert and “on and insert”", CAT_DATA,
                new DropMode[] {DropMode.USE_SELECTION, DropMode.ON, DropMode.INSERT, DropMode.ON_OR_INSERT},
                new String[]{"default", "on", "insert", "on and insert"});
`  
So what’s the required spell?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 31, 2017, 1:59pm UTC](https://forum.inductiveautomation.com/t/enum-properties/12626/2 "2017-01-31T13:59:47Z")

</div>

According to the [signature](http://files.inductiveautomation.com/sdk/javadoc/ignition784rc1/com/inductiveautomation/vision/api/designer/beans/DefaultBeanInfo.html), you can’t have an actual enum type property. The property needs to expose int getters and setters, and supply the values in addEnumProp() as integers. How you actually store the selected value is up to you, of course.

---

<div class="post-metadata">

**Author:** ![JimBranKelly1](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@JimBranKelly1](https://forum.inductiveautomation.com/u/JimBranKelly1)\
**Post date:** [January 31, 2017, 11:49pm UTC](https://forum.inductiveautomation.com/t/enum-properties/12626/3 "2017-01-31T23:49:43Z")

</div>

Yep that works, thanks.

I’m using the following in the bean info class:

` addEnumProp("dropMode", "Drop Mode", "Options: default, on, insert and 'on and insert'", CAT_DATA,
                new int[] {DropMode.USE_SELECTION.ordinal()
                    , DropMode.ON.ordinal()
                    , DropMode.INSERT.ordinal()
                    , DropMode.ON_OR_INSERT.ordinal()},
                new String[]{"default", "on", "insert", "on and insert"});`  
With the following to translate the integer back to an enum:

` private void updateDropMode() {
        Integer val = DropMode.USE_SELECTION.ordinal();
        if (baseDropMode != null) {
            val = baseDropMode;
        }
        for (DropMode d : DropMode.values()) {
            if (d.ordinal() == val) { jtree.setDropMode(d); }
        }        
    }`

Internet suggests that use of the ordinal function is not kosher. Better suggestions?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 1, 2017, 1:22am UTC](https://forum.inductiveautomation.com/t/enum-properties/12626/4 "2017-02-01T01:22:54Z")

</div>

[quote=“JimBranKelly”]Internet suggests that use of the ordinal function is not kosher. Better suggestions?[/quote]I wouldn’t worry too much. The issue is that ordinals are potentially subject to change, and your component will be serialized/deserialized with the integers. Future versions could mess up a project from an older version, simply by a difference in the underlying version of JFreeChart.  
The canonical solution would be to use a switch statement in both getter and setter with each value called out.
