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.

TablesCssTest.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.vaadin.tests.components.uitest.components;
  2. import java.util.HashSet;
  3. import java.util.Iterator;
  4. import com.vaadin.event.Action;
  5. import com.vaadin.server.ThemeResource;
  6. import com.vaadin.tests.components.uitest.TestSampler;
  7. import com.vaadin.tests.util.TestUtils;
  8. import com.vaadin.ui.Component;
  9. import com.vaadin.ui.GridLayout;
  10. import com.vaadin.v7.ui.Table;
  11. import com.vaadin.v7.ui.themes.ChameleonTheme;
  12. import com.vaadin.v7.ui.themes.Reindeer;
  13. @SuppressWarnings("deprecation")
  14. public class TablesCssTest extends GridLayout {
  15. private TestSampler parent;
  16. private int debugIdCounter = 0;
  17. private final Action ACTION_MARK = new Action("Mark");
  18. private final Action ACTION_UNMARK = new Action("Unmark");
  19. private final Action ACTION_LOG = new Action("Save");
  20. private final Action[] ACTIONS_UNMARKED = { ACTION_MARK, ACTION_LOG };
  21. private final Action[] ACTIONS_MARKED = { ACTION_UNMARK, ACTION_LOG };
  22. public TablesCssTest(TestSampler parent) {
  23. super();
  24. setSpacing(true);
  25. setColumns(2);
  26. setWidth("100%");
  27. this.parent = parent;
  28. createTableWith("CC & flags, default table", null);
  29. createTableWith("Borderless", ChameleonTheme.TABLE_BORDERLESS);
  30. createTableWith("Big", ChameleonTheme.TABLE_BIG);
  31. createTableWith("Small", ChameleonTheme.TABLE_SMALL);
  32. createTableWith("Striped", ChameleonTheme.TABLE_STRIPED);
  33. createTableWith("Strong", Reindeer.TABLE_STRONG);
  34. parent.addReadOnlyChangeListener(event -> {
  35. Iterator<Component> iterator = iterator();
  36. while (iterator.hasNext()) {
  37. Component c = iterator.next();
  38. if (c instanceof Table) {
  39. Table t = (Table) c;
  40. t.setReadOnly(!t.isReadOnly());
  41. }
  42. }
  43. });
  44. }
  45. private void createTableWith(String caption, String primaryStyleName) {
  46. final HashSet<Object> markedRows = new HashSet<>();
  47. final Table t;
  48. if (caption != null) {
  49. t = new Table(caption);
  50. } else {
  51. t = new Table();
  52. }
  53. t.setId("table" + debugIdCounter++);
  54. if (primaryStyleName != null) {
  55. t.addStyleName(primaryStyleName);
  56. }
  57. t.setWidth("100%");
  58. t.setHeight("100px");
  59. t.setSelectable(true);
  60. t.setMultiSelect(true);
  61. t.setImmediate(true);
  62. t.setContainerDataSource(TestUtils.getISO3166Container());
  63. t.setColumnReorderingAllowed(true);
  64. t.setColumnCollapsingAllowed(true);
  65. // t.setColumnHeaders(new String[] { "Country", "Code", "Icon file" });
  66. t.setColumnIcon(TestUtils.iso3166_PROPERTY_NAME,
  67. new ThemeResource(TestSampler.ICON_URL));
  68. // Actions (a.k.a context menu)
  69. t.addActionHandler(new Action.Handler() {
  70. @Override
  71. public Action[] getActions(Object target, Object sender) {
  72. if (markedRows.contains(target)) {
  73. return ACTIONS_MARKED;
  74. } else {
  75. return ACTIONS_UNMARKED;
  76. }
  77. }
  78. @Override
  79. public void handleAction(Action action, Object sender,
  80. Object target) {
  81. // We just want the actions UI.. don't care about the logic...
  82. if (ACTION_MARK == action) {
  83. markedRows.add(target);
  84. t.refreshRowCache();
  85. } else if (ACTION_UNMARK == action) {
  86. markedRows.remove(target);
  87. t.refreshRowCache();
  88. }
  89. }
  90. });
  91. addComponent(t);
  92. parent.registerComponent(t);
  93. }
  94. }