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.

BaseAddReplaceMove.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.layouts.layouttester;
  17. import com.vaadin.server.VaadinRequest;
  18. import com.vaadin.shared.ui.ContentMode;
  19. import com.vaadin.ui.AbstractComponent;
  20. import com.vaadin.ui.AbstractLayout;
  21. import com.vaadin.ui.Button;
  22. import com.vaadin.ui.Button.ClickEvent;
  23. import com.vaadin.ui.Button.ClickListener;
  24. import com.vaadin.ui.HorizontalLayout;
  25. import com.vaadin.ui.Label;
  26. import com.vaadin.v7.ui.Table;
  27. import com.vaadin.v7.ui.TextField;
  28. /**
  29. *
  30. * @since
  31. * @author Vaadin Ltd
  32. */
  33. public class BaseAddReplaceMove extends BaseLayoutTestUI {
  34. /**
  35. * @param layoutClass
  36. */
  37. public BaseAddReplaceMove(Class<? extends AbstractLayout> layoutClass) {
  38. super(layoutClass);
  39. }
  40. @Override
  41. protected void setup(VaadinRequest request) {
  42. init();
  43. buildLayout();
  44. super.setup(request);
  45. }
  46. private void buildLayout() {
  47. // Set undefined height to avoid expanding
  48. l2.setHeight(null);
  49. // extra layout from which components will be moved
  50. final HorizontalLayout source = new HorizontalLayout();
  51. Label label1 = new Label("OTHER LABEL 1");
  52. label1.setWidth("100%"); // Only to make test backwards compatible
  53. source.addComponent(label1);
  54. Label label2 = new Label("OTHER LABEL 2");
  55. label2.setWidth("100%"); // Only to make test backwards compatible
  56. source.addComponent(label2);
  57. final AbstractComponent c1 = new Label("<b>LABEL</b>",
  58. ContentMode.HTML);
  59. final AbstractComponent c2 = new Label("<b>LABEL</b>",
  60. ContentMode.HTML);
  61. final AbstractComponent c3 = new Table("TABLE");
  62. c3.setHeight("100px");
  63. c3.setWidth("100%");
  64. final Button btnAdd = new Button("Test add");
  65. final Button btnReplace = new Button("Test replace");
  66. final Button btnMove = new Button("Test move");
  67. final Button btnRemove = new Button("Test remove");
  68. l1.addComponent(btnAdd);
  69. l1.addComponent(btnReplace);
  70. l1.addComponent(btnMove);
  71. l1.addComponent(btnRemove);
  72. btnAdd.addClickListener(new ClickListener() {
  73. @Override
  74. public void buttonClick(ClickEvent event) {
  75. l2.addComponent(new TextField());
  76. }
  77. });
  78. btnReplace.addClickListener(new ClickListener() {
  79. @Override
  80. public void buttonClick(ClickEvent event) {
  81. l2.replaceComponent(c1, c3);
  82. }
  83. });
  84. btnMove.addClickListener(new ClickListener() {
  85. @Override
  86. public void buttonClick(ClickEvent event) {
  87. l2.moveComponentsFrom(source);
  88. }
  89. });
  90. btnRemove.addClickListener(new ClickListener() {
  91. @Override
  92. public void buttonClick(ClickEvent event) {
  93. l2.removeComponent(c1);
  94. l2.removeComponent(c2);
  95. }
  96. });
  97. l2.addComponent(c1);
  98. l2.addComponent(c2);
  99. l2.addComponent(c3);
  100. }
  101. }