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.

FeatureForm.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* *************************************************************************
  2. IT Mill Toolkit
  3. Development of Browser User Interfaces Made Easy
  4. Copyright (C) 2000-2006 IT Mill Ltd
  5. *************************************************************************
  6. This product is distributed under commercial license that can be found
  7. from the product package on license.pdf. Use of this product might
  8. require purchasing a commercial license from IT Mill Ltd. For guidelines
  9. on usage, see licensing-guidelines.html
  10. *************************************************************************
  11. For more information, contact:
  12. IT Mill Ltd phone: +358 2 4802 7180
  13. Ruukinkatu 2-4 fax: +358 2 4802 7181
  14. 20540, Turku email: info@itmill.com
  15. Finland company www: www.itmill.com
  16. Primary source for information and releases: www.itmill.com
  17. ********************************************************************** */
  18. package com.itmill.toolkit.demo.features;
  19. import java.util.Date;
  20. import com.itmill.toolkit.data.Property;
  21. import com.itmill.toolkit.ui.*;
  22. public class FeatureForm extends Feature implements
  23. Property.ValueChangeListener {
  24. OrderedLayout demo = null;
  25. Form test;
  26. Layout formLayout = null;
  27. Select addField = new Select("Add field");
  28. Select resetLayout = new Select("Restart");
  29. protected Component getDemoComponent() {
  30. if (demo == null) {
  31. demo = new OrderedLayout();
  32. createDemo();
  33. }
  34. setJavadocURL("ui/Form.html");
  35. return demo;
  36. }
  37. private void createDemo() {
  38. demo.removeAllComponents();
  39. // Test form
  40. if (formLayout == null)
  41. test = new Form();
  42. else
  43. test = new Form(formLayout);
  44. demo.addComponent(test);
  45. OrderedLayout actions = new OrderedLayout(
  46. OrderedLayout.ORIENTATION_HORIZONTAL);
  47. demo.addComponent(actions);
  48. // form adder
  49. addField.setImmediate(true);
  50. addField.addItem("Add field");
  51. addField.setNullSelectionItemId("Add field");
  52. addField.addItem("Text field");
  53. addField.addItem("Time");
  54. addField.addItem("Option group");
  55. addField.addItem("Calendar");
  56. addField.addListener(this);
  57. actions.addComponent(addField);
  58. // Layout reset
  59. resetLayout.setImmediate(true);
  60. resetLayout.addItem("Select layout example");
  61. resetLayout.setNullSelectionItemId("Select layout example");
  62. resetLayout.addItem("Vertical form (OrderedLayout form-style)");
  63. resetLayout.addItem("Two columns (2x1 GridLayout)");
  64. resetLayout.addItem("Flow (OrderedLayout flow-orientation)");
  65. resetLayout.addListener(this);
  66. actions.addComponent(resetLayout);
  67. // Properties
  68. propertyPanel = new PropertyPanel(test);
  69. propertyPanel.addProperties("Form special properties", new Form());
  70. }
  71. public void valueChange(Property.ValueChangeEvent event) {
  72. if (event.getProperty() == resetLayout) {
  73. String value = (String) resetLayout.getValue();
  74. if (value != null) {
  75. formLayout = null;
  76. if (value.equals("Two columns (2x1 GridLayout)"))
  77. formLayout = new GridLayout(2, 1);
  78. if (value.equals("Horizontal (OrderedLayout)"))
  79. formLayout = new OrderedLayout(
  80. OrderedLayout.ORIENTATION_HORIZONTAL);
  81. createDemo();
  82. resetLayout.setValue(null);
  83. }
  84. }
  85. if (event.getProperty() == addField) {
  86. String value = (String) addField.getValue();
  87. if (value != null) {
  88. if (value.equals("Text field"))
  89. test.addField(new Object(), new TextField("Test field"));
  90. if (value.equals("Time")) {
  91. DateField d = new DateField("Time", new Date());
  92. d
  93. .setDescription("This is a DateField-component with text-style");
  94. d.setResolution(DateField.RESOLUTION_MIN);
  95. d.setStyle("text");
  96. test.addField(new Object(), d);
  97. }
  98. if (value.equals("Calendar")) {
  99. DateField c = new DateField("Calendar", new Date());
  100. c
  101. .setDescription("DateField-component with calendar-style and day-resolution");
  102. c.setStyle("calendar");
  103. c.setResolution(DateField.RESOLUTION_DAY);
  104. test.addField(new Object(), c);
  105. }
  106. if (value.equals("Option group")) {
  107. Select s = new Select("Options");
  108. s.setDescription("Select-component with optiongroup-style");
  109. s.addItem("Linux");
  110. s.addItem("Windows");
  111. s.addItem("Solaris");
  112. s.addItem("Symbian");
  113. s.setStyle("optiongroup");
  114. test.addField(new Object(), s);
  115. }
  116. addField.setValue(null);
  117. }
  118. }
  119. }
  120. protected String getDescriptionXHTML() {
  121. return "<p>Form is a flexible, yet simple container for fields. "
  122. + " It provides support for any layouts and provides buffering interface for"
  123. + " easy connection of commit- and discard buttons. All the form"
  124. + " fields can be customized by adding validators, setting captions and icons, "
  125. + " setting immediateness, etc. Also direct mechanism for replacing existing"
  126. + " fields with selections is given.</p>"
  127. + " <p>Form provides customizable editor for classes implementing"
  128. + " Item-interface. Also the form itself"
  129. + " implements this interface for easier connectivity to other items."
  130. + " To use the form as editor for an item, just connect the item to"
  131. + " form.After the item has been connected to the form,"
  132. + " the automatically created fields can be customized and new fields can"
  133. + " be added. If you need to connect a class that does not implement"
  134. + " Item-interface, most properties of any"
  135. + " class following bean pattern, can be accessed trough"
  136. + " BeanItem.</p>"
  137. + " <p>The best example of Form usage is the this feature browser itself; "
  138. + " all the Property-panels in demos are composed of Form-components.</p>";
  139. }
  140. protected String getTitle() {
  141. return "Form";
  142. }
  143. protected String getImage() {
  144. return "form.jpg";
  145. }
  146. }