Class XbpTreeView() Foundation

Class function of the XbpTreeView class.

Superclass
Description

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
:new()
Creates an instance of the XbpTreeView class.
Configuration

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.

:alwaysShowSelection
Highlights the selected item, regardless of the input focus.
:hasButtons
Displays Plus and Minus signs for expanding the next level in the tree view
:hasLines
Displays lines between nodes in the tree
Runtime
:rootItem
The first item in a tree (the root)
Life cycle
:create()
Requests system resources for the XbpTreeView object
:configure()
Reconfigures the XbpTreeView object after :create() has been executed.
:destroy()
Releases the system resources of the XbpTreeView object.
Editing
:getData()
Returns the marked item in the tree view.
:itemFromPos()
Retrieves an item in the tree view from the mouse position.
:setData()
Defines the marked item in the tree view.
Events
:itemCollapsed
The level below the current item has collapsed.
:itemExpanded
The level below the current item is displayed.
:itemMarked
An item is marked in the tree.
:itemSelected
An item is selected.
Examples
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 "Appevent.ch" 

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

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

      BuildWorkSpaceTree() 

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


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

   oTree:hasLines   := .T. 
   oTree:hasButtons := .T. 
   oTree:create() 

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


** 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" 
   oStatus:create() 

   oArea:addItem( oStatus ) 

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

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


** 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() ) ) ) 
RETURN 


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

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


** 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 ) ) 
RETURN 
Feedback

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.