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.2KB

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