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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.components.table;
  17. import com.vaadin.data.util.IndexedContainer;
  18. import com.vaadin.server.VaadinRequest;
  19. import com.vaadin.tests.components.AbstractTestUIWithLog;
  20. import com.vaadin.ui.Button;
  21. import com.vaadin.ui.Button.ClickEvent;
  22. import com.vaadin.ui.CustomComponent;
  23. import com.vaadin.ui.FormLayout;
  24. import com.vaadin.ui.Label;
  25. import com.vaadin.ui.Table;
  26. public class TableParentEnabledStateChange extends AbstractTestUIWithLog {
  27. private Button toggle;
  28. @Override
  29. protected void setup(VaadinRequest request) {
  30. addComponent(new Label(
  31. "Toggling the enabled state of the custom component will break the selectability of the row in the table. "));
  32. final MyCustomComponent customComponent = new MyCustomComponent();
  33. toggle = new Button("Toggle enabled state ; "
  34. + customComponent.isEnabled());
  35. toggle.addClickListener(new Button.ClickListener() {
  36. @Override
  37. public void buttonClick(ClickEvent event) {
  38. customComponent.setEnabled(!customComponent.isEnabled());
  39. toggle.setCaption("Toggle enabled state ; "
  40. + customComponent.isEnabled());
  41. }
  42. });
  43. addComponent(toggle);
  44. addComponent(customComponent);
  45. }
  46. class MyCustomComponent extends CustomComponent {
  47. private static final long serialVersionUID = 1L;
  48. private FormLayout root;
  49. private Table table;
  50. private Button toggle;
  51. public MyCustomComponent() {
  52. root = new FormLayout();
  53. setCompositionRoot(root);
  54. setWidth("300px");
  55. setHeight("300px");
  56. table = new Table();
  57. table.setWidth("200px");
  58. table.setHeight("150px");
  59. table.setSelectable(true);
  60. IndexedContainer container = new IndexedContainer();
  61. container.addContainerProperty("name", String.class,
  62. "Select this item");
  63. container.addItem(1);
  64. table.setContainerDataSource(container);
  65. root.addComponent(table);
  66. }
  67. }
  68. }