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.

FeatureTable.java 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /* *************************************************************************
  2. Enably Toolkit
  3. Development of Browser User Intarfaces 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/license.txt. Use of this product might
  8. require purchasing a commercial license from IT Mill Ltd. For guidelines
  9. on usage, see license/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@enably.com
  15. Finland company www: www.enably.com
  16. Primary source for information and releases: www.enably.com
  17. ********************************************************************** */
  18. package com.enably.tk.demo.features;
  19. import com.enably.tk.event.Action;
  20. import com.enably.tk.ui.*;
  21. public class FeatureTable extends Feature implements Action.Handler {
  22. private static final String[] firstnames =
  23. new String[] {
  24. "John",
  25. "Mary",
  26. "Joe",
  27. "Sarah",
  28. "Jeff",
  29. "Jane",
  30. "Peter",
  31. "Marc",
  32. "Josie",
  33. "Linus" };
  34. private static final String[] lastnames =
  35. new String[] {
  36. "Torvalds",
  37. "Smith",
  38. "Jones",
  39. "Beck",
  40. "Sheridan",
  41. "Picard",
  42. "Hill",
  43. "Fielding",
  44. "Einstein" };
  45. private static final String[] eyecolors =
  46. new String[] { "Blue", "Green", "Brown" };
  47. private static final String[] haircolors =
  48. new String[] { "Brown", "Black", "Red", "Blonde" };
  49. private Table t;
  50. private boolean actionsActive = false;
  51. private Button actionHandlerSwitch =
  52. new Button("Activate actions", this, "toggleActions");
  53. public void toggleActions() {
  54. if (actionsActive) {
  55. t.removeActionHandler(this);
  56. actionsActive = false;
  57. actionHandlerSwitch.setCaption("Activate Actions");
  58. } else {
  59. t.addActionHandler(this);
  60. actionsActive = true;
  61. actionHandlerSwitch.setCaption("Deactivate Actions");
  62. }
  63. }
  64. protected Component getDemoComponent() {
  65. OrderedLayout l = new OrderedLayout();
  66. // Sample table
  67. t = new Table("Most Wanted Persons List");
  68. t.setPageLength(10);
  69. l.addComponent(t);
  70. // Add columns to table
  71. t.addContainerProperty("Firstname", String.class, "");
  72. t.addContainerProperty("Lastname", String.class, "");
  73. t.addContainerProperty("Age", String.class, "");
  74. t.addContainerProperty("Eyecolor", String.class, "");
  75. t.addContainerProperty("Haircolor", String.class, "");
  76. // Add random rows to table
  77. for (int j = 0; j < 50; j++) {
  78. Object id = t.addItem(
  79. new Object[] {
  80. firstnames[(int) (Math.random() * (firstnames.length-1))],
  81. lastnames[(int) (Math.random() * (lastnames.length-1))],
  82. new Integer((int) (Math.random() * 80)),
  83. eyecolors[(int) (Math.random() * 3)],
  84. haircolors[(int) (Math.random() * 4)] },
  85. new Integer(j));
  86. t.setItemIcon(id,getSampleIcon());
  87. }
  88. // Actions
  89. l.addComponent(this.actionHandlerSwitch);
  90. // Properties
  91. PropertyPanel p = new PropertyPanel(t);
  92. Form ap =
  93. p.createBeanPropertySet(
  94. new String[] {
  95. "pageLength",
  96. "rowHeaderMode",
  97. "selectable",
  98. "columnHeaderMode",
  99. "columnCollapsingAllowed",
  100. "columnReorderingAllowed"});
  101. ap.replaceWithSelect(
  102. "columnHeaderMode",
  103. new Object[] {
  104. new Integer(Table.COLUMN_HEADER_MODE_EXPLICIT),
  105. new Integer(Table.COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID),
  106. new Integer(Table.COLUMN_HEADER_MODE_HIDDEN),
  107. new Integer(Table.COLUMN_HEADER_MODE_ID)},
  108. new Object[] {
  109. "Explicit",
  110. "Explicit defaults ID",
  111. "Hidden",
  112. "ID" });
  113. ap.replaceWithSelect(
  114. "rowHeaderMode",
  115. new Object[] {
  116. new Integer(Table.ROW_HEADER_MODE_EXPLICIT),
  117. new Integer(Table.ROW_HEADER_MODE_EXPLICIT_DEFAULTS_ID),
  118. new Integer(Table.ROW_HEADER_MODE_HIDDEN),
  119. new Integer(Table.ROW_HEADER_MODE_ICON_ONLY),
  120. new Integer(Table.ROW_HEADER_MODE_ID),
  121. new Integer(Table.ROW_HEADER_MODE_INDEX),
  122. new Integer(Table.ROW_HEADER_MODE_ITEM),
  123. new Integer(Table.ROW_HEADER_MODE_PROPERTY)},
  124. new Object[] {
  125. "Explicit",
  126. "Explicit defaults ID",
  127. "Hidden",
  128. "Icon only",
  129. "ID",
  130. "Index",
  131. "Item",
  132. "Property" });
  133. Select themes = (Select) p.getField("style");
  134. themes
  135. .addItem("list")
  136. .getItemProperty(themes.getItemCaptionPropertyId())
  137. .setValue("list");
  138. p.addProperties("Table Properties", ap);
  139. l.addComponent(p);
  140. return l;
  141. }
  142. protected String getExampleSrc() {
  143. return "// Sample table\n"
  144. + "t = new Table(\"Most Wanted Persons List\");\n"
  145. + "t.setPageLength(10);\n\n"
  146. + "// Add columns to table\n"
  147. + "t.addContainerProperty(\"Firstname\", String.class, \"\");\n"
  148. + "t.addContainerProperty(\"Lastname\", String.class, \"\");\n"
  149. + "t.addContainerProperty(\"Age\", String.class, \"\");\n"
  150. + "t.addContainerProperty(\"Eyecolor\", String.class, \"\");\n"
  151. + "t.addContainerProperty(\"Haircolor\", String.class, \"\");\n\n"
  152. + "// Add random rows to table\n"
  153. + "for (int j = 0; j < 50; j++) {\n"
  154. + " t.addItem(\n"
  155. + " new Object[] {\n"
  156. + " firstnames[(int) (Math.random() * 9)],\n"
  157. + " lastnames[(int) (Math.random() * 9)],\n"
  158. + " new Integer((int) (Math.random() * 80)),\n"
  159. + " eyecolors[(int) (Math.random() * 3)],\n"
  160. + " haircolors[(int) (Math.random() * 4)] },\n"
  161. + " new Integer(j));\n"
  162. + "}\n";
  163. }
  164. protected String getDescriptionXHTML() {
  165. return "<p>The Table component is designed for displaying large volumes of tabular data, "
  166. + "in multiple pages whenever needed.</p> "
  167. + "<p>Selection of the displayed data is supported both in selecting exclusively one row "
  168. + "or multiple rows at the same time. For each row, there may be a set of actions associated, "
  169. + "depending on the theme these actions may be displayed either as a drop-down "
  170. + "menu for each row or a set of command buttons.</p><p>"
  171. + "Table may be connected to any datasource implementing the <code>Container</code> interface."
  172. + "This way data found in external datasources can be directly presented in the table component."
  173. + "</p><p>"
  174. + "Table implements a number of features and you can test most of them in the table demo tab.</p>";
  175. }
  176. protected String getImage() {
  177. return "table.jpg";
  178. }
  179. protected String getTitle() {
  180. return "Table";
  181. }
  182. private Action ACTION1 = new Action("Action 1");
  183. private Action ACTION2 = new Action("Action 2");
  184. private Action ACTION3 = new Action("Action 3");
  185. private Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 };
  186. public Action[] getActions(Object target, Object sender) {
  187. return actions;
  188. }
  189. public void handleAction(Action action, Object sender, Object target) {
  190. t.setDescription(
  191. "Last action clicked was '"
  192. + action.getCaption()
  193. + "' on item '"
  194. + t.getItem(target).toString()
  195. + "'");
  196. }
  197. }