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.

CustomLayoutUsingTemplate.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package com.vaadin.tests.components.customlayout;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import com.vaadin.tests.components.TestBase;
  5. import com.vaadin.ui.Button;
  6. import com.vaadin.ui.Button.ClickEvent;
  7. import com.vaadin.ui.Button.ClickListener;
  8. import com.vaadin.ui.CustomLayout;
  9. import com.vaadin.ui.Label;
  10. import com.vaadin.v7.ui.LegacyTextField;
  11. public class CustomLayoutUsingTemplate extends TestBase
  12. implements ClickListener {
  13. CustomLayout layout;
  14. Button button1 = new Button("Add Button to first location", this);
  15. Button button2 = new Button("Add TextField to second location", this);
  16. @Override
  17. protected void setup() {
  18. String thisPackage = CustomLayoutUsingTemplate.class.getName()
  19. .replace('.', '/');
  20. thisPackage = thisPackage.replaceAll(
  21. CustomLayoutUsingTemplate.class.getSimpleName() + "$", "");
  22. String template = thisPackage + "template.htm";
  23. InputStream is = getClass().getClassLoader()
  24. .getResourceAsStream(template);
  25. addComponent(button1);
  26. try {
  27. layout = new CustomLayout(is);
  28. addComponent(layout);
  29. } catch (IOException e) {
  30. addComponent(new Label(e.getMessage()));
  31. e.printStackTrace();
  32. } finally {
  33. try {
  34. is.close();
  35. } catch (IOException e) {
  36. // TODO Auto-generated catch block
  37. e.printStackTrace();
  38. }
  39. }
  40. }
  41. @Override
  42. protected String getDescription() {
  43. return "Test for using a CustomLayout with a template read from an input stream and passed through the state";
  44. }
  45. @Override
  46. protected Integer getTicketNumber() {
  47. return null;
  48. }
  49. @Override
  50. public void buttonClick(ClickEvent event) {
  51. if (event.getButton() == button1) {
  52. layout.addComponent(button2, "location1");
  53. } else {
  54. layout.addComponent(new LegacyTextField("A text field!"),
  55. "location2");
  56. }
  57. }
  58. }