Name

basetree — An abstract base class to build tree controls.

Synopsis

LZX: basetree
JavaScript: 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

Known Direct Subclasses: tree

Details

Properties (17)

autoscroll
<attribute name="autoscroll" type="boolean" value="false" />
public var autoscroll : Boolean;
Auto scroll if tree is clipped. Default is false.
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.
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.
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.
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 (8)

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.
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.
isRoot()
<method name="isRoot" />
public function isRoot() : Boolean;
Check to see if this is the root of the tree.
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);

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="basetree" extends=" basecomponent ">
  <attribute name=" autoscroll " type="boolean" value="false" />
  <attribute name=" closechildren " type="boolean" value="false" />
  <attribute name=" closesiblings " type="boolean" value="false" />
  <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=" 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=" 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=" getChildClass " />
  <method name=" getChildIndex " args="child" />
  <method name=" getRoot " />
  <method name=" getSelection " />
  <method name=" isRoot " />
  <method name=" keySelect " />
  <event name=" onfocus " />
  <event name=" onfocused " />
  <event name=" onopen " />
  <event name=" onselect " />
  <event name=" onselected " />
  <method name=" openChildren " args="o" />
</class>

JavaScript Synopsis

public basetree extends  basecomponent  {
  public var autoscroll  : Boolean;
  public var closechildren  : Boolean;
  public var closesiblings  : Boolean;
  public var defaultplacement  : String;
  public read-only var focused  : Boolean;
  public var focusoverlay  : Boolean;
  public final var focusselect  : Boolean;
  public var isleaf  : Boolean;
  public var layout ;
  public final var multiselect  : Boolean;
  public var open  : Boolean;
  public final var recurse  : Boolean;
  public var selected  : Boolean;
  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 public function getChildClass ();
  prototype public function getChildIndex (child : LzView) : Number;
  prototype public function getRoot () : basetree;
  prototype public function getSelection () : Object;
  prototype public function isRoot () : Boolean;
  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);
}