Name

basetree — An abstract base class to build tree controls.

Synopsis

LZX: basetree
JavaScript: lz.basetree
Type: Class
Access: public
Topic: Components.Base Components
Declared in: lps/components/base/basetree.lzx

Description

You can subclass basetree to build a tree control with your own look and feel. Basetree has two content areas: item and children. The item view is where the visual component of the tree should be placed. Any view that you want to place in the tree node should be placed in item. You can use placement="item". The children view is the defaultplacement for basetree.

The following diagram demonstrates how item and children are associated in tree. Since basetree has no visual component, tree is used here for demonstration purposes.

Example 30. Basetree subclass with echoed text node

<canvas width="200" height="200">
              <include href="base/basetree.lzx"/>
            
              <class name="echotree" extends="basetree">
                <view placement="item" layout="axis: x; spacing: 2" bgcolor="${classroot.selected ? classroot.style.selectedcolor : classroot.parent.bgcolor}">
                  <handler name="onclick">
                    classroot.changeFocus();
                    if (! classroot.isleaf) {
                      classroot.setAttribute("open", ! classroot.open);
                    }
                  </handler>
                  <text text="${classroot.text}" resize="true"/>
                  <text text="${classroot.text}" resize="true"/>
                </view>
              </class>
            
              <view x="20" y="20" layout="axis: x; spacing: 10">
                <echotree>paragraph
                  <echotree>sentence
                    <echotree>words
                      <echotree isleaf="true">letter</echotree>
                      <echotree isleaf="true">number</echotree>
                      <echotree isleaf="true">punctuation</echotree>
                    </echotree>
                  </echotree>
                </echotree>
              </view>
            </canvas>

An abstract base class to build tree controls.

Superclass Chain

node (LzNode) » view (LzView) » basecomponent » basetree

Known Subclasses

Details

Properties (21)

autoscroll
<attribute name="autoscroll" type="boolean" value="false" />
public var autoscroll : boolean;
Auto scroll if tree is clipped. Default is false.
_children
<attribute name="_children" value="null" />
private var _children;
closechildren
<attribute name="closechildren" type="boolean" value="false" />
public var closechildren : boolean;
Close all immediate children when this tree is closed. Default is false.
closesiblings
<attribute name="closesiblings" type="boolean" value="false" />
public var closesiblings : boolean;
Flag to close other siblings when this tree is open. Default is false.
_currentChild
<attribute name="_currentChild" type="number" value="0" />
private var _currentChild : Number;
Child subview number selected. Default to the first one. This will get set when key press moves up and down.
defaultplacement
<attribute name="defaultplacement" type="string" value="children" />
public var defaultplacement : String;
focused
<attribute name="focused" type="boolean" value="false" />
public read-only var focused : boolean;
If true, this tree is focused. Default is false.
focusoverlay
<attribute name="focusoverlay" type="boolean" value="false" />
public var focusoverlay : boolean;
Meaningful only in root. If focusselect is false and focusoverlay is true, then focus has a visual bracket overlay over the focused tree. Default is false.
focusselect
<attribute name="focusselect" type="boolean" value="false" />
public final var focusselect : boolean;
Meaningful only in root. Flag to select a tree on focus. Default is false.
isleaf
<attribute name="isleaf" type="boolean" value="false" />
public var isleaf : boolean;
If true, this basetree is a leaf node. Default is false.
_lastfocused
<attribute name="_lastfocused" type="boolean" value="null" />
private var _lastfocused : boolean;
The last focused tree. Only available in the root.
layout
<attribute name="layout" value="class: simplelayout; axis: y; spacing: 0" />
public var layout;
Layout for children. Default is "class: simplelayout; axis: y; spacing: 0".
multiselect
<attribute name="multiselect" type="boolean" value="false" />
public final var multiselect : boolean;
Meaningful only in root. Whether to multiselect items. Default is false.
open
<attribute name="open" type="boolean" value="false" />
public var open : boolean;
Check to see if this tree is open. Default is false.
recurse
<attribute name="recurse" type="boolean" value="true" />
public final var recurse : boolean;
Meaningful only with data replication. If true, it will recursively follow the datapath's children. Default is true.
selected
<attribute name="selected" type="boolean" value="false" />
public var selected : boolean;
Check to see if this tree is selected. Default is false, except for the root of a tree, which its selected attribute is set to true.
_selector
<attribute name="_selector" type="expression" value="null" />
private var _selector : Object;
The selection manager. Only available in the root.
showroot
<attribute name="showroot" type="boolean" value="true" />
public final var showroot : boolean;
Meaningful only in root tree. If false, the root item is invisible and its children are displayed. Default is true.
toggleselected
<attribute name="toggleselected" type="boolean" value="false" />
public final var toggleselected : boolean;
Meaningful only in root. Flag to toggle selected nodes. Default is false.
xindent
<attribute name="xindent" type="number" value="10" />
public var xindent : Number;
Spacing to indent trees on the x-axis. Default is 10.
yindent
<attribute name="yindent" type="number" value="20" />
public var yindent : Number;
Spacing to indent trees on the y-axis. Default is 20.

