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.

CellStyleGeneratorTest.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.tests.components.TestBase;
  3. import com.vaadin.tests.util.TestUtils;
  4. import com.vaadin.ui.Table;
  5. import com.vaadin.ui.Table.CellStyleGenerator;
  6. @SuppressWarnings("serial")
  7. public class CellStyleGeneratorTest extends TestBase {
  8. @Override
  9. protected void setup() {
  10. TestUtils
  11. .injectCSS(getMainWindow(),
  12. ".v-table-cell-content-red{background:red;}.v-table-row-blue{background:blue;}");
  13. CellStyleGenerator g = new CellStyleGenerator() {
  14. @Override
  15. public String getStyle(Table source, Object itemId,
  16. Object propertyId) {
  17. if (propertyId != null && propertyId.equals("red")) {
  18. return "red";
  19. } else if (itemId.equals("blue") && propertyId == null) {
  20. // row style
  21. return "blue";
  22. }
  23. return null;
  24. }
  25. };
  26. Table table = new Table();
  27. table.addContainerProperty("foo", String.class, "foo");
  28. table.addContainerProperty("red", String.class, "red");
  29. table.addItem();
  30. table.addItem("blue");
  31. table.setCellStyleGenerator(g);
  32. addComponent(table);
  33. table = new Table();
  34. table.addContainerProperty("foo", String.class, "foo");
  35. table.addContainerProperty("red", String.class, "red");
  36. table.addItem();
  37. table.addItem("blue");
  38. table.setCellStyleGenerator(g);
  39. table.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
  40. addComponent(table);
  41. }
  42. @Override
  43. protected String getDescription() {
  44. return "Cell style generators should work";
  45. }
  46. @Override
  47. protected Integer getTicketNumber() {
  48. return null;
  49. }
  50. }