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.

GridColumnDeclarativeTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.server.component.grid.declarative;
  17. import com.vaadin.ui.LegacyGrid;
  18. import org.junit.Test;
  19. public class GridColumnDeclarativeTest extends GridDeclarativeTestBase {
  20. @Test
  21. public void testSimpleGridColumns() {
  22. String design = "<vaadin-legacy-grid><table>"//
  23. + "<colgroup>"
  24. + " <col sortable width='100' property-id='Column1'>"
  25. + " <col sortable=false max-width='200' expand='2' property-id='Column2'>"
  26. + " <col sortable editable=false resizable=false min-width='15' expand='1' property-id='Column3'>"
  27. + " <col sortable hidable hiding-toggle-caption='col 4' property-id='Column4'>"
  28. + " <col sortable hidden property-id='Column5'>"
  29. + "</colgroup>" //
  30. + "<thead />" //
  31. + "</table></vaadin-legacy-grid>";
  32. LegacyGrid grid = new LegacyGrid();
  33. grid.addColumn("Column1", String.class).setWidth(100);
  34. grid.addColumn("Column2", String.class).setMaximumWidth(200)
  35. .setExpandRatio(2).setSortable(false);
  36. grid.addColumn("Column3", String.class).setMinimumWidth(15)
  37. .setExpandRatio(1).setEditable(false).setResizable(false);
  38. grid.addColumn("Column4", String.class).setHidable(true)
  39. .setHidingToggleCaption("col 4").setResizable(true);
  40. grid.addColumn("Column5", String.class).setHidden(true);
  41. // Remove the default header
  42. grid.removeHeaderRow(grid.getDefaultHeaderRow());
  43. // Use the read grid component to do another pass on write.
  44. testRead(design, grid, true);
  45. testWrite(design, grid);
  46. }
  47. @Test
  48. public void testReadColumnsWithoutPropertyId() {
  49. String design = "<vaadin-legacy-grid><table>"//
  50. + "<colgroup>"
  51. + " <col sortable=true width='100' property-id='Column1'>"
  52. + " <col sortable=true max-width='200' expand='2'>" // property-id="property-1"
  53. + " <col sortable=true min-width='15' expand='1' property-id='Column3'>"
  54. + " <col sortable=true hidden=true hidable=true hiding-toggle-caption='col 4'>" // property-id="property-3"
  55. + "</colgroup>" //
  56. + "</table></vaadin-legacy-grid>";
  57. LegacyGrid grid = new LegacyGrid();
  58. grid.addColumn("Column1", String.class).setWidth(100);
  59. grid.addColumn("property-1", String.class).setMaximumWidth(200)
  60. .setExpandRatio(2);
  61. grid.addColumn("Column3", String.class).setMinimumWidth(15)
  62. .setExpandRatio(1);
  63. grid.addColumn("property-3", String.class).setHidable(true)
  64. .setHidden(true).setHidingToggleCaption("col 4");
  65. testRead(design, grid);
  66. }
  67. @Test
  68. public void testReadEmptyExpand() {
  69. String design = "<vaadin-legacy-grid><table>"//
  70. + "<colgroup>" + " <col sortable=true expand />"
  71. + "</colgroup>" //
  72. + "</table></vaadin-legacy-grid>";
  73. LegacyGrid grid = new LegacyGrid();
  74. grid.addColumn("property-0", String.class).setExpandRatio(1);
  75. testRead(design, grid);
  76. }
  77. @Test
  78. public void testReadColumnWithNoAttributes() {
  79. String design = "<vaadin-legacy-grid><table>"//
  80. + "<colgroup>" //
  81. + " <col />" //
  82. + "</colgroup>" //
  83. + "</table></vaadin-legacy-grid>";
  84. LegacyGrid grid = new LegacyGrid();
  85. grid.addColumn("property-0", String.class);
  86. testRead(design, grid);
  87. }
  88. }