Difference between revisions of "Treecontrol"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
Line 1: Line 1:
  
 +
=== The Tree Model ===
  
=== Using the DefaultTreeModel ===
+
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 ====
  
 
<pre>
 
<pre>
 +
#define O(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
 +
 
Reference< ComponentContext > xCC(...);
 
Reference< ComponentContext > xCC(...);
 +
Reference< XTreeControlModel > xTreeControlModel(...);
  
 
// create the root node with the text value "root node text"
 
// create the root node with the text value "root node text"
  
Reference< XMutableTreeNode > xRootNode( MutableTreeNode::create2( Any( OUString( "root node text" ) ) ) );
+
Reference< XMutableTreeNode > xRootNode( MutableTreeNode::create2( xCC, Any( O( "root node text" ) ) ) );
  
 
// add two child nodes with text
 
// add two child nodes with text
xRootNode.appendChild( MutableTreeNode::create2( Any( OUString( "child 1" ) ) ) );
+
xRootNode.appendChild( MutableTreeNode::create2( xCC, Any( O( "child 1" ) ) ) );
xRootNode.appendChild( MutableTreeNode::create2( Any( OUString( "child 2" ) ) ) );
+
xRootNode.appendChild( MutableTreeNode::create2( xCC, Any( O( "child 2" ) ) ) );
  
 
// create the default tree model with the root node
 
// create the default tree model with the root node
Reference< XDefaultTreeModel > xDefaultTreeModel( DefaultTreeModel::create2( xRootNode ) );
+
Reference< XTreeModel > xDefaultTreeModel( DefaultTreeModel::create2( xCC, xRootNode ), UNO_QUERY );
 +
 
 +
// set the default model at the tree control model
 +
xTreeControlModel->setModel( xDefaultTreeModel );

Revision as of 12:49, 7 September 2006

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 );
Personal tools