NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
Mvek
Joined: 31 Oct 2011 Posts: 43 Location: Prague, Czech Republic
|
Posted: Thu Mar 01, 2012 2:56 pm Post subject: [Solved by another way] Method node.parentNode() returns null when deleting multiple nodes |
|
|
I can't find solution, why my Explorer Manager (either BeanTreeView or OutlineView) in NetBeans Platform 7.1 application works fine with tree structure, when deleting single Node, but not when deleting multiple nodes. The problem is with the refreshing the tree, not with the deleting itself. When calling delete action (system action), it calls destroy() method on my Node:
| Code: | @Override
public void destroy() throws IOException {
//removing the business object
...
try {
IReloadableViewCapability rvc;
if (getParentNode() != null) {
rvc = this.getParentNode().getLookup().lookup(IReloadableViewCapability.class);
} else {
rvc = this.getLookup().lookup(IReloadableViewCapability.class);
}
rvc.reloadChildren();
} catch (Exception ex) {
logger.log(Level.WARNING, null, ex);
}
fireNodeDestroyed();
} |
And let's say, I have this structure:
Now let's say, I want delete nodes 1.1, 1.2 and 1.3. I select them all, call the delete action and it calls destroy() method of the node 1.1, where it deletes data for it and calls my reloadChildren() method on parentNode of the node 1.1 (as shown in the code above).
Then after deleting node 1.2, it comes to 1.3 It deletes deletes data for 1.3, but now the getParentNode() returns null, even though, it again should return the Node 1.
The similar problem occurs when deleting Node 1 and Node 2 together (or any other top nodes), even though, they are children of special RootNode node. The only difference in root is that there it goes ok only for the first node, but than any other one selected, can't find its parent.
Where could be the problem? |
|
| Back to top |
|
 |
Mvek
Joined: 31 Oct 2011 Posts: 43 Location: Prague, Czech Republic
|
Posted: Fri Mar 02, 2012 8:58 pm Post subject: |
|
|
The better solution to this problem is just avoid calling parentNode, but change a bit my implementation of ChildFactory. My CHildFactory now also implements NodeListener and in the nodeDestroyed overriden method it calls just:
Then I have added the listener to the created node:
| Code: | @Override
protected Node createNodeForKey(Chapters key) {
ChapterNode chapterNode = new ChapterNode(key);
chapterNode.addNodeListener(this);
return chapterNode;
} |
And then I have modified my node's destroy() method:
| Code: | @Override
public void destroy() throws IOException {
//removing the business object
...
fireNodeDestroyed();
} |
|
|
| 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
|
|