aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/demo/BufferedComponents.java
blob: 6a560e39c6c1ba146a0748fd09686c1a6bb5efc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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);

		// 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);
	}
}