]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added Joonas's example.
authorJani Laakso <jani.laakso@itmill.com>
Wed, 4 Apr 2007 10:13:57 +0000 (10:13 +0000)
committerJani Laakso <jani.laakso@itmill.com>
Wed, 4 Apr 2007 10:13:57 +0000 (10:13 +0000)
svn changeset:1136/svn branch:trunk

src/com/itmill/toolkit/demo/BufferedComponents.java [new file with mode: 0644]

diff --git a/src/com/itmill/toolkit/demo/BufferedComponents.java b/src/com/itmill/toolkit/demo/BufferedComponents.java
new file mode 100644 (file)
index 0000000..6740fdf
--- /dev/null
@@ -0,0 +1,76 @@
+package com.itmill.toolkit.demo;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.data.util.MethodProperty;
+import com.itmill.toolkit.data.util.ObjectProperty;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.TextField;
+import com.itmill.toolkit.ui.Window;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+
+public class BufferedComponents extends Application {
+
+       private ObjectProperty property;
+
+       private TextField text;
+
+       public void init() {
+
+               Window w = new Window("Buffered UI components demo");
+               addWindow(w);
+               setTheme("corporate");
+
+               // Create property
+               Float floatValue = new Float(1.0f);
+               property = new ObjectProperty(floatValue);
+
+               // Textfield
+               text = new TextField("TextField (Buffered, using ObjectProperty)",
+                               property);
+               text.setImmediate(true);
+               text.setWriteThrough(false);
+               w.addComponent(text);
+
+               // Property state
+               Label propertyState = new Label(property);
+               propertyState.setCaption("Property (data source) state");
+               w.addComponent(propertyState);
+
+               // Button state
+               Label textState = new Label(text);
+               textState.setCaption("TextField state");
+               w.addComponent(textState);
+
+               // Button to change the property
+               w.addComponent(new Button("increase property value",
+                               new Button.ClickListener() {
+                                       public void buttonClick(ClickEvent event) {
+                                               Float currentValue = (Float) property.getValue();
+                                               property.setValue(new Float(
+                                                               currentValue.floatValue() + 1.0));
+                                       }
+                               }));
+
+               // Buffering
+               w.addComponent(new Button("Write through enabled", new MethodProperty(
+                               text, "writeThrough")));
+               w.addComponent(new Button("discard", new Button.ClickListener() {
+                       public void buttonClick(ClickEvent event) {
+                               text.discard();
+                       }
+               }));
+               w.addComponent(new Button("commit", new Button.ClickListener() {
+                       public void buttonClick(ClickEvent event) {
+                               text.commit();
+                       }
+               }));
+
+               // Restart button for application
+               // (easier debugging when you dont have to restart the server to make
+               // code changes)
+               Button restart = new Button("restart", this, "close");
+               restart.setStyle("link");
+               w.addComponent(restart);
+       }
+}