In my last post I showed how to simulate enums, and then Giorgio asked in the comments as to how this fits in with the choices() method, used to provide a drop-down list of values.
To start with, let’s add an all() method to StockType:
import org.nakedobjects.applib.DomainObjectContainer;
public class StockType extends EnumeratedAbstract {
private static final String CD = "cd";
private static final String BOOK = "book";
public static StockType Book(DomainObjectContainer container) {
return lookup(container, StockType.class, BOOK);
}
public static StockType Cd(DomainObjectContainer container) {
return lookup(container, StockType.class, CD);
}
public static List all(DomainObjectContainer container) {
return Arrays.asList(Book(container), Cd(container));
}
public static void createAll(DomainObjectContainer container) {
create(container, StockType.class, BOOK);
create(container, StockType.class, CD);
}
}
Then, in the StockType domain object we just add the choices() method, for example:
// {{ StockType
private StockType stockType;
@Disabled
@MemberOrder(sequence = "2")
public StockType getStockType() {
return stockType;
}
public void setStockType(final StockType stockType) {
this.stockType = stockType;
}
public List choicesStockType() {
return StockType.all(getContainer());
}
// }}
Short and sweet. In the next post I’ll show how we can teach Naked Objects to support Java 5 enums natively (a feature that we’ll be adding formally in Naked Objects 4.1).


[...] Simulated Enums – supporting choices » var dzone_url = [...]