Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

FeatureTable.java 7.1KB

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