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.

RemoveItemOnClick.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.Container;
  18. import com.vaadin.data.Item;
  19. import com.vaadin.data.Property.ValueChangeEvent;
  20. import com.vaadin.data.Property.ValueChangeListener;
  21. import com.vaadin.data.util.IndexedContainer;
  22. import com.vaadin.server.VaadinRequest;
  23. import com.vaadin.tests.components.AbstractTestUI;
  24. import com.vaadin.ui.Table;
  25. public class RemoveItemOnClick extends AbstractTestUI {
  26. private Table table;
  27. @Override
  28. protected void setup(VaadinRequest request) {
  29. table = new Table();
  30. IndexedContainer ic = new IndexedContainer();
  31. populate(ic);
  32. table.setContainerDataSource(ic);
  33. table.setPageLength(20);
  34. table.setSelectable(true);
  35. table.setImmediate(true);
  36. table.addValueChangeListener(new ValueChangeListener() {
  37. @Override
  38. public void valueChange(ValueChangeEvent event) {
  39. table.removeItem(table.getValue());
  40. }
  41. });
  42. addComponent(table);
  43. }
  44. private void populate(Container container) {
  45. container.addContainerProperty("property1", String.class, "foo");
  46. container.addContainerProperty("property2", Integer.class, 1210);
  47. container.addContainerProperty("property3", String.class, "bar");
  48. for (int i = 0; i < 100; i++) {
  49. Item item = container.addItem("Item " + i);
  50. item.getItemProperty("property1").setValue("This is item " + i);
  51. }
  52. }
  53. @Override
  54. protected String getTestDescription() {
  55. return "Selecting a row should remove that row from the table";
  56. }
  57. @Override
  58. protected Integer getTicketNumber() {
  59. return 10071;
  60. }
  61. }