LinkedHashMap<String, String> unitsChoices = new LinkedHashMap<String, String>();
for (MeasurementUnits unit : EnumSet.allOf(MeasurementUnits.class)) {
unitsChoices.put(unit.name(), unit.name());
}
final SelectItem unitsMenu = new SelectItem("unitsItem", "Units");
unitsMenu.setValueMap(unitsChoices);
unitsMenu.setDefaultValue(MeasurementUnits.BYTES.name());
final TextItem textItem = new TextItem("valueItem", "Value");
final StaticTextItem resultsValueItem = new StaticTextItem("resultsValue", "Results Value");
final StaticTextItem resultsUnitItem = new StaticTextItem("resultsUnits", "Results Units");
ButtonItem button = new ButtonItem("convertItem", "Convert");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
MeasurementUnits units = MeasurementUnits.valueOf(unitsMenu.getValueAsString());
String value = textItem.getValueAsString();
MeasurementNumericValueAndUnits vu = MeasurementParser.parse(value, units);
resultsValueItem.setValue(vu.getValue().toString());
resultsUnitItem.setValue(vu.getUnits().name());
}