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.

IdOverrideTest.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.vaadin.tests.components.ui;
  2. import com.vaadin.annotations.Theme;
  3. import com.vaadin.annotations.Widgetset;
  4. import com.vaadin.server.VaadinRequest;
  5. import com.vaadin.shared.ui.MarginInfo;
  6. import com.vaadin.tests.components.AbstractReindeerTestUI;
  7. import com.vaadin.tests.widgetset.TestingWidgetSet;
  8. import com.vaadin.tests.widgetset.server.IdTestLabel;
  9. import com.vaadin.ui.Button;
  10. import com.vaadin.ui.Label;
  11. @Widgetset(TestingWidgetSet.NAME)
  12. @Theme("tests-tickets")
  13. public class IdOverrideTest extends AbstractReindeerTestUI {
  14. @Override
  15. protected String getTestDescription() {
  16. return "Id shouldn't get overridden unless specifically re-set.<br>"
  17. + "First two are custom labels with a default id, third is an ordinary label for comparison.";
  18. }
  19. @Override
  20. protected Integer getTicketNumber() {
  21. return 10179;
  22. }
  23. @Override
  24. protected void setup(VaadinRequest request) {
  25. getLayout().setSpacing(true);
  26. getLayout().setMargin(new MarginInfo(true, false, false, false));
  27. final IdTestLabel idTestLabel = new IdTestLabel("default id");
  28. idTestLabel.setSizeUndefined();
  29. addComponent(idTestLabel);
  30. final IdTestLabel idTestLabelWithId = new IdTestLabel("set id");
  31. idTestLabelWithId.setSizeUndefined();
  32. idTestLabelWithId.setId("set10179");
  33. addComponent(idTestLabelWithId);
  34. final Label label = new Label("no id");
  35. label.setSizeUndefined();
  36. addComponent(label);
  37. Button button = new Button();
  38. button.setCaption("Toggle");
  39. button.addClickListener(event -> {
  40. if (idTestLabelWithId.getId() == null) {
  41. idTestLabelWithId.setId("set10179");
  42. idTestLabelWithId.setValue("set id");
  43. idTestLabel.setValue("default id");
  44. label.setValue("no id");
  45. } else {
  46. idTestLabelWithId.setId(null);
  47. idTestLabelWithId.setValue("removed id");
  48. idTestLabel.setValue("still default id");
  49. label.setValue("still no id");
  50. }
  51. });
  52. button.setId("toggle");
  53. addComponent(button);
  54. }
  55. }