My quick and dirty solution would be to use a simple modeldata as sven suggested, then use a custom Converter class to transfer back and forth.
Try this as a model object - this assumes that the toString() method of the enum has been overridden to display something useful (you aren't just displaying the PascalCased words on your otherwise pretty UI are you? Alternatively, you could make the constructor take an additional String param if you like...
Code:
public class EnumWrapper<E extends Enum<E>> extends BaseModelData {
public EnumWrapper(E enumValue) {
set("enum", enumValue);
set("value", enumValue.toString());
}
}
Then the Converter subclass looks something like this:
Code:
public class EnumConverter<E> extends Converter {
public Object convertFieldValue(Object value) {
return new EnumWrapper<E>((E)value);
}
public Object convertModelValue(Object value) {
return ((EnumWrapper)value).get("enum");
}
}
I think this is a good question, one which I will need answered for myself in the coming weeks, so if anyone has good/bad luck with this approach or finds another one, please share!
FWIW, I am find a lot of cases where a Converter class is essential to get many faucets of GXT working well. They are ugly to have to patch in, as you only want a single instance of each one, and Java's syntax makes them rather verbose - at least 6 lines of code before you even start adding custom code to the thing... Anyone have better ideas on how some of this could be implemented?
I am aware that it is a big deal to get the ComboBox working well, especially if you want it to contain complex data, but this whole idea of using a Map<String, Object> (i.e. ModelData) feels like you are trying to write Javascript components in Java. And while yes, it will all be compiled to Javascript in the end, the entire point of using Java is to stay far away from Javascript
...