Esempio n. 1
0
 @Override
 public void containerItemSetChange(com.vaadin.data.Container.ItemSetChangeEvent event) {
   super.containerItemSetChange(event);
   if (getContainerDataSource() instanceof Filterable) {
     boolean hasFilters = !((Filterable) getContainerDataSource()).getContainerFilters().isEmpty();
     if (!hasFilters) {
       /*
        * If Container is not filtered then the itemsetchange is caused
        * by either adding or removing items to the container. To
        * prevent a memory leak we should cleanup the expanded list
        * from items which was removed.
        *
        * However, there will still be a leak if the container is
        * filtered to show only a subset of the items in the tree and
        * later unfiltered items are removed from the container. In
        * that case references to the unfiltered item ids will remain
        * in the expanded list until the Tree instance is removed and
        * the list is destroyed, or the container data source is
        * replaced/updated. To force the removal of the removed items
        * the application developer needs to a) remove the container
        * filters temporarly or b) re-apply the container datasource
        * using setContainerDataSource(getContainerDataSource())
        */
       cleanupExpandedItems();
     }
   }
 }
Esempio n. 2
0
  /**
   * Sets the Container that serves as the data source of the viewer.
   *
   * @see com.vaadin.data.Container.Viewer#setContainerDataSource(Container)
   */
  @Override
  public void setContainerDataSource(Container newDataSource) {
    if (newDataSource == null) {
      newDataSource = new HierarchicalContainer();
    }

    // Assure that the data source is ordered by making unordered
    // containers ordered by wrapping them
    if (Container.Hierarchical.class.isAssignableFrom(newDataSource.getClass())) {
      super.setContainerDataSource(newDataSource);
    } else {
      super.setContainerDataSource(new ContainerHierarchicalWrapper(newDataSource));
    }

    /*
     * Ensure previous expanded items are cleaned up if they don't exist in
     * the new container
     */
    if (expanded != null) {
      /*
       * We need to check that the expanded-field is not null since
       * setContainerDataSource() is called from the parent constructor
       * (AbstractSelect()) and at that time the expanded field is not yet
       * initialized.
       */
      cleanupExpandedItems();
    }
  }