5.3.10.8 LazyTreeIterator Objects
Description: LazyTreeIterator Objects
Keywords: albatross

###
5.3.10.8 LazyTreeIterator Objects

`<al-tree>` tags that include the `lazy` attribute use an instance of the `LazyTreeIterator` class. This class supports all the methods of the `TreeIterator` class, as well as the following:

`is_open`( | )

  Returns `TRUE` is the current node is open. Calls the `albatross_alias()` method of the current node and returns `TRUE` if the returned alias exists in the `_open_aliases` dictionary member.

`is_selected`( | )

  Returns `TRUE` if the current node is selected. Calls the `albatross_alias()` method of the current node and returns `TRUE` if the returned alias exists in the `_selected_aliases` dictionary member.

Some methods are designed to be called from application code, not from templates.

`close_all`( | )

  Closes all tree nodes by reinitialising the `_open_aliases` to the empty dictionary.

`deselect_all`( | )

  Deselects all tree nodes by reinitialising the `_selected_aliases` to the empty dictionary.

`get_selected_aliases`( | )

  Returns a sorted list of aliases for all nodes that are selected (ie. in the `_selected_aliases` member).

`set_selected_aliases`( | aliases)

  Builds a new `_selected_aliases` member from the sequence of aliases passed in the aliases argument.

`get_open_aliases`( | )

  Returns a sorted list of aliases for all nodes that are open (ie. in the `_open_aliases` member).

`set_open_aliases`( | aliases)

  Builds a new `_open_aliases` member from the sequence of aliases passed in the aliases argument.

`LazyTreeIterator` instances add the follow private methods and members:

`_key`
  This member caches the value returned by the `albatross_alias()` method for the current node. This key is then used to look up the `_open_aliases` and `_selected_aliases` members.

`_open_aliases`
  A dictionary that contains the aliases for all tree nodes that are currently open. The contents of this dictionary is maintained via the `set_backdoor()` method.

`_selected_aliases`
  A dictionary that contains the aliases for all tree nodes that are currently selected. The contents of this dictionary is maintained via the `set_backdoor()` method.

`__getstate__`( | )

  Used to save the iterator in the session. This restricts the Python pickler to saving only the `_lazy`, `_open_aliases` and `_selected_aliases` members.

`__setstate__`( | tup)

  Restores an iterator from the Python pickler.

`set_value`( | node)

  Sets the `_value` to the node argument. When operating in lazy mode the `albatross_alias()` method is called for node and the result is cached in `_key`.

`node_is_open`( | ctx, node)

  Called internally whenever the toolkit needs to determine the open state of a tree node. It returns whether or not the node in the node argument is open. This always returns `0` for leaf nodes as they do not have children.

  When in lazy mode the open state of node is retrieved from `_open_aliases`. If the node state is open then the method checks the value of the node `children_loaded` member. If `children_loaded` is `FALSE` then the node `load_children()` is called to load the children of node.

`set_backdoor`( | op, key, value)

  The `<al-input>` and `<al-a>` tags provide `treefold` and `treeselect` attributes that generate names using a special backdoor format. When the browser request is processed, the `set_value()` method of the `NamespaceMixin` directs tree backdoor input fields to this method. Refer to the documentation in section 7.6.

  When the op argument is `"treeselect"` the `_selected_aliases` is updated for the node identified by the key argument. If value is `FALSE` the key is removed else it is added.

  When the op argument is `"treefold"` and value argument is `TRUE` then the open state of the node identified by the key argument is toggled.

`get_backdoor`( | op, key)

  When generating backdoor fields for the `<al-input>` and `<al-a>` tags the toolkit calls this method to determine the value that will assigned to that field.

  When op is `"treeselect"` the method returns the current selected state of the node identified by key.

  When op is `"treefold"` the method returns `1`.