Package muntjac :: Package data :: Package util :: Module hierarchical_container :: Class HierarchicalContainer
[hide private]
[frames] | no frames]

Class HierarchicalContainer

source code

                                    object --+                
                                             |                
                          container.IContainer --+            
                                                 |            
              abstract_container.AbstractContainer --+        
                                                     |        
                                        object --+   |        
                                                 |   |        
                  container.IItemSetChangeNotifier --+        
                                                     |        
                                object --+           |        
                                         |           |        
                      container.IContainer --+       |        
                                             |       |        
                            container.IOrdered --+   |        
                                                 |   |        
                                container.IIndexed --+        
                                                     |        
abstract_in_memory_container.AbstractInMemoryContainer --+    
                                                         |    
                                            object --+   |    
                                                     |   |    
                  container.IPropertySetChangeNotifier --+    
                                                         |    
                                            object --+   |    
                                                     |   |    
                         property.IValueChangeNotifier --+    
                                                         |    
                                    object --+           |    
                                             |           |    
                          container.IContainer --+       |    
                                                 |       |    
                                container.IOrdered --+   |    
                                                     |   |    
                                   container.ISortable --+    
                                                         |    
                                        object --+       |    
                                                 |       |    
                              container.IContainer --+   |    
                                                     |   |    
                                 container.IFilterable --+    
                                                         |    
                                        object --+       |    
                                                 |       |    
                              container.IContainer --+   |    
                                                     |   |    
                           container.ISimpleFilterable --+    
                                                         |    
                        indexed_container.IndexedContainer --+
                                                             |
                                            object --+       |
                                                     |       |
                                  container.IContainer --+   |
                                                         |   |
                                   container.IHierarchical --+
                                                             |
                                                object --+   |
                                                         |   |
                                      container.IContainer --+
                                                             |
                                                            HierarchicalContainer

A specialized Container whose contents can be accessed like it was a tree-like structure.


Authors:
Vaadin Ltd., Richard Lincoln
Instance Methods [hide private]
 
__init__(self)
Constructor for an abstract in-memory container.
source code
 
areChildrenAllowed(self, itemId)
Tests if the Item with given ID can have children.
source code
 
getChildren(self, itemId)
Gets the IDs of all Items that are children of the specified Item.
source code
 
getParent(self, itemId)
Gets the ID of the parent Item of the specified Item.
source code
 
hasChildren(self, itemId)
Tests if the Item specified with itemId has child Items or if it is a leaf.
source code
 
isRoot(self, itemId)
Tests if the Item specified with itemId is a root Item.
source code
 
rootItemIds(self)
Gets the IDs of all Items in the container that don't have a parent.
source code
 
setChildrenAllowed(self, itemId, childrenAllowed)
Sets the given Item's capability to have children.
source code
 
setParent(self, itemId, newParentId)
Sets the parent of an Item.
source code
 
hasFilters(self) source code
 
moveAfterSibling(self, itemId, siblingId)
Moves a node (an Item) in the container immediately after a sibling node.
source code
 
addItem(self, itemId=None)
Creates a new Item with the given ID in the IContainer.
source code
 
fireItemSetChange(self, event=None)
Sends a simple Item set change event to all interested listeners, indicating that anything in the contents may have changed (items added, removed etc.).
source code
 
contentsChangeEventsOn(self) source code
 
disableContentsChangeEvents(self) source code
 
enableAndFireContentsChangeEvents(self) source code
 
removeAllItems(self)
Removes all Items from the IContainer.
source code
 
removeItem(self, itemId)
Removes the Item identified by ItemId from the IContainer.
source code
 
removeItemRecursively(self, *args)
Removes the Item identified by given itemId and all its children from the given Container.
source code
 
doSort(self)
Perform the sorting of the data structures in the container.
source code
 
isIncludeParentsWhenFiltering(self)
Used to control how filtering works.
source code
 
setIncludeParentsWhenFiltering(self, includeParentsWhenFiltering)
Controls how the filtering of the container works.
source code
 
doFilterContainer(self, hasFilters)
Filters the data in the container and updates internal data structures.
source code
 
addFilteredChild(self, parentItemId, childItemId)
Adds the given childItemId as a filteredChildren for the parentItemId and sets it filteredParent.
source code
 
addFilteredChildrenRecursively(self, parentItemId, includedItems)
Recursively adds all items in the includedItems list to the filteredChildren map in the same order as they are in the children map.
source code
 
filterIncludingParents(self, itemId, includedItems)
Scans the itemId and all its children for which items should be included when filtering.
source code
 
passesFilters(self, itemId)
Checks if the given itemId passes the filters set for the container.
source code

