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.

FeatureBrowser.java 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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.Iterator;
  20. import java.util.StringTokenizer;
  21. import com.itmill.toolkit.data.*;
  22. import com.itmill.toolkit.ui.*;
  23. import com.itmill.toolkit.ui.Button.ClickEvent;
  24. import com.itmill.toolkit.ui.Button.ClickListener;
  25. public class FeatureBrowser extends CustomComponent implements
  26. Property.ValueChangeListener, ClickListener {
  27. private Tree features;
  28. private Feature currentFeature = null;
  29. private OrderedLayout layout;
  30. private Button propertiesSelect;
  31. private OrderedLayout right;
  32. private PropertyPanel properties;
  33. private Component welcome;
  34. private boolean initialized = false;
  35. private Select themeSelector = new Select();
  36. private static final String WELCOME_TEXT = "<h3>Welcome to the IT Mill Toolkit feature tour!</h3>"
  37. + "In this application you may view and play with some features of IT Mill Toolkit.<br/>"
  38. + "Most of the features can be tested online and include simple example of their "
  39. + "usage associated with it.<br/><br/>"
  40. + "Start your tour by selecting features from the list on the left.<br/><br/>"
  41. + "For more information, point your browser to: <a href=\"http://www.itmill.com\""
  42. + " target=\"_new\">www.itmill.com</a>";
  43. public void attach() {
  44. if (initialized)
  45. return;
  46. initialized = true;
  47. // Configure tree
  48. features = new Tree();
  49. features.setStyle("menu");
  50. features.addContainerProperty("name", String.class, "");
  51. features.addContainerProperty("feature", Feature.class, null);
  52. features.setItemCaptionPropertyId("name");
  53. features.addListener(this);
  54. features.setImmediate(true);
  55. // Configure component layout
  56. layout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
  57. layout.setStyle("featurebrowser-mainlayout");
  58. setCompositionRoot(layout);
  59. OrderedLayout left = new OrderedLayout(
  60. OrderedLayout.ORIENTATION_VERTICAL);
  61. left.addComponent(features);
  62. layout.addComponent(left);
  63. // Welcome temporarily disabled
  64. // Label greeting = new Label(WELCOME_TEXT, Label.CONTENT_XHTML);
  65. // OrderedLayout welcomePanel = new OrderedLayout();
  66. // welcome =
  67. // new Embedded(
  68. // "",
  69. // new ClassResource(
  70. // getClass(),
  71. // "itmill.gif",
  72. // getApplication()));
  73. // welcomePanel.addComponent(welcome);
  74. // welcomePanel.addComponent(greeting);
  75. // layout.addComponent(welcomePanel);
  76. // Theme selector
  77. left.addComponent(themeSelector);
  78. themeSelector.addItem("demo");
  79. themeSelector.addItem("corporate");
  80. themeSelector.addItem("base");
  81. themeSelector.addListener(this);
  82. themeSelector.select("demo");
  83. themeSelector.setImmediate(true);
  84. // Restart button
  85. Button close = new Button("restart", getApplication(), "close");
  86. close.setStyle("link");
  87. left.addComponent(close);
  88. // Test component
  89. registerFeature("/UI Components", new UIComponents());
  90. registerFeature("/UI Components/Basic/Text Field",
  91. new FeatureTextField());
  92. registerFeature("/UI Components/Basic/Date Field",
  93. new FeatureDateField());
  94. registerFeature("/UI Components/Basic/Button", new FeatureButton());
  95. registerFeature("/UI Components/Basic/Form", new FeatureForm());
  96. registerFeature("/UI Components/Basic/Label", new FeatureLabel());
  97. registerFeature("/UI Components/Basic/Link", new FeatureLink());
  98. registerFeature("/UI Components/Item Containers/Select",
  99. new FeatureSelect());
  100. registerFeature("/UI Components/Item Containers/Table",
  101. new FeatureTable());
  102. registerFeature("/UI Components/Item Containers/Tree",
  103. new FeatureTree());
  104. registerFeature("/UI Components/Layouts/Ordered Layout",
  105. new FeatureOrderedLayout());
  106. registerFeature("/UI Components/Layouts/Grid Layout",
  107. new FeatureGridLayout());
  108. registerFeature("/UI Components/Layouts/Custom Layout",
  109. new FeatureCustomLayout());
  110. registerFeature("/UI Components/Layouts/Panel", new FeaturePanel());
  111. registerFeature("/UI Components/Layouts/Tab Sheet",
  112. new FeatureTabSheet());
  113. registerFeature("/UI Components/Layouts/Window", new FeatureWindow());
  114. registerFeature("/UI Components/Layouts/Frame Window",
  115. new FeatureFrameWindow());
  116. registerFeature("/UI Components/Data handling/Embedded Objects",
  117. new FeatureEmbedded());
  118. registerFeature("/UI Components/Data handling/Upload",
  119. new FeatureUpload());
  120. registerFeature("/Data Model/Properties", new FeatureProperties());
  121. registerFeature("/Data Model/Items", new FeatureItems());
  122. registerFeature("/Data Model/Containers", new FeatureContainers());
  123. registerFeature("/Data Model/Validators", new FeatureValidators());
  124. registerFeature("/Data Model/Buffering", new FeatureBuffering());
  125. registerFeature("/Terminal/Parameters and URI Handling",
  126. new FeatureParameters());
  127. // Pre-open all menus
  128. for (Iterator i = features.getItemIds().iterator(); i.hasNext();)
  129. features.expandItem(i.next());
  130. // Add demo component and tabs
  131. currentFeature = new FeatureButton();
  132. layout.addComponent(currentFeature);
  133. // Add properties
  134. right = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
  135. layout.addComponent(right);
  136. propertiesSelect = new Button("Show properties", this);
  137. propertiesSelect.setSwitchMode(true);
  138. right.addComponent(propertiesSelect);
  139. properties = currentFeature.getPropertyPanel();
  140. properties.setVisible(false);
  141. right.addComponent(properties);
  142. }
  143. public void registerFeature(String path, Feature feature) {
  144. StringTokenizer st = new StringTokenizer(path, "/");
  145. String id = "";
  146. String parentId = null;
  147. while (st.hasMoreTokens()) {
  148. String token = st.nextToken();
  149. id += "/" + token;
  150. if (!features.containsId(id)) {
  151. features.addItem(id);
  152. features.setChildrenAllowed(id, false);
  153. }
  154. features.getContainerProperty(id, "name").setValue(token);
  155. if (parentId != null) {
  156. features.setChildrenAllowed(parentId, true);
  157. features.setParent(id, parentId);
  158. }
  159. if (!st.hasMoreTokens())
  160. features.getContainerProperty(id, "feature").setValue(feature);
  161. parentId = id;
  162. }
  163. }
  164. public void valueChange(Property.ValueChangeEvent event) {
  165. // Change feature
  166. if (event.getProperty() == features) {
  167. Object id = features.getValue();
  168. if (id != null) {
  169. if (features.areChildrenAllowed(id))
  170. features.expandItem(id);
  171. Property p = features.getContainerProperty(id, "feature");
  172. Feature feature = p != null ? ((Feature) p.getValue()) : null;
  173. if (feature != null) {
  174. layout.replaceComponent(currentFeature, feature);
  175. currentFeature = feature;
  176. properties = feature.getPropertyPanel();
  177. if (properties != null) {
  178. Iterator i = right.getComponentIterator();
  179. i.next();
  180. PropertyPanel oldProps = (PropertyPanel) i.next();
  181. if (oldProps != null)
  182. right.replaceComponent(oldProps, properties);
  183. else
  184. right.addComponent(properties);
  185. properties.setVisible(((Boolean) propertiesSelect
  186. .getValue()).booleanValue());
  187. }
  188. getWindow()
  189. .setCaption(
  190. "IT Mill Toolkit Features / "
  191. + features.getContainerProperty(id,
  192. "name"));
  193. }
  194. }
  195. } else if (event.getProperty() == themeSelector) {
  196. getApplication().setTheme(themeSelector.toString());
  197. }
  198. }
  199. public void buttonClick(ClickEvent event) {
  200. properties.setVisible(((Boolean) propertiesSelect.getValue())
  201. .booleanValue());
  202. }
  203. }