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.

GridLayoutRequiredIndicatorLocation.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package com.vaadin.tests.components.gridlayout;
  2. import com.vaadin.server.Page;
  3. import com.vaadin.server.VaadinRequest;
  4. import com.vaadin.tests.components.AbstractReindeerTestUI;
  5. import com.vaadin.ui.Alignment;
  6. import com.vaadin.ui.GridLayout;
  7. import com.vaadin.ui.Label;
  8. import com.vaadin.ui.VerticalLayout;
  9. import com.vaadin.v7.ui.TextField;
  10. /**
  11. * Test for grid required indicator location within slots.
  12. */
  13. public class GridLayoutRequiredIndicatorLocation
  14. extends AbstractReindeerTestUI {
  15. @Override
  16. protected void setup(VaadinRequest request) {
  17. Page.getCurrent().getStyles()
  18. .add(".allow-overflow { overflow: visible; }");
  19. Page.getCurrent().getStyles()
  20. .add(".colored { background: lime; overflow: visible; }");
  21. Page.getCurrent().getStyles()
  22. .add(".pink { background: pink; overflow: visible; }");
  23. Page.getCurrent().getStyles()
  24. .add(".v-gridlayout-slot { border: 1px solid red; }");
  25. GridLayout rootLayout = new GridLayout(2, 2);
  26. rootLayout.addStyleName("allow-overflow");
  27. rootLayout.setSpacing(true);
  28. addComponent(rootLayout);
  29. GridLayout gridLayout = createGridLayout(false);
  30. gridLayout.addStyleName("allow-overflow");
  31. gridLayout.addStyleName("colored");
  32. rootLayout.addComponent(gridLayout);
  33. // for reference, VerticalLayout does it right
  34. VerticalLayout vl = createVerticalLayout(false);
  35. vl.addStyleName("allow-overflow");
  36. vl.addStyleName("colored");
  37. rootLayout.addComponent(vl);
  38. GridLayout gridLayout2 = createGridLayout(true);
  39. gridLayout2.addStyleName("allow-overflow");
  40. gridLayout2.addStyleName("colored");
  41. rootLayout.addComponent(gridLayout2);
  42. VerticalLayout vl2 = createVerticalLayout(true);
  43. vl2.addStyleName("allow-overflow");
  44. vl2.addStyleName("colored");
  45. rootLayout.addComponent(vl2);
  46. }
  47. private VerticalLayout createVerticalLayout(boolean useCaption) {
  48. VerticalLayout vl = new VerticalLayout();
  49. vl.setMargin(false);
  50. vl.setSpacing(false);
  51. vl.setWidth("320px");
  52. addLabel(vl, "200px", Alignment.MIDDLE_LEFT, useCaption);
  53. addLabel(vl, "40%", Alignment.MIDDLE_LEFT, useCaption);
  54. addLabel(vl, "100%", Alignment.MIDDLE_LEFT, useCaption);
  55. addLabel(vl, "200px", Alignment.MIDDLE_CENTER, useCaption);
  56. addLabel(vl, "30%", Alignment.MIDDLE_CENTER, useCaption);
  57. addLabel(vl, "100%", Alignment.MIDDLE_CENTER, useCaption);
  58. addLabel(vl, "200px", Alignment.MIDDLE_RIGHT, useCaption);
  59. addLabel(vl, "50%", Alignment.MIDDLE_RIGHT, useCaption);
  60. addLabel(vl, "100%", Alignment.MIDDLE_RIGHT, useCaption);
  61. return vl;
  62. }
  63. private GridLayout createGridLayout(boolean useCaption) {
  64. GridLayout gridLayout = new GridLayout();
  65. gridLayout.setColumns(2);
  66. gridLayout.setWidth("500px");
  67. gridLayout.setColumnExpandRatio(0, 0);
  68. gridLayout.setColumnExpandRatio(1, 1);
  69. addLabel(gridLayout, "200px", Alignment.MIDDLE_LEFT, useCaption);
  70. addLabel(gridLayout, "40%", Alignment.MIDDLE_LEFT, useCaption);
  71. addLabel(gridLayout, "100%", Alignment.MIDDLE_LEFT, useCaption);
  72. addLabel(gridLayout, "200px", Alignment.MIDDLE_CENTER, useCaption);
  73. addLabel(gridLayout, "30%", Alignment.MIDDLE_CENTER, useCaption);
  74. addLabel(gridLayout, "100%", Alignment.MIDDLE_CENTER, useCaption);
  75. addLabel(gridLayout, "200px", Alignment.MIDDLE_RIGHT, useCaption);
  76. addLabel(gridLayout, "50%", Alignment.MIDDLE_RIGHT, useCaption);
  77. addLabel(gridLayout, "100%", Alignment.MIDDLE_RIGHT, useCaption);
  78. return gridLayout;
  79. }
  80. private void addLabel(GridLayout layout, String width, Alignment alignment,
  81. boolean useCaption) {
  82. Label label = new Label("Align " + alignment.getHorizontalAlignment()
  83. + " width " + width);
  84. label.setWidth("180px");
  85. label.addStyleName("pink");
  86. layout.addComponent(label);
  87. // TODO also test with captions
  88. TextField field = new TextField(useCaption ? "caption" : null);
  89. field.setRequired(true);
  90. field.setWidth(width);
  91. layout.addComponent(field);
  92. layout.setComponentAlignment(field, alignment);
  93. }
  94. private void addLabel(VerticalLayout layout, String width,
  95. Alignment alignment, boolean useCaption) {
  96. TextField field = new TextField(useCaption ? "caption" : null);
  97. field.setRequired(true);
  98. field.setWidth(width);
  99. layout.addComponent(field);
  100. layout.setComponentAlignment(field, alignment);
  101. }
  102. @Override
  103. protected Integer getTicketNumber() {
  104. return 18418;
  105. }
  106. @Override
  107. protected String getTestDescription() {
  108. return "If a GridLayout slot has a size smaller than 100%, the required indicators should be at the end of each field";
  109. }
  110. }