Inherited from indexed_container.IndexedContainer: addCallback, addContainerFilter, addContainerProperty, addDefaultValues, addItemAfter, addItemAt, addListener, addSinglePropertyChangeListener, clone, fireItemAdded, firePropertyValueChange, generateId, getCallbacks, getContainerProperty, getContainerPropertyIds, getItemSorter, getListeners, getSortableContainerPropertyIds, getType, getUnfilteredItem, registerNewItem, removeAllContainerFilters, removeCallback, removeContainerFilter, removeContainerFilters, removeContainerProperty, removeListener, removeSinglePropertyChangeListener, setItemSorter, sort

Inherited from abstract_in_memory_container.AbstractInMemoryContainer: __len__, addFilter, containsId, filterAll, fireItemRemoved, firstItemId, getAllItemIds, getFilteredItemIds, getFilters, getIdByIndex, getItem, getItemIds, getSortablePropertyIds, getVisibleItemIds, indexOfId, internalAddAt, internalAddItemAfter, internalAddItemAt, internalAddItemAtEnd, internalRemoveAllItems, internalRemoveItem, isFiltered, isFirstId, isLastId, isPropertyFiltered, lastItemId, nextItemId, prevItemId, removeAllFilters, removeFilter, removeFilters, setAllItemIds, setFilteredItemIds, setFilters, size, sortContainer

Inherited from abstract_container.AbstractContainer: fireContainerPropertySetChange, getItemSetChangeListeners, getPropertySetChangeListeners, setItemSetChangeListeners, setPropertySetChangeListeners

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

Constructor for an abstract in-memory container.

Overrides: object.__init__
(inherited documentation)

areChildrenAllowed(self, itemId)

source code 

Tests if the Item with given ID can have children.

Parameters:
  • itemId - ID of the Item in the container whose child capability is to be tested
Returns:
True if the specified Item exists in the IContainer and it can have children, False if it's not found from the container or it can't have children.
Overrides: container.IHierarchical.areChildrenAllowed
(inherited documentation)

getChildren(self, itemId)

source code 

Gets the IDs of all Items that are children of the specified Item. The returned collection is unmodifiable.

Parameters:
  • itemId - ID of the Item whose children the caller is interested in
Returns:
An iterable containing the IDs of all other Items that are children in the container hierarchy
Overrides: container.IHierarchical.getChildren
(inherited documentation)

getParent(self, itemId)

source code 

Gets the ID of the parent Item of the specified Item.

Parameters:
  • itemId - ID of the Item whose parent the caller wishes to find out.
Returns:
the ID of the parent Item. Will be None if the specified Item is a root element.
Overrides: container.IHierarchical.getParent
(inherited documentation)

hasChildren(self, itemId)

source code 

Tests if the Item specified with itemId has child Items or if it is a leaf. The getChildren method always returns None for leaf Items.

Note that being a leaf does not imply whether or not an Item is allowed to have children.

Parameters:
  • itemId - ID of the Item to be tested
Returns:
True if the specified Item has children, False if not (is a leaf)
Overrides: container.IHierarchical.hasChildren
(inherited documentation)

isRoot(self, itemId)

source code 

Tests if the Item specified with itemId is a root Item. The hierarchical container can have more than one root and must have at least one unless it is empty. The getParent method always returns None for root Items.

Parameters:
  • itemId - ID of the Item whose root status is to be tested
Returns:
True if the specified Item is a root, False if not
Overrides: container.IHierarchical.isRoot
(inherited documentation)

rootItemIds(self)

source code 

Gets the IDs of all Items in the container that don't have a parent. Such items are called root Items. The returned collection is unmodifiable.

Returns:
An iterable containing IDs of all root elements of the container
Overrides: container.IHierarchical.rootItemIds
(inherited documentation)

setChildrenAllowed(self, itemId, childrenAllowed)

source code 

Sets the given Item's capability to have children. If the Item identified with the itemId already has children and the areChildrenAllowed is false this method fails and False is returned; the children must be first explicitly removed with setParent or IContainer.removeItem.

Parameters:
  • itemId - the ID of the Item in the container whose child capability is to be set.
  • childrenAllowed - the boolean value specifying if the Item can have children or not.
Returns:
True if the operation succeeded, False if not
Overrides: container.IHierarchical.setChildrenAllowed

setParent(self, itemId, newParentId)

source code 

Sets the parent of an Item. The new parent item must exist and be able to have children. (canHaveChildren(newParentId) == True). It is also possible to detach a node from the hierarchy (and thus make it root) by setting the parent None.

Parameters:
  • itemId - the ID of the item to be set as the child of the Item identified with newParentId.
  • newParentId - the ID of the Item that's to be the new parent of the Item identified with itemId.
Returns:
True if the operation succeeded, False if not
Overrides: container.IHierarchical.setParent

