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.

AbstractOrderedLayoutDeclarativeTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright 2000-2014 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.abstractorderedlayout;
  17. import java.util.Arrays;
  18. import java.util.List;
  19. import org.junit.Test;
  20. import com.vaadin.shared.ui.label.ContentMode;
  21. import com.vaadin.tests.server.component.DeclarativeMarginTestBase;
  22. import com.vaadin.ui.AbstractOrderedLayout;
  23. import com.vaadin.ui.Alignment;
  24. import com.vaadin.ui.Button;
  25. import com.vaadin.ui.Label;
  26. import com.vaadin.ui.VerticalLayout;
  27. /**
  28. * Tests declarative support for AbstractOrderedLayout.
  29. *
  30. * @since
  31. * @author Vaadin Ltd
  32. */
  33. public class AbstractOrderedLayoutDeclarativeTest extends
  34. DeclarativeMarginTestBase<AbstractOrderedLayout> {
  35. private List<String> defaultAlignments = Arrays.asList(new String[] {
  36. ":top", ":left" });
  37. @Test
  38. public void testMargins() {
  39. testMargins("vaadin-vertical-layout");
  40. }
  41. @Test
  42. public void testExpandRatio() {
  43. String design = getDesign(1);
  44. AbstractOrderedLayout layout = getLayout(1, null);
  45. testRead(design, layout);
  46. testWrite(design, layout);
  47. design = getDesign(0.25f);
  48. layout = getLayout(0.25f, null);
  49. testRead(design, layout);
  50. testWrite(design, layout);
  51. }
  52. @Test
  53. public void testAlignment() {
  54. String design = getDesign(0, ":top", ":left");
  55. AbstractOrderedLayout layout = getLayout(0, Alignment.TOP_LEFT);
  56. testRead(design, layout);
  57. testWrite(design, layout);
  58. design = getDesign(0, ":middle", ":center");
  59. layout = getLayout(0, Alignment.MIDDLE_CENTER);
  60. testRead(design, layout);
  61. testWrite(design, layout);
  62. design = getDesign(0, ":bottom", ":right");
  63. layout = getLayout(0, Alignment.BOTTOM_RIGHT);
  64. testRead(design, layout);
  65. testWrite(design, layout);
  66. }
  67. private String getDesign(float expandRatio, String... alignments) {
  68. String result = "<vaadin-vertical-layout caption=test-layout>";
  69. result += "<vaadin-label caption=test-label ";
  70. String ratioString = expandRatio == 1.0f ? null : String
  71. .valueOf(expandRatio);
  72. if (expandRatio != 0) {
  73. if (ratioString == null) {
  74. result += ":expand";
  75. } else {
  76. result += ":expand=" + ratioString;
  77. }
  78. }
  79. for (String alignment : alignments) {
  80. if (!defaultAlignments.contains(alignment)) {
  81. result += " " + alignment;
  82. }
  83. }
  84. result += "></vaadin-label><vaadin-button ";
  85. if (expandRatio != 0) {
  86. if (ratioString == null) {
  87. result += ":expand";
  88. } else {
  89. result += ":expand=" + ratioString;
  90. }
  91. }
  92. for (String alignment : alignments) {
  93. if (!defaultAlignments.contains(alignment)) {
  94. result += " " + alignment;
  95. }
  96. }
  97. result += "></vaadin-button></vaadin-vertical-layout>";
  98. return result;
  99. }
  100. private AbstractOrderedLayout getLayout(float expandRatio,
  101. Alignment alignment) {
  102. VerticalLayout layout = new VerticalLayout();
  103. layout.setCaption("test-layout");
  104. Label l = new Label();
  105. l.setCaption("test-label");
  106. l.setContentMode(ContentMode.HTML);
  107. layout.addComponent(l);
  108. layout.setExpandRatio(l, expandRatio);
  109. Button b = new Button();
  110. b.setCaptionAsHtml(true);
  111. layout.addComponent(b);
  112. layout.setExpandRatio(b, expandRatio);
  113. if (alignment != null) {
  114. layout.setComponentAlignment(l, alignment);
  115. layout.setComponentAlignment(b, alignment);
  116. }
  117. return layout;
  118. }
  119. }