1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /*
- @ITMillApache2LicenseForJavaFiles@
- */
-
- 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() {
-
- final Window w = new Window("Buffered UI components demo");
- addWindow(w);
-
- // Create property
- final 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
- final Label propertyState = new Label(property);
- propertyState.setCaption("Property (data source) state");
- w.addComponent(propertyState);
-
- // Button state
- final 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) {
- final 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)
- final Button restart = new Button("restart", this, "close");
- restart.addStyleName(Button.STYLE_LINK);
- w.addComponent(restart);
- }
- }
|