Package muntjac :: Package data :: Package util :: Module container_hierarchical_wrapper :: Class ContainerHierarchicalWrapper
[hide private]
[frames] | no frames]

Class ContainerHierarchicalWrapper

source code

                      object --+        
                               |        
            container.IContainer --+    
                                   |    
             container.IHierarchical --+
                                       |
                          object --+   |
                                   |   |
                container.IContainer --+
                                       |
                          object --+   |
                                   |   |
    container.IItemSetChangeNotifier --+
                                       |
                          object --+   |
                                   |   |
container.IPropertySetChangeNotifier --+
                                       |
                                      ContainerHierarchicalWrapper

A wrapper class for adding external hierarchy to containers not implementing the IHierarchical interface.

If the wrapped container is changed directly (that is, not through the wrapper), and does not implement IItemSetChangeNotifier and/or IPropertySetChangeNotifier the hierarchy information must be updated with the updateHierarchicalWrapper method.


Authors:
Vaadin Ltd., Richard Lincoln
Instance Methods [hide private]
 
__init__(self, toBeWrapped)
Constructs a new hierarchical wrapper for an existing Container.
source code
 
updateHierarchicalWrapper(self)
Updates the wrapper's internal hierarchy data to include all Items in the underlying container.
source code
 
removeFromHierarchyWrapper(self, itemId)
Removes the specified Item from the wrapper's internal hierarchy structure.
source code
 
addToHierarchyWrapper(self, itemId)
Adds the specified Item specified to the internal hierarchy structure.
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
 
addItem(self, itemId=None)
Adds a new Item by its ID to the underlying container and to the hierarchy.
source code
 
removeAllItems(self)
Removes all items from the underlying container and from the hierarchy.
source code
 
removeItem(self, itemId)
Removes an Item specified by the itemId from the underlying container and from the hierarchy.
source code
 
removeItemRecursively(self, itemId)
Removes the Item identified by given itemId and all its children.
source code
 
addContainerProperty(self, propertyId, typ, defaultValue)
Adds a new Property to all Items in the Container.
source code
 
removeContainerProperty(self, propertyId)
Removes the specified Property from the underlying container and from the hierarchy.
source code
 
containsId(self, itemId)
Tests if the IContainer contains the specified Item.
source code
 
getItem(self, itemId)
Gets the Item with the given Item ID from the IContainer.
source code
 
getItemIds(self)
Gets the ID's of all visible (after filtering and sorting) Items stored in the IContainer.
source code
 
getContainerProperty(self, itemId, propertyId)
Gets the Property identified by the given itemId and propertyId from the IContainer.
source code
 
getContainerPropertyIds(self)
Gets the ID's of all Properties stored in the IContainer.
source code
 
getType(self, propertyId)
Gets the data type of all Properties identified by the given Property ID.
source code
 
size(self)
Gets the number of visible Items in the IContainer.
source code
 
__len__(self) source code
 
addListener(self, listener, iface=None)
Adds an Item set change listener for the object.
source code
 
addCallback(self, callback, eventType=None, *args) source code
 
removeListener(self, listener, iface=None)
Removes the Item set change listener from the object.
source code
 
removeCallback(self, callback, eventType=None) source code

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

Instance Variables [hide private]
  _container
The wrapped container
  _noChildrenAllowed
Set of IDs of those contained Items that can't have children.
  _parent
Mapping from Item ID to parent Item ID
  _children
Mapping from Item ID to a list of child IDs
  _roots
List that contains all root elements of the container.
  _hierarchical
Is the wrapped container hierarchical by itself ?
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, toBeWrapped)
(Constructor)

source code 

Constructs a new hierarchical wrapper for an existing Container. Works even if the to-be-wrapped container already implements the IHierarchical interface.

Parameters:
  • toBeWrapped - the container that needs to be accessed hierarchically
Overrides: object.__init__

updateHierarchicalWrapper(self)

source code 

Updates the wrapper's internal hierarchy data to include all Items in the underlying container. If the contents of the wrapped container change without the wrapper's knowledge, this method needs to be called to update the hierarchy information of the Items.

removeFromHierarchyWrapper(self, itemId)

source code 

Removes the specified Item from the wrapper's internal hierarchy structure.

Note : The Item is not removed from the underlying Container.

Parameters:
  • itemId - the ID of the item to remove from the hierarchy.

addToHierarchyWrapper(self, itemId)

source code 

Adds the specified Item specified to the internal hierarchy structure. The new item is added as a root Item. The underlying container is not modified.

Parameters:
  • itemId - the ID of the item to add to the hierarchy.

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

addItem(self, itemId=None)

source code 

Adds a new Item by its ID to the underlying container and to the hierarchy. Creates a new Item into the Container, assigns it an automatic ID, and adds it to the hierarchy if itemId is None.

Parameters:
  • itemId - the ID of the Item to be created.
