You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BufferedComponents.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.demo;
  5. import com.itmill.toolkit.Application;
  6. import com.itmill.toolkit.data.util.MethodProperty;
  7. import com.itmill.toolkit.data.util.ObjectProperty;
  8. import com.itmill.toolkit.ui.Button;
  9. import com.itmill.toolkit.ui.Label;
  10. import com.itmill.toolkit.ui.TextField;
  11. import com.itmill.toolkit.ui.Window;
  12. import com.itmill.toolkit.ui.Button.ClickEvent;
  13. public class BufferedComponents extends Application {
  14. private ObjectProperty property;
  15. private TextField text;
  16. public void init() {
  17. final Window w = new Window("Buffered UI components demo");
  18. addWindow(w);
  19. // Create property
  20. final Float floatValue = new Float(1.0f);
  21. property = new ObjectProperty(floatValue);
  22. // Textfield
  23. text = new TextField("TextField (Buffered, using ObjectProperty)",
  24. property);
  25. text.setImmediate(true);
  26. text.setWriteThrough(false);
  27. w.addComponent(text);
  28. // Property state
  29. final Label propertyState = new Label(property);
  30. propertyState.setCaption("Property (data source) state");
  31. w.addComponent(propertyState);
  32. // Button state
  33. final Label textState = new Label(text);
  34. textState.setCaption("TextField state");
  35. w.addComponent(textState);
  36. // Button to change the property
  37. w.addComponent(new Button("increase property value",
  38. new Button.ClickListener() {
  39. public void buttonClick(ClickEvent event) {
  40. final Float currentValue = (Float) property.getValue();
  41. property.setValue(new Float(
  42. currentValue.floatValue() + 1.0));
  43. }
  44. }));
  45. // Buffering
  46. w.addComponent(new Button("Write through enabled", new MethodProperty(
  47. text, "writeThrough")));
  48. w.addComponent(new Button("discard", new Button.ClickListener() {
  49. public void buttonClick(ClickEvent event) {
  50. text.discard();
  51. }
  52. }));
  53. w.addComponent(new Button("commit", new Button.ClickListener() {
  54. public void buttonClick(ClickEvent event) {
  55. text.commit();
  56. }
  57. }));
  58. // Restart button for application
  59. // (easier debugging when you dont have to restart the server to
  60. // make
  61. // code changes)
  62. final Button restart = new Button("restart", this, "close");
  63. restart.addStyleName(Button.STYLE_LINK);
  64. w.addComponent(restart);
  65. }
  66. }