public class NumberAdapter implements PropertyAdapter {
private TableEditor numberEditor = null;
private class NumberEditor implements TableEditor {
public Widget getEditor(Table table, Object value, TableRow row, String key) throws GUIException {
final MapDataModel dataModel = new MapDataModel();
final String type = ((PropertyTableRow) row).getPropertyNode().getAttribute("type");
dataModel.setValue("value", value);
dataModel.setValue("value_str", value.toString());
dataModel.addModelChangeListener(new ModelChangeListener() {
public void modelChanged(ModelChangeEvent e) throws GUIException {
if (e instanceof MapChangeEvent) {
MapChangeEvent event = (MapChangeEvent) e;
if (event.getKey().equals("value_str")) {
try {
if (type.equals("int"))
dataModel.setValue("value", new Integer((String) dataModel.getValue("value_str")));
else if (type.equals("long"))
dataModel.setValue("value", new Long((String) dataModel.getValue("value_str")));
else if (type.equals("float"))
dataModel.setValue("value", new Float((String) dataModel.getValue("value_str")));
else if (type.equals("double"))
dataModel.setValue("value", new Double((String) dataModel.getValue("value_str")));
} catch (Exception ex) {
/* Ignore */
}
}
}