NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Subclassing ChildFactory<String> and children does not show up

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
plopp



Joined: 30 May 2012
Posts: 1
Location: Gothenburg, Sweden

PostPosted: Wed May 30, 2012 2:03 pm    Post subject: Subclassing ChildFactory<String> and children does not show up Reply with quote

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



working_leafs.jpg
 Description:
Screenshot after problem was solved.
 Filesize:  24.11 KB
 Viewed:  985 Time(s)

working_leafs.jpg



non_working_leafs.jpg
 Description:
Screenshot showing the problem.
 Filesize:  17.25 KB
 Viewed:  985 Time(s)

non_working_leafs.jpg



ValDataObject.java
 Description:
The complete ValDataObject class.

Download
 Filename:  ValDataObject.java
 Filesize:  2.4 KB
 Downloaded:  28 Time(s)

Back to top
gbivins



Joined: 14 Aug 2009
Posts: 162

PostPosted: Mon Jun 04, 2012 6:14 pm    Post subject: Reply with quote

Hello plopp,
I don't know the answer but I ran into this exact issue as well. It seems like a bug because none of the docs/examples/tutorials describe this.
I am using netbeans 7.1 apis, wonder how long the behavior has been like this.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo