public static void TREES()
{
ItsNatDocument itsNatDoc = null;
ItsNatComponentManager componentMgr = itsNatDoc.getItsNatComponentManager();
ItsNatFreeTree treeComp = (ItsNatFreeTree)componentMgr.createItsNatComponentById("compId","freeTree",null);
new FreeTreeDecorator(treeComp).bind();
DefaultTreeModel dataModel = (DefaultTreeModel)treeComp.getTreeModel();
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Grey�s Anatomy");
dataModel.setRoot(rootNode);
DefaultMutableTreeNode parentNode;
parentNode = addNode("Characters",rootNode,dataModel);
addNode("Meredith Grey",parentNode,dataModel);
addNode("Cristina Yang",parentNode,dataModel);
addNode("Alex Karev",parentNode,dataModel);
addNode("George O'Malley",parentNode,dataModel);
parentNode = addNode("Actors",rootNode,dataModel);
addNode("Ellen Pompeo",parentNode,dataModel);
addNode("Sandra Oh",parentNode,dataModel);
addNode("Justin Chambers",parentNode,dataModel);
addNode("T.R. Knight",parentNode,dataModel);
TreeSelectionModel selModel = treeComp.getTreeSelectionModel();
selModel.setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
selModel.addSelectionPath(new TreePath(parentNode.getPath())); // Actors
TreeModelListener dataListener = new TreeModelListener()
{
public void treeNodesChanged(TreeModelEvent e)
{
treeChangedLog(e);
}
public void treeNodesInserted(TreeModelEvent e)
{
treeChangedLog(e);
}
public void treeNodesRemoved(TreeModelEvent e)
{
treeChangedLog(e);
}
public void treeStructureChanged(TreeModelEvent e)
{
treeChangedLog(e);
}
public void treeChangedLog(TreeModelEvent e)
{
System.out.println(e.toString());
}
};
dataModel.addTreeModelListener(dataListener);
TreeSelectionListener selListener = new TreeSelectionListener()
{
public void valueChanged(TreeSelectionEvent e)
{
TreeSelectionModel selModel = (TreeSelectionModel)e.getSource();
TreePath[] paths = e.getPaths();
String fact = "";
for(int i = 0; i < paths.length; i++)
{
TreePath path = paths[i];
boolean selected = selModel.isPathSelected(path);
if (selected)
fact += ", selected ";
else
fact += ", deselected ";
fact += path.getLastPathComponent();
}
System.out.println("Selection changes" + fact);
}
};
selModel.addTreeSelectionListener(selListener);
TreeWillExpandListener willExpandListener = new TreeWillExpandListener()
{
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException
{
// Will expand
}
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException
{
// Will collapse
}
};
treeComp.addTreeWillExpandListener(willExpandListener);
}