Methods (23)

changeFocus()
<method name="changeFocus" args="focusedTree" />
public function changeFocus(focusedTree : Basetree);
Change the focus to new tree and unfocus the previous focused tree. If the focusselect for the tree is true, this method will also select the focused tree.
createChildTrees()
<method name="createChildTrees" />
private function createChildTrees();
Method to recurse and create subtrees when replicating data.
destroy()
<method name="destroy" />
private function destroy();
doAutoScroll()
<method name="doAutoScroll" args="root" />
private function doAutoScroll(root : Basetree);
Autoscroll if this tree is outside of scroll view.
_focusFirstChild()
<method name="_focusFirstChild" />
private function _focusFirstChild();
Keyboard focus on first child. If none exists, keep focus on current tree.
_focusLastChild()
<method name="_focusLastChild" />
private function _focusLastChild();
Keyboard focus on last child. If none exist, keep focus on current tree.
_focusNextSibling()
<method name="_focusNextSibling" />
private function _focusNextSibling();
Keyboard focus on next sibling. If we're not root, focus on parent's next sibling, else keep focus on current tree.
_focusParent()
<method name="_focusParent" />
private function _focusParent();
Keyboard focus on parent. If no parent exists, keep focus on current tree.
_focusPreviousSibling()
<method name="_focusPreviousSibling" />
private function _focusPreviousSibling();
Keyboard focus on previous sibling. If we're the first sibling, calls _focusParent(). If none exists, keep focus on current tree.
getChildClass()
<method name="getChildClass" />
public function getChildClass();
Returns class to use for instantiating replicated tree children. If tree is leaf, return null, since we don't care to instantiate any more subtrees. Override this method to instantiate different classes.
getChildIndex()
<method name="getChildIndex" args="child" />
public function getChildIndex(child : LzView) : Number;
Get the child index of the child passed in.
getRoot()
<method name="getRoot" />
public function getRoot() : basetree;
Get the root of this tree.
getSelection()
<method name="getSelection" />
public function getSelection() : Object;
Get current tree selection.
init()
<method name="init" />
private function init();
isRoot()
<method name="isRoot" />
public function isRoot() : Boolean;
Check to see if this is the root of the tree.
keyboardNavigate()
<method name="keyboardNavigate" args="kc" />
private function keyboardNavigate(kc);
keySelect()
<method name="keySelect" />
public function keySelect();
Called when tree is selected using keyboard. Default action is to select the tree.
openChildren()
<method name="openChildren" args="o" />
public function openChildren(o);
_setIsLeaf()
<method name="_setIsLeaf" args="leaf" />
private function _setIsLeaf(leaf : boolean);
Setter for isleaf attribute.
_setOpen()
<method name="_setOpen" args="o" />
private function _setOpen(o : boolean);
Setter for open attribute. Leaf nodes are always closed.
setSelected()
<method name="setSelected" args="s" />
private function setSelected(s : Boolean);
Called by selectionmanager when this is selected or unselected.
_setSelected()
<method name="_setSelected" args="s" />
private function _setSelected(s : boolean);
Calls selector to select this tree.
setTreeFocus()
<method name="setTreeFocus" args="focus, root" />
private function setTreeFocus(focus : Boolean, root);
Set the focus of this tree. This will not onfocus the last focused tree. Use changeFocus() for to do that.

Events (5)

onfocus
<attribute name="onfocus" />
public event onfocus;
This event gets triggered whenever the tree's focus is changed. This tree is sent with the event. The tree root also receives this event.
onfocused
<attribute name="onfocused" />
public event onfocused;
This event gets triggered whenever this tree is focused. The value of the focus (true or false) is sent with this event.
onopen
<attribute name="onopen" />
public event onopen;
This event gets triggered whenever this tree is open. The open value of this tree is also sent.
onselect
<attribute name="onselect" />
public event onselect;
This event gets triggered whenever this tree is selected. This tree is sent with the event. The tree root also receives this event.
onselected
<attribute name="onselected" />
public event onselected;
This event gets triggered whenever this tree is selected. The value of the selection (true or false) is sent with this event. Note the args of this has changed from the previous release.

