NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
plopp
Joined: 30 May 2012 Posts: 1 Location: Gothenburg, Sweden
|
Posted: Wed May 30, 2012 2:03 pm Post subject: Subclassing ChildFactory<String> and children does not show up |
|
|
Hi,
I have a problem with the Nodes API, I've found the solution myself, but I don't understand why the solution works...
Problem: Children leaves not showing up when expanding DataNode in "Favorites"-explorer.
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:
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.
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
| Description: |
| Screenshot after problem was solved. |
|
| Filesize: |
24.11 KB |
| Viewed: |
986 Time(s) |

|
| Description: |
| Screenshot showing the problem. |
|
| Filesize: |
17.25 KB |
| Viewed: |
986 Time(s) |

|
| 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
|
Posted: Mon Jun 04, 2012 6:14 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|
|