moveAfterSibling(self, itemId, siblingId)

source code 

Moves a node (an Item) in the container immediately after a sibling node. The two nodes must have the same parent in the container.

Parameters:
  • itemId - the identifier of the moved node (Item)
  • siblingId - the identifier of the reference node (Item), after which the other node will be located

addItem(self, itemId=None)

source code 

Creates a new Item with the given ID in the IContainer. Creates a new Item into the IContainer, and assign it an automatic ID if itemId is None.

The new Item is returned, and it is ready to have its Properties modified. Returns None if the operation fails or the IContainer already contains a Item with the given ID.

Parameters:
  • itemId - ID of the Item to be created
Returns:
Created new Item, or None in case of a failure
Raises:
  • NotImplementedError - if adding an item with an explicit item ID is not supported by the container
Overrides: container.IContainer.addItem
(inherited documentation)

fireItemSetChange(self, event=None)

source code 

Sends a simple Item set change event to all interested listeners, indicating that anything in the contents may have changed (items added, removed etc.).

Parameters:
  • event - the item set change event to send, optionally with additional information
Overrides: abstract_container.AbstractContainer.fireItemSetChange
(inherited documentation)

removeAllItems(self)

source code 

Removes all Items from the IContainer.

Note that Property ID and type information is preserved. This functionality is optional.

Returns:
True if the operation succeeded, False if not
Raises:
  • NotImplementedError - if the container does not support removing all items
Overrides: container.IContainer.removeAllItems
(inherited documentation)

removeItem(self, itemId)

source code 

Removes the Item identified by ItemId from the IContainer.

Containers that support filtering should also allow removing an item that is currently filtered out.

This functionality is optional.

Parameters:
  • itemId - ID of the Item to remove
Returns:
True if the operation succeeded, False if not
Raises:
  • NotImplementedError - if the container does not support removing individual items
Overrides: container.IContainer.removeItem
(inherited documentation)

removeItemRecursively(self, *args)

source code 

Removes the Item identified by given itemId and all its children from the given Container.

Parameters:
  • args - tuple of the form
    • (itemId)
      • the identifier of the Item to be removed
    • (container, itemId)
      • the container where the item is to be removed
      • the identifier of the Item to be removed
Returns:
true if the operation succeeded

See Also: removeItem

doSort(self)

source code 

Perform the sorting of the data structures in the container. This is invoked when the itemSorter has been prepared for the sort operation. Typically this method calls sorted on all arrays (containing item ids) that need to be sorted.

Overrides: abstract_in_memory_container.AbstractInMemoryContainer.doSort
(inherited documentation)

isIncludeParentsWhenFiltering(self)

source code 

Used to control how filtering works. @see setIncludeParentsWhenFiltering for more information.

Returns:
true if all parents for items that match the filter are included when filtering, false if only the matching items are included

setIncludeParentsWhenFiltering(self, includeParentsWhenFiltering)

source code 

Controls how the filtering of the container works. Set this to true to make filtering include parents for all matched items in addition to the items themselves. Setting this to false causes the filtering to only include the matching items and make items with excluded parents into root items.

Parameters:
  • includeParentsWhenFiltering - true to include all parents for items that match the filter, false to only include the matching items

doFilterContainer(self, hasFilters)

source code 

Filters the data in the container and updates internal data structures. This method should reset any internal data structures and then repopulate them so getItemIds and other methods only return the filtered items.

Parameters:
  • hasFilters - true if filters has been set for the container, false otherwise
Returns:
true if the item set has changed as a result of the filtering
Overrides: abstract_in_memory_container.AbstractInMemoryContainer.doFilterContainer
(inherited documentation)

addFilteredChildrenRecursively(self, parentItemId, includedItems)

source code 

Recursively adds all items in the includedItems list to the filteredChildren map in the same order as they are in the children map. Starts from parentItemId and recurses down as long as child items that should be included are found.

Parameters:
  • parentItemId - The item id to start recurse from. Not added to a filteredChildren list
  • includedItems - Set containing the item ids for the items that should be included in the filteredChildren map

filterIncludingParents(self, itemId, includedItems)

source code 

Scans the itemId and all its children for which items should be included when filtering. All items which passes the filters are included. Additionally all items that have a child node that should be included are also themselves included.

Returns:
true if the itemId should be included in the filtered container.

passesFilters(self, itemId)

source code 

Checks if the given itemId passes the filters set for the container. The caller should make sure the itemId exists in the container. For non-existing itemIds the behaviour is undefined.

Parameters:
  • itemId - An itemId that exists in the container.
Returns:
true if the itemId passes all filters or no filters are set, false otherwise.
Overrides: abstract_in_memory_container.AbstractInMemoryContainer.passesFilters
(inherited documentation)