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.

TableParentEnabledStateChange.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractTestUIWithLog;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.CustomComponent;
  6. import com.vaadin.ui.FormLayout;
  7. import com.vaadin.ui.Label;
  8. import com.vaadin.v7.data.util.IndexedContainer;
  9. import com.vaadin.v7.ui.Table;
  10. public class TableParentEnabledStateChange extends AbstractTestUIWithLog {
  11. private Button toggle;
  12. @Override
  13. protected void setup(VaadinRequest request) {
  14. addComponent(new Label(
  15. "Toggling the enabled state of the custom component will break the selectability of the row in the table. "));
  16. final MyCustomComponent customComponent = new MyCustomComponent();
  17. toggle = new Button(
  18. "Toggle enabled state ; " + customComponent.isEnabled());
  19. toggle.addClickListener(event -> {
  20. customComponent.setEnabled(!customComponent.isEnabled());
  21. toggle.setCaption(
  22. "Toggle enabled state ; " + customComponent.isEnabled());
  23. });
  24. addComponent(toggle);
  25. addComponent(customComponent);
  26. }
  27. class MyCustomComponent extends CustomComponent {
  28. private static final long serialVersionUID = 1L;
  29. private FormLayout root;
  30. private Table table;
  31. private Button toggle;
  32. public MyCustomComponent() {
  33. root = new FormLayout();
  34. setCompositionRoot(root);
  35. setWidth("300px");
  36. setHeight("300px");
  37. table = new Table();
  38. table.setWidth("200px");
  39. table.setHeight("150px");
  40. table.setSelectable(true);
  41. IndexedContainer container = new IndexedContainer();
  42. container.addContainerProperty("name", String.class,
  43. "Select this item");
  44. container.addItem(1);
  45. table.setContainerDataSource(container);
  46. root.addComponent(table);
  47. }
  48. }
  49. }