Returns:
the added Item or None if the operation failed.
Raises:
  • NotImplementedError - if the addItem is not supported.
Overrides: container.IContainer.addItem

removeAllItems(self)

source code 

Removes all items from the underlying container and from the hierarchy.

Returns:
True if the operation succeeded, False if not
Raises:
  • NotImplementedError - if the removeAllItems is not supported.
Overrides: container.IContainer.removeAllItems

removeItem(self, itemId)

source code 

Removes an Item specified by the itemId from the underlying container and from the hierarchy.

Parameters:
  • itemId - the ID of the Item to be removed.
Returns:
True if the operation succeeded, False if not
Raises:
  • NotImplementedError - if the removeItem is not supported.
Overrides: container.IContainer.removeItem

removeItemRecursively(self, itemId)

source code 

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

Parameters:
  • itemId - the identifier of the Item to be removed
Returns:
true if the operation succeeded

See Also: removeItem

addContainerProperty(self, propertyId, typ, defaultValue)

source code 

Adds a new Property to all Items in the Container.

Parameters:
  • propertyId - the ID of the new Property.
  • typ - the Data type of the new Property.
  • defaultValue - the value all created Properties are initialized to.
Returns:
True if the operation succeeded, False if not
Raises:
  • NotImplementedError - if the addContainerProperty is not supported.
Overrides: container.IContainer.addContainerProperty

removeContainerProperty(self, propertyId)

source code 

Removes the specified Property from the underlying container and from the hierarchy.

Note: The Property will be removed from all Items in the Container.

Parameters:
  • propertyId - the ID of the Property to remove.
Returns:
True if the operation succeeded, False if not
Raises:
  • NotImplementedError - if the removeContainerProperty is not supported.
Overrides: container.IContainer.removeContainerProperty

containsId(self, itemId)

source code 

Tests if the IContainer contains the specified Item.

Filtering can hide items so that they will not be visible through the container API, and this method should respect visibility of items (i.e. only indicate visible items as being in the container) if feasible for the container.

Parameters:
  • itemId - ID the of Item to be tested
Returns:
boolean indicating if the IContainer holds the specified Item
Overrides: container.IContainer.containsId
(inherited documentation)

getItem(self, itemId)

source code 

Gets the Item with the given Item ID from the IContainer. If the IContainer does not contain the requested Item, None is returned.

Containers should not return Items that are filtered out.

Parameters:
  • itemId - ID of the Item to retrieve
Returns:
the Item with the given ID or None if the Item is not found in the IContainer
Overrides: container.IContainer.getItem
(inherited documentation)

getItemIds(self)

source code 

Gets the ID's of all visible (after filtering and sorting) Items stored in the IContainer. The ID's cannot be modified through the returned collection.

If the container is IOrdered, the collection returned by this method should follow that order. If the container is ISortable, the items should be in the sorted order.

Calling this method for large lazy containers can be an expensive operation and should be avoided when practical.

Returns:
unmodifiable collection of Item IDs
Overrides: container.IContainer.getItemIds
(inherited documentation)

getContainerProperty(self, itemId, propertyId)

source code 

Gets the Property identified by the given itemId and propertyId from the IContainer. If the IContainer does not contain the item or it is filtered out, or the IContainer does not have the Property, None is returned.

Parameters:
  • itemId - ID of the visible Item which contains the Property
  • propertyId - ID of the Property to retrieve
Returns:
Property with the given ID or None
Overrides: container.IContainer.getContainerProperty
(inherited documentation)

getContainerPropertyIds(self)

source code 

Gets the ID's of all Properties stored in the IContainer. The ID's cannot be modified through the returned collection.

Returns:
unmodifiable collection of Property IDs
Overrides: container.IContainer.getContainerPropertyIds
(inherited documentation)

getType(self, propertyId)

source code 

Gets the data type of all Properties identified by the given Property ID.

Parameters:
  • propertyId - ID identifying the Properties
Returns:
data type of the Properties
Overrides: container.IContainer.getType
(inherited documentation)

size(self)

source code 

Gets the number of visible Items in the IContainer.

Filtering can hide items so that they will not be visible through the container API.

Returns:
number of Items in the IContainer
Overrides: container.IContainer.size
(inherited documentation)

addListener(self, listener, iface=None)

source code 

Adds an Item set change listener for the object.

Parameters:
  • listener - listener to be added
Overrides: container.IPropertySetChangeNotifier.addListener
(inherited documentation)

addCallback(self, callback, eventType=None, *args)

source code 
Overrides: container.IPropertySetChangeNotifier.addCallback

removeListener(self, listener, iface=None)

source code 

Removes the Item set change listener from the object.

Parameters:
  • listener - listener to be removed
Overrides: container.IPropertySetChangeNotifier.removeListener
(inherited documentation)

removeCallback(self, callback, eventType=None)

source code 
Overrides: container.IPropertySetChangeNotifier.removeCallback