LZX Synopsis

<class name="lz.basetree" extends=" lz.basecomponent ">
  <attribute name=" autoscroll " type="boolean" value="false" />
  <attribute name=" _children " value="null" />
  <attribute name=" closechildren " type="boolean" value="false" />
  <attribute name=" closesiblings " type="boolean" value="false" />
  <attribute name=" _currentChild " type="number" value="0" />
  <attribute name=" defaultplacement " type="string" value="children" />
  <attribute name=" focused " type="boolean" value="false" />
  <attribute name=" focusoverlay " type="boolean" value="false" />
  <attribute name=" focusselect " type="boolean" value="false" />
  <attribute name=" isleaf " type="boolean" value="false" />
  <attribute name=" _lastfocused " type="boolean" value="null" />
  <attribute name=" layout " value="class: simplelayout; axis: y; spacing: 0" />
  <attribute name=" multiselect " type="boolean" value="false" />
  <attribute name=" open " type="boolean" value="false" />
  <attribute name=" recurse " type="boolean" value="true" />
  <attribute name=" selected " type="boolean" value="false" />
  <attribute name=" _selector " type="expression" value="null" />
  <attribute name=" showroot " type="boolean" value="true" />
  <attribute name=" toggleselected " type="boolean" value="false" />
  <attribute name=" xindent " type="number" value="10" />
  <attribute name=" yindent " type="number" value="20" />
  <method name=" changeFocus " args="focusedTree" />
  <method name=" createChildTrees " />
  <method name=" destroy " />
  <method name=" doAutoScroll " args="root" />
  <method name=" _focusFirstChild " />
  <method name=" _focusLastChild " />
  <method name=" _focusNextSibling " />
  <method name=" _focusParent " />
  <method name=" _focusPreviousSibling " />
  <method name=" getChildClass " />
  <method name=" getChildIndex " args="child" />
  <method name=" getRoot " />
  <method name=" getSelection " />
  <method name=" init " />
  <method name=" isRoot " />
  <method name=" keyboardNavigate " args="kc" />
  <method name=" keySelect " />
  <event name=" onfocus " />
  <event name=" onfocused " />
  <event name=" onopen " />
  <event name=" onselect " />
  <event name=" onselected " />
  <method name=" openChildren " args="o" />
  <method name=" _setIsLeaf " args="leaf" />
  <method name=" _setOpen " args="o" />
  <method name=" setSelected " args="s" />
  <method name=" _setSelected " args="s" />
  <method name=" setTreeFocus " args="focus, root" />
</class>

JavaScript Synopsis

public lz.basetree extends  lz.basecomponent  {
  public var autoscroll  : boolean;
  private var _children ;
  public var closechildren  : boolean;
  public var closesiblings  : boolean;
  private var _currentChild  : Number;
  public var defaultplacement  : String;
  public read-only var focused  : boolean;
  public var focusoverlay  : boolean;
  public final var focusselect  : boolean;
  public var isleaf  : boolean;
  private var _lastfocused  : boolean;
  public var layout ;
  public final var multiselect  : boolean;
  public var open  : boolean;
  public final var recurse  : boolean;
  public var selected  : boolean;
  private var _selector  : Object;
  public final var showroot  : boolean;
  public final var toggleselected  : boolean;
  public var xindent  : Number;
  public var yindent  : Number;
  prototype public function changeFocus (focusedTree : Basetree);
  prototype private function createChildTrees ();
  prototype private function destroy ();
  prototype private function doAutoScroll (root : Basetree);
  prototype private function _focusFirstChild ();
  prototype private function _focusLastChild ();
  prototype private function _focusNextSibling ();
  prototype private function _focusParent ();
  prototype private function _focusPreviousSibling ();
  prototype public function getChildClass ();
  prototype public function getChildIndex (child : LzView) : Number;
  prototype public function getRoot () : basetree;
  prototype public function getSelection () : Object;
  prototype private function init ();
  prototype public function isRoot () : Boolean;
  prototype private function keyboardNavigate (kc);
  prototype public function keySelect ();
  prototype public event onfocus ;
  prototype public event onfocused ;
  prototype public event onopen ;
  prototype public event onselect ;
  prototype public event onselected ;
  prototype public function openChildren (o);
  prototype private function _setIsLeaf (leaf : boolean);
  prototype private function _setOpen (o : boolean);
  prototype private function setSelected (s : Boolean);
  prototype private function _setSelected (s : boolean);
  prototype private function setTreeFocus (focus : Boolean, root);
}