Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

FeatureBrowser.java 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 IntroComponents());
  90. registerFeature("/UI Components/Basic", new IntroBasic());
  91. registerFeature("/UI Components/Basic/Text Field",
  92. new FeatureTextField());
  93. registerFeature("/UI Components/Basic/Date Field",
  94. new FeatureDateField());
  95. registerFeature("/UI Components/Basic/Button", new FeatureButton());
  96. registerFeature("/UI Components/Basic/Form", new FeatureForm());
  97. registerFeature("/UI Components/Basic/Label", new FeatureLabel());
  98. registerFeature("/UI Components/Basic/Link", new FeatureLink());
  99. registerFeature("/UI Components/Item Containers",
  100. new IntroItemContainers());
  101. registerFeature("/UI Components/Item Containers/Select",
  102. new FeatureSelect());
  103. registerFeature("/UI Components/Item Containers/Table",
  104. new FeatureTable());
  105. registerFeature("/UI Components/Item Containers/Tree",
  106. new FeatureTree());
  107. registerFeature("/UI Components/Layouts", new IntroLayouts());
  108. registerFeature("/UI Components/Layouts/Ordered Layout",
  109. new FeatureOrderedLayout());
  110. registerFeature("/UI Components/Layouts/Grid Layout",
  111. new FeatureGridLayout());
  112. registerFeature("/UI Components/Layouts/Custom Layout",
  113. new FeatureCustomLayout());
  114. registerFeature("/UI Components/Layouts/Panel", new FeaturePanel());
  115. registerFeature("/UI Components/Layouts/Tab Sheet",
  116. new FeatureTabSheet());
  117. registerFeature("/UI Components/Layouts/Window", new FeatureWindow());
  118. // Disabled for now
  119. // registerFeature("/UI Components/Layouts/Frame Window",
  120. // new FeatureFrameWindow());
  121. registerFeature("/UI Components/Data handling", new IntroDataHandling());
  122. registerFeature("/UI Components/Data handling/Embedded Objects",
  123. new FeatureEmbedded());
  124. registerFeature("/UI Components/Data handling/Upload",
  125. new FeatureUpload());
  126. registerFeature("/Data Model", new IntroDataModel());
  127. registerFeature("/Data Model/Properties", new FeatureProperties());
  128. registerFeature("/Data Model/Items", new FeatureItems());
  129. registerFeature("/Data Model/Containers", new FeatureContainers());
  130. registerFeature("/Data Model/Validators", new FeatureValidators());
  131. registerFeature("/Data Model/Buffering", new FeatureBuffering());
  132. registerFeature("/Terminal", new IntroTerminal());
  133. registerFeature("/Terminal/Parameters and URI Handling",
  134. new FeatureParameters());
  135. // Pre-open all menus
  136. for (Iterator i = features.getItemIds().iterator(); i.hasNext();)
  137. features.expandItem(i.next());
  138. // Add demo component and tabs
  139. currentFeature = new FeatureTable();
  140. layout.addComponent(currentFeature);
  141. // Add properties
  142. right = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
  143. layout.addComponent(right);
  144. propertiesSelect = new Button("Show properties", this);
  145. propertiesSelect.setSwitchMode(true);
  146. right.addComponent(propertiesSelect);
  147. properties = currentFeature.getPropertyPanel();
  148. properties.setVisible(false);
  149. right.addComponent(properties);
  150. }
  151. public void registerFeature(String path, Feature feature) {
  152. StringTokenizer st = new StringTokenizer(path, "/");
  153. String id = "";
  154. String parentId = null;
  155. while (st.hasMoreTokens()) {
  156. String token = st.nextToken();
  157. id += "/" + token;
  158. if (!features.containsId(id)) {
  159. features.addItem(id);
  160. features.setChildrenAllowed(id, false);
  161. }
  162. features.getContainerProperty(id, "name").setValue(token);
  163. if (parentId != null) {
  164. features.setChildrenAllowed(parentId, true);
  165. features.setParent(id, parentId);
  166. }
  167. if (!st.hasMoreTokens())
  168. features.getContainerProperty(id, "feature").setValue(feature);
  169. parentId = id;
  170. }
  171. }
  172. public void valueChange(Property.ValueChangeEvent event) {
  173. // Change feature
  174. if (event.getProperty() == features) {
  175. Object id = features.getValue();
  176. if (id != null) {
  177. if (features.areChildrenAllowed(id))
  178. features.expandItem(id);
  179. Property p = features.getContainerProperty(id, "feature");
  180. Feature feature = p != null ? ((Feature) p.getValue()) : null;
  181. if (feature != null) {
  182. layout.replaceComponent(currentFeature, feature);
  183. currentFeature = feature;
  184. properties = feature.getPropertyPanel();
  185. if (properties != null) {
  186. Iterator i = right.getComponentIterator();
  187. i.next();
  188. PropertyPanel oldProps = (PropertyPanel) i.next();
  189. if (oldProps != null)
  190. right.replaceComponent(oldProps, properties);
  191. else
  192. right.addComponent(properties);
  193. properties.setVisible(((Boolean) propertiesSelect
  194. .getValue()).booleanValue());
  195. }
  196. getWindow()
  197. .setCaption(
  198. "IT Mill Toolkit Features / "
  199. + features.getContainerProperty(id,
  200. "name"));
  201. }
  202. }
  203. } else if (event.getProperty() == themeSelector) {
  204. getApplication().setTheme(themeSelector.toString());
  205. }
  206. }
  207. public void buttonClick(ClickEvent event) {
  208. properties.setVisible(((Boolean) propertiesSelect.getValue())
  209. .booleanValue());
  210. }
  211. }