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.

TableToggleVisibility.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package com.vaadin.tests.components.table;
  2. import java.text.DecimalFormat;
  3. import com.vaadin.tests.components.AbstractTestCase;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.HorizontalLayout;
  6. import com.vaadin.ui.HorizontalSplitPanel;
  7. import com.vaadin.ui.Label;
  8. import com.vaadin.ui.LegacyWindow;
  9. import com.vaadin.ui.VerticalLayout;
  10. import com.vaadin.v7.ui.Table;
  11. public class TableToggleVisibility extends AbstractTestCase {
  12. private static final int[] LENGTHS = { 20, 22, 10 };
  13. @Override
  14. public void init() {
  15. DecimalFormat format = new DecimalFormat("000");
  16. Table[] tables = new Table[3];
  17. Button[] buttons = new Button[3];
  18. VerticalLayout leftComponent = new VerticalLayout();
  19. leftComponent.setMargin(true);
  20. leftComponent.setSpacing(true);
  21. // Toolbar with buttons to hide or show lists
  22. HorizontalLayout toolBar = new HorizontalLayout();
  23. toolBar.setSpacing(true);
  24. toolBar.setMargin(true);
  25. leftComponent.addComponent(toolBar);
  26. leftComponent.setExpandRatio(toolBar, 0.0f);
  27. // List of trucks -----------------------
  28. tables[0] = new Table("Trucks");
  29. tables[0].addContainerProperty("Brand", String.class, null);
  30. tables[0].addContainerProperty("Model", String.class, null);
  31. tables[0].addContainerProperty("License Plate", String.class, null);
  32. for (int i = 1; i < LENGTHS[0]; i++) {
  33. tables[0].addItem(
  34. new Object[] { "MAN", "XYZ", "1-ABC-" + format.format(i) },
  35. Integer.valueOf(i));
  36. }
  37. tables[0].setPageLength(LENGTHS[0]);
  38. tables[0].setWidth("100%");
  39. tables[0].setHeight("100%");
  40. tables[0].setSelectable(true);
  41. leftComponent.addComponent(tables[0]);
  42. leftComponent.setExpandRatio(tables[0], 1.0f);
  43. // List of trailers ----------------------
  44. tables[1] = new Table("Trailers");
  45. tables[1].addContainerProperty("Type", String.class, null);
  46. tables[1].addContainerProperty("License Plate", String.class, null);
  47. for (int i = 1; i < LENGTHS[1]; i++) {
  48. tables[1].addItem(
  49. new Object[] { "Cooler", "1-QQQ-" + format.format(i) },
  50. Integer.valueOf(i));
  51. }
  52. tables[1].setPageLength(LENGTHS[1]);
  53. tables[1].setWidth("100%");
  54. tables[1].setHeight("100%");
  55. tables[1].setSelectable(true);
  56. leftComponent.addComponent(tables[1]);
  57. leftComponent.setExpandRatio(tables[1], 1.0f);
  58. // List of drivers ------------------------
  59. tables[2] = new Table("Drivers");
  60. tables[2].addContainerProperty("First Name", String.class, null);
  61. tables[2].addContainerProperty("Last Name", String.class, null);
  62. tables[2].addContainerProperty("HR ID", String.class, null);
  63. for (int i = 1; i < LENGTHS[2]; i++) {
  64. tables[2].addItem(
  65. new Object[] { "King", "Vabis", "HR-" + format.format(i) },
  66. Integer.valueOf(i));
  67. }
  68. tables[2].setPageLength(LENGTHS[2]);
  69. tables[2].setWidth("100%");
  70. tables[2].setHeight("100%");
  71. tables[2].setSelectable(true);
  72. leftComponent.addComponent(tables[2]);
  73. leftComponent.setExpandRatio(tables[2], 1.0f);
  74. leftComponent.setWidth("100%");
  75. HorizontalSplitPanel split = new HorizontalSplitPanel();
  76. split.setFirstComponent(leftComponent);
  77. VerticalLayout rightComponent = new VerticalLayout();
  78. rightComponent.setMargin(true);
  79. rightComponent.addComponent(new Label("Left blank!"));
  80. split.setSecondComponent(rightComponent);
  81. split.setSizeFull();
  82. VerticalLayout mainLayout = new VerticalLayout();
  83. mainLayout.setSizeFull();
  84. mainLayout.addComponent(split);
  85. mainLayout.setExpandRatio(split, 1.0f);
  86. LegacyWindow mainWindow = new LegacyWindow("Visibilitybug Application",
  87. mainLayout);
  88. mainWindow.setSizeFull();
  89. setMainWindow(mainWindow);
  90. // complete toolbar
  91. for (int i = 0; i < buttons.length; i++) {
  92. buttons[i] = new ToggleButton(tables[i]);
  93. toolBar.addComponent(buttons[i]);
  94. }
  95. }
  96. // Button to switch the visibility of a table.
  97. private static class ToggleButton extends Button {
  98. private Table table;
  99. private ToggleButton(Table table) {
  100. this.table = table;
  101. setCaption("- " + table.getCaption());
  102. addClickListener(event -> {
  103. boolean wasVisible = ToggleButton.this.table.isVisible();
  104. ToggleButton.this.table.setVisible(!wasVisible);
  105. setCaption((wasVisible ? "+ " : "- ")
  106. + ToggleButton.this.table.getCaption());
  107. setDescription(
  108. (wasVisible ? "Show " : "Hide ") + "the list with "
  109. + ToggleButton.this.table.getCaption());
  110. });
  111. }
  112. }
  113. @Override
  114. protected String getDescription() {
  115. return "Test for hiding and showing tables. Click a button to show/hide one of the tables. The tables are all 100% wide and should be rendered the same way after being hidden and shown again.";
  116. }
  117. @Override
  118. protected Integer getTicketNumber() {
  119. return 6494;
  120. }
  121. }