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.

TableDemoApplication.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package com.itmill.tk.demo.table;
  2. import com.itmill.tk.Application;
  3. import com.itmill.tk.event.Action;
  4. import com.itmill.tk.terminal.ExternalResource;
  5. import com.itmill.tk.ui.Button;
  6. import com.itmill.tk.ui.DateField;
  7. import com.itmill.tk.ui.GridLayout;
  8. import com.itmill.tk.ui.Label;
  9. import com.itmill.tk.ui.Link;
  10. import com.itmill.tk.ui.Panel;
  11. import com.itmill.tk.ui.Select;
  12. import com.itmill.tk.ui.TabSheet;
  13. import com.itmill.tk.ui.Table;
  14. import com.itmill.tk.ui.TextField;
  15. import com.itmill.tk.ui.Tree;
  16. import com.itmill.tk.ui.Window;
  17. public class TableDemoApplication extends Application implements Action.Handler {
  18. private Table myTable;
  19. private String[] texts = {"Lorem","Ipsum","Dolor","Sit","Amet"};
  20. private Action deleteAction = new Action("Delete row");
  21. public void init() {
  22. Window mainWindow = new Window("Millstone Example");
  23. setMainWindow(mainWindow);
  24. GridLayout gl1 = new GridLayout(1,2);
  25. GridLayout gl2 = new GridLayout(2,1);
  26. gl1.addComponent(gl2);
  27. myTable = new Table("Table caption");
  28. myTable.setMultiSelect(true);
  29. myTable.setPageLength(10);
  30. myTable.setSelectable(true);
  31. myTable.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID);
  32. myTable.addContainerProperty("text", String.class, "-");
  33. myTable.addContainerProperty("number", Integer.class, new Integer(0));
  34. //myTable.addContainerProperty("date", DateField.class, "");
  35. myTable.setColumnReorderingAllowed(true);
  36. myTable.setColumnCollapsingAllowed(true);
  37. myTable.addActionHandler(this);
  38. myTable.setRowHeaderMode(Table.ROW_HEADER_MODE_INDEX);
  39. //myTable.setDescription("Table description text.");
  40. DateField df = new DateField();
  41. df.setValue(new java.util.Date());
  42. df.setReadOnly(true);
  43. df.setResolution(DateField.RESOLUTION_DAY);
  44. df.setStyle("text");
  45. for(int i=0; i<10000; i++) {
  46. myTable.addItem(
  47. new Object[] {
  48. texts[(int) (Math.random() * 5)],
  49. new Integer((int) (Math.random() * 80))},
  50. new Integer(i));
  51. }
  52. TabSheet ts = new TabSheet();
  53. Panel codeSamplePanel = new Panel();
  54. codeSamplePanel.setCaption("Example panel");
  55. codeSamplePanel.setDescription("A code example how to implement a Table into your application.");
  56. codeSamplePanel.setStyle("light");
  57. TextField codeSample = new TextField("Code sample");
  58. codeSamplePanel.addComponent(codeSample);
  59. ts.addTab(codeSamplePanel, "Code Sample", null);
  60. Label info = new Label();
  61. info.setContentMode(Label.CONTENT_XHTML);
  62. info.setValue("<h1>Millstone AjaxAdapter</h1><p>Examples of Millstone components.</p><h2>Table Component demo</h2><p>General info about the component and its properties (static HTML).</p><h3>Third level heading</h3><h4>Subheading</h4><h5>Paragraph heading</h5><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce pharetra congue nunc. Vestibulum odio metus, tristiqueeu, venenatis eget, nonummy vel, mauris.</p><p>Mauris lobortis dictum dolor. Phasellus suscipit. Nam feugiat est in risus.</p>");
  63. ts.addTab(myTable,"Info", null);
  64. //mainWindow.addComponent(ts);
  65. //mainWindow.addComponent(info);
  66. //mainWindow.addComponent(myTable);
  67. /* Theme testing purposes */
  68. Button b = new Button("Button caption");
  69. //b.setStyle("link");
  70. //b.setDescription("Button description text.");
  71. //mainWindow.addComponent(b);
  72. Link lnk = new Link("Link caption",new ExternalResource("http://www.itmill.com"));
  73. lnk.setDescription("Link description text.");
  74. Panel show = new Panel("Panel caption");
  75. show.setStyle("");
  76. show.addComponent(lnk);
  77. show.setWidth(350);
  78. show.setWidthUnits(Panel.UNITS_PIXELS);
  79. show.setHeightUnits(Panel.UNITS_PIXELS);
  80. //mainWindow.addComponent(show);
  81. gl2.addComponent(info);
  82. gl2.addComponent(show);
  83. gl2.addComponent(codeSamplePanel);
  84. gl1.addComponent(myTable);
  85. gl1.addComponent(b);
  86. mainWindow.addComponent(gl1);
  87. Select s = new Select("Select Car");
  88. s.addItem("Audi");
  89. s.addItem("BMW");
  90. s.addItem("Chrysler");
  91. s.addItem("Volvo");
  92. //show.addComponent(s);
  93. // Create tree
  94. Tree t = new Tree("Family Tree");
  95. for (int i = 0; i < 4; i++) {
  96. t.addItem(texts[i]);
  97. String parent = texts[(int) (Math.random() * (texts.length - 1))];
  98. if (t.containsId(parent))
  99. t.setParent(texts[i],parent);
  100. }
  101. // Forbid childless people to have children (makes them leaves)
  102. for (int i = 0; i < 4; i++) {
  103. if (!t.hasChildren(texts[i])) {
  104. t.setChildrenAllowed(texts[i], false);
  105. }
  106. }
  107. //mainWindow.addComponent(t);
  108. /*
  109. Upload u = new Upload("Upload a file:", new uploadReceiver());
  110. mainWindow.addComponent(u);
  111. */
  112. }
  113. public Action[] getActions(Object arg0, Object arg1) {
  114. Action[] actions = {deleteAction};
  115. return actions;
  116. }
  117. public void handleAction(Action arg0, Object arg1, Object arg2) {
  118. if(arg0 != null) {
  119. if(arg0.getCaption() == "Delete row") {
  120. myTable.removeItem(arg2);
  121. }
  122. }
  123. }
  124. }