Class XbpTreeView() Foundation

Class function of the XbpTreeView class.


Instances of the XbpTreeView() class are used to visualize hierarchically structured or tree-like data (tree view). A typical example is a directory tree with sub-directories and files. Sub-directories are what is called a "node" in the tree and files are considered "leaves". An XbpTreeView object can display tree-structured data nested to any depth. When displaying a tree, single branches, or sub-levels, respectively, can be suppressed or expanded. This way, complexly structured data can be presented in a clearly organized manner to the user.

The major task of an XbpTreeView object is providing a tree view with a root and to let the user navigate through the tree. Data displayed in the tree view, i.e. the nodes and leaves, is managed by instances of the XbpTreeViewItem class. Objects of this class must be added to an XbpTreeView object when building a tree view. The starting point of a tree view is always an invisible XbpTreeViewItem object referenced in the instance variable :rootItem. The first level of a tree view is created by adding new XbpTreeViewItem objects to the root item using the :addItem() method (oTree:rootItem:addItem()).

Class methods
Creates an instance of the XbpTreeView class.

The instance variables in this group configure system resources. If changes are made to the default values, they must be made before the :create() method is executed or :configure() must be called to activate the changes.

Highlights the selected item, regardless of the input focus.
Displays Plus and Minus signs for expanding the next level in the tree view
Displays lines between nodes in the tree
The first item in a tree (the root)
Life cycle
Requests system resources for the XbpTreeView object
Reconfigures the XbpTreeView object after :create() has been executed.
Releases the system resources of the XbpTreeView object.
Returns the marked item in the tree view.
Retrieves an item in the tree view from the mouse position.
Defines the marked item in the tree view.
The level below the current item has collapsed.
The level below the current item is displayed.
An item is marked in the tree.
An item is selected.
Displaying tree-structured data

// The example displays data for all DBF files in the current 
// directory as a tree. The first level shows Alias names, 
// the second level offers a choice between status information 
// and file structure, and the third level displays chosen 
// data. 

#include "" 

   LOCAL nEvent, mp1, mp2, oXbp 
   LOCAL aDbf := Directory( "*.DBF" ) 

   IF ! Empty( aDbf ) 
      AEval( aDbf, {|a| DbUseArea( .T. , , a[1] ) } ) 


      DO WHILE nEvent <> xbeP_Close 
         nEvent := AppEvent( @mp1, @mp2, @oXbp ) 
         oXbp:handleEvent( nEvent, mp1, mp2 ) 

** Create the tree view 
PROCEDURE BuildWorkSpaceTree() 
   LOCAL oTree := XbpTreeView():new( ,, {0,0}, {640,400} ) 

   oTree:hasLines   := .T. 
   oTree:hasButtons := .T. 

   // Add information about each 
   // used work area to the tree 
   WorkSpaceEval( {|| WorkAreaInfo( oTree ) } ) 

** Build the tree structure for a work area 
PROCEDURE WorkAreaInfo( oTree ) 
   LOCAL oArea, oStatus, oStruct 

   // First level in the tree starts with oTree:rootItem 
   oArea := oTree:rootItem:addItem( Alias() ) 

   // Second level in the tree begins with a XbpTreeViewItem 
   // Create XbpTreeViewItem explicitly (1st possibility) 
   oStatus         := XbpTreeViewItem():new() 
   oStatus:caption := "STATUS" 

   oArea:addItem( oStatus ) 

   // Create XbpTreeViewItem implicitly (2nd possibility) 
   oStruct := oArea:addItem( "STRUCTURE" ) 

   // Create third level in the tree 
   WAStatus( oStatus ) 
   WAStruct( oStruct ) 

** Third level -> status information 
PROCEDURE WAStatus( oItem ) 
   oItem:addItem( "Bof() = "    + IIf( Bof()  , ".T.", ".F." ) ) 
   oItem:addItem( "Eof() = "    + IIf( Eof()  , ".T.", ".F." ) ) 
   oItem:addItem( "Found() = "  + IIf( Found(), ".T.", ".F." ) ) 
   oItem:addItem( "Recno() = "  + Ltrim( Str( Recno()   ) ) ) 
   oItem:addItem( "LastRec() =" + Ltrim( Str( LastRec() ) ) ) 

** Third level -> field information 
PROCEDURE WAStruct( oItem ) 

   AEval( DbStruct(), ; 
     {|a,i,oSub| oSub := oItem:addItem( "FIELD_NAME = " + a[1] ), ; 
                 FieldStruct( oSub, a ) } ) 

** Create fourth level in the tree 
PROCEDURE FieldStruct( oItem, aField ) 
   oItem:addItem( "FIELD_TYPE = " + aField[2] ) 
   oItem:addItem( "FIELD_LEN  = " + Str( aField[3], 3 ) ) 
   oItem:addItem( "FIELD_DEC  = " + Str( aField[4], 3 ) ) 

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.