Difference between revisions of "Treecontrol"
From Apache OpenOffice Wiki
Line 1: | Line 1: | ||
− | + | API Preview: file://x|/cl/awt/com/sun/star/awt/tree/module-ix.html | |
=== The Tree Model === | === The Tree Model === |
Revision as of 13:16, 7 September 2006
API Preview: file://x|/cl/awt/com/sun/star/awt/tree/module-ix.html
The Tree Model
The tree control needs a tree model that stores the model information of the entries in the tree. You can provide your own mode which must at least support the interface com.sun.star.awt.XTreeModel. Or you can use the service DefaultTreeModel which manages a hirarchie of MutableTreeModels.
Using the DefaultTreeModel
#define O(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) ) Reference< ComponentContext > xCC(...); Reference< XTreeControlModel > xTreeControlModel(...); // create the root node with the text value "root node text" Reference< XMutableTreeNode > xRootNode( MutableTreeNode::create2( xCC, Any( O( "root node text" ) ) ) ); // add two child nodes with text xRootNode.appendChild( MutableTreeNode::create2( xCC, Any( O( "child 1" ) ) ) ); xRootNode.appendChild( MutableTreeNode::create2( xCC, Any( O( "child 2" ) ) ) ); // create the default tree model with the root node Reference< XTreeModel > xDefaultTreeModel( DefaultTreeModel::create2( xCC, xRootNode ), UNO_QUERY ); // set the default model at the tree control model xTreeControlModel->setModel( xDefaultTreeModel );