Package muntjac :: Package data :: Module container :: Class IHierarchical
[hide private]
[frames] | no frames]

Class IHierarchical

source code

object --+    
         |    
IContainer --+
             |
            IHierarchical
Known Subclasses:

Interface for IContainer classes whose Items can be arranged hierarchically. This means that the Items in the container belong in a tree-like structure, with the following quirks:

Instance Methods [hide private]
 
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
 
rootItemIds(self)
Gets the IDs of all Items in the container that don't have a parent.
source code
 
setParent(self, itemId, newParentId)
Sets the parent of an Item.
source code
 
areChildrenAllowed(self, itemId)
Tests if the Item with given ID can have children.
source code
 
setChildrenAllowed(self, itemId, areChildrenAllowed)
Sets the given Item's capability to have children.
source code
 
isRoot(self, itemId)
Tests if the Item specified with itemId is a root Item.
source code
 
hasChildren(self, itemId)
Tests if the Item specified with itemId has child Items or if it is a leaf.
source code
 
removeItem(self, itemId)
Removes the Item identified by ItemId from the IContainer.
source code

Inherited from IContainer: addContainerProperty, addItem, containsId, getContainerProperty, getContainerPropertyIds, getItem, getItemIds, getType, removeAllItems, removeContainerProperty, size

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

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

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.

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

setParent(self, itemId, newParentId)

source code 

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

This operation is optional.

Parameters:
  • itemId - ID of the item to be set as the child of the Item identified with newParentId
  • newParentId - 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

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.

setChildrenAllowed(self, itemId, areChildrenAllowed)

source code 

Sets the given Item's capability to have children. If the Item identified with itemId already has children and areChildrenAllowed is false this method fails and False is returned.

The children must be first explicitly removed with setParent or removeItem.

This operation is optional. If it is not implemented, the method always returns False.

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

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

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)

removeItem(self, itemId)

source code 

Removes the Item identified by ItemId from the IContainer.

Note that this does not remove any children the item might have.

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: IContainer.removeItem