[nbusers] Subclassing ChildFactory and children does not show up

  • From: "plopp" < >
  • To:
  • Subject: [nbusers] Subclassing ChildFactory<String> and children does not show up
  • Date: Wed, 30 May 2012 10:03:13 -0400

Hi,

I have a problem with the Nodes API, I've found the solution myself, but I 
don't understand why the solution works...

[Arrow] Problem: Children leaves not showing up when expanding DataNode in 
"Favorites"-explorer.

[Arrow] Background: I'm using the built-in "Favorites"-file explorer in my 
module platform to display a file-tree. At certain places in this file-tree 
exists text-files with the file-extension ".val". I've created my own custom 
file type-module to recognize these files and so far everything is OK. 

Going further, expanding one of the DataNodes (which wraps my ".val"-files) 
should expose the text content of the file in leaves. 

My solution to this is to override the createNodeDelegate() method  in my 
ValDataObject class and in there create an instance of my subclassed 
ChildFactory<String> named ParameterChildFactory


Code:
@Override
    protected Node createNodeDelegate() {   
        ParameterChildFactory childFactory = new ParameterChildFactory(this);
        DataNode valFileNode = new DataNode(this, 
Children.create(childFactory, true), this.getLookup());        
        valFileNode.setDisplayName(this.getName());
        
        return valFileNode;
    }



  which looks like this:

Code:
private class ParameterChildFactory extends ChildFactory<String>{
        private final ValDataObject vdo;
        private ParameterChildFactory(ValDataObject vdo) {
            this.vdo = vdo;
        }

        @Override
        protected boolean createKeys(List<String> list) {    
            
            try {
                list.addAll(vdo.getPrimaryFile().asLines());                
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
            return true;
        }        
        
        
        @Override
        public Node createNodeForKey(String key) {
            Node parameterNode = new AbstractNode(Children.LEAF);             
 
            parameterNode.setDisplayName(key);
            return parameterNode;
        }

        @Override
        protected Node createWaitNode() {
            Node waitNode = new AbstractNode(Children.LEAF);
            waitNode.setDisplayName("Loading...");
            return waitNode;
        }                        
    }



This above code does not work, no children shows up. However, I found a 
solution to make them show up; by replacing a row in the 
createNodeForKey(String key) method above:

[Exclamation] Solution:




Code:

@Override
        public Node createNodeForKey(String key) {
            Node parameterNode = new AbstractNode(Children.LEAF, 
this.vdo.getLookup());              //<--- Changed row, this.vdo.getLookup() 
added.
            parameterNode.setDisplayName(key);
            return parameterNode;
        }



 

Why doesn't the children leaves show up until I pass the lookup of the 
ValDataObject to the constructor of the AbstractNode?

I've seen several code examples where similar things are done, but nowhere 
where is the lookup passed to the AbstractNode.

I've attached two screenshots showing the behaviour of the DataNode in the 
two cases described above. When the children are not showing, the "+"-sign is 
present, but clicking it merely makes it dissappear and no children leaves 
shows up. I've also attached the ValDataObject.java.

[Question] Can someone please explain to me what difference the lookup makes 
in this case and why it is necessary in the creation of the AbstractNode?

My great thanks to anyone who is willing to enlighten me in this matter.

//plopp




Attachments: 
http://forums.netbeans.org//files/valdataobject_127.java
http://forums.netbeans.org//files/working_leafs_798.jpg
http://forums.netbeans.org//files/non_working_leafs_119.jpg



[nbusers] Subclassing ChildFactory<String> and children does not show up

plopp 05/30/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close