From dc0608d8e8c82aeec8261f11dea51e79cf8e38b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 26 Sep 2011 14:50:04 +0200 Subject: vaadin-app: instanciate Property abscract class --- .../src/ch/asynk/helloworld/HelloWorldApp.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java b/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java index e69967d..bf48c5b 100644 --- a/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java +++ b/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java @@ -69,6 +69,46 @@ class DataMappingLayout extends FormLayout { } }); // + class IntegerObjectProperty implements Property { + Integer data = 0; + boolean readOnly = false; + public Class getType() { + return Integer.class; + } + public Object getValue() { + return data; + } + public boolean isReadOnly() { + return readOnly; + } + public void setReadOnly(boolean newStatus) { + readOnly = newStatus; + } + public void setValue(Object newValue) throws ReadOnlyException, ConversionException { + if (readOnly) + throw new ReadOnlyException(); + if (newValue instanceof Integer) + data = (Integer) newValue; + else if (newValue instanceof String) + try { + data = Integer.parseInt((String) newValue, 16); + } catch (NumberFormatException e) { + throw new ConversionException("Must be an integer (from property)"); + } + else + throw new ConversionException("Unknown entry type (from property)"); + } + @Override + public String toString() { + return Integer.toHexString(data)+" (hex)"; + } + }; + final IntegerObjectProperty intProperty = new IntegerObjectProperty(); + intProperty.setValue(666); + final TextField tf4 = new TextField("MyObjectProperty",intProperty); + tf4.setImmediate(true); + addComponent(tf4); + // Button closeButton = new Button("close the application"); closeButton.setDescription("This will close the application"); addComponent(closeButton ); -- cgit v1.1-2-g2b99