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.

ModifyContainerProperty.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.data.util.IndexedContainer;
  3. import com.vaadin.tests.components.TestBase;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.Table;
  6. @SuppressWarnings("serial")
  7. public class ModifyContainerProperty extends TestBase {
  8. private Table table = new Table();
  9. private IndexedContainer ic = new IndexedContainer();
  10. @Override
  11. protected void setup() {
  12. addComponent(table);
  13. ic.addContainerProperty("one", String.class, "one");
  14. ic.addContainerProperty("two", String.class, "two");
  15. ic.addItem("foo");
  16. ic.getContainerProperty("foo", "one").setValue("bar");
  17. ic.getContainerProperty("foo", "two").setValue("baz");
  18. table.setContainerDataSource(ic);
  19. addComponent(new Button("Remove container property",
  20. new Button.ClickListener() {
  21. @Override
  22. public void buttonClick(com.vaadin.ui.Button.ClickEvent arg0) {
  23. ic.removeContainerProperty("one");
  24. }
  25. }));
  26. addComponent(new Button("Add container property",
  27. new Button.ClickListener() {
  28. @Override
  29. public void buttonClick(com.vaadin.ui.Button.ClickEvent arg0) {
  30. boolean added = ic.addContainerProperty("three",
  31. String.class, "three");
  32. if (added) {
  33. Object[] current = table.getVisibleColumns();
  34. Object[] vis = new Object[current.length + 1];
  35. for (int i = 0; i < current.length; i++) {
  36. vis[i] = current[i];
  37. }
  38. vis[current.length] = "three";
  39. table.setVisibleColumns(vis);
  40. }
  41. }
  42. }));
  43. }
  44. @Override
  45. protected String getDescription() {
  46. return "Clicking on \"Add container property\" adds a property to the container and sets it visible. The table should then show a \"three\" column in addition to the others. Clicking on \"Remove container property\" should remove column \"two\" from the table.";
  47. }
  48. @Override
  49. protected Integer getTicketNumber() {
  50. return 3165;
  51. }
  52. }