Lets see how we can modify nodes in the tree.

How to use it?

Here is another interesting thing about the JContextTree, making your own nodes without having all
the problems of the JTree. And more than that, this can handle dynamic node creation.
Thoses new nodes can also be handled by your own columns or popup items.

        //Manipulating sub nodes------------------------------------------------
        SubNodeGroup myGroup = buildSubNodeGroup();
        
        tree.addSubNodeGroup(myGroup);
//        tree.removeSubNodeGroup(myGroup);
//        tree.removeSubNodeGroup(0);
//        int nbgroups = tree.getSubNodeGroupCount();
//        int index = tree.getSubNodeGroupIndex(myGroup);
//        SubNodeGroup[] groups = tree.getSubNodeGroups();


public SubNodeGroup buildSubNodeGroup() {
        
        
        class TitleNode extends ContextTreeNode{

            String title = "";
            
            TitleNode(String title,LightContextTreeModel model){
                super(model);
                this.title = title;
            }
            
            @Override
            public Object getValue() {
                return title;
            }

            @Override
            public void setValue(Object obj) {                
            }

            @Override
            public Icon getIcon() {
                return IconBundle.EMPTY_ICON;
            }

            @Override
            public boolean isEditable() {
                return false;
            }
            
        }
        
        class TitleNodeGroup implements SubNodeGroup{

            public boolean isValid(Object target) {
                return (target instanceof MapLayer);
            }

            public void installInNode(LightContextTreeModel model, ContextTreeNode node) {
                MapLayer layer = (MapLayer) node.getUserObject();
                TitleNode mynode = new TitleNode(layer.getTitle(),model);
                
                model.insetNodeInto(mynode, node, 0);
            }

            public void removeForNode(LightContextTreeModel model, ContextTreeNode node) {
                int max = node.getChildCount();
                
                for(int i=0; i<max; i++){
                    ContextTreeNode aNode = (ContextTreeNode) node.getChildAt(i);
                    if( aNode instanceof TitleNode){
                        model.removeNodeFromParent(aNode);
                    }
                }
                
            }
            
        };
        
        
        
        return new TitleNodeGroup();
        
    }