How to refresh all ExplorerViews showing the same data?

Go To StackoverFlow.com

0

What is the smoothest (easy and good in design) way to refresh all data after some changed? I have an application, where may be opened multiple windows showing the same data. The user may edit one node in one of the windows, but I need to refresh that node (or its children) in every view.

Example: I have ExplorerView using the OutlineView in my TopComponent and it shows all Chapters in tree structure. But I can open this window many times (like "new window" in MS Word, which is another "view" on the same data). When I change the title of one chapter, I need to refresh it everywhere, where it is visible (in all expanded nodes).

I see one solution, but it has some pros and cons: Make my own lookup and store in it all opened root nodes of all opened ExplorerViews. Then on every edit, just cycle through all opened root nodes and call some method on them to recreate the viewed structure (call setChildren... like when showing for the first time). But the tree view collapses. And if I would create some mechanism, some my implementation of the OutlineView, which would remember all the expanded nodes, so it would recreate the expanded tree (but not the whole tree, only as it was), it might take some time, when having too much data, right?

2012-04-03 21:22
by Martin Vondráček
I tried a bit different solution, but I have not solved big problem. I made my lookup and store there all nodes (well implementation of interfaces, which were subclasses of those nodes - inspired by the Reloadable capabilities article by Geertjan). Then I could update only the node, which changed (cycle through them and check the data, it shows), or its parent. The problem was that I don't know how to remove these objects from lookup when recreating children of some node (setChildren). So the lookup only growed, because I did not know the nodes to remove them from it after every change - Martin Vondráček 2012-04-03 21:25


1

Each view is built with a set of nodes. If you modify the data in one node then the modification is reflected in the view containing the node, but not in the other views (not the other nodes) :-(.

When I architect a NB RCP based application I build a model with "entities". These entities have "abilities" that I model with the NetBeans Lookup. These are usually plain POJOs.

Then when I want to "see" an entity I create a "Node" for it. You can have as many nodes you want (as many "MS Word" views as you want), but you want to keep a single "tree" with your model.

If I change a property in an "entity" this change is propagated to all the nodes listening to it. You may want to see how to relate 'abilities' with 'actions'.

2012-04-04 19:53
by NoName
Thx, in fact, my app is partly built by your example (well, I looked there too, but I built it from the Geertjan's articles on CRUD capabilities, with Derby, on DZone, because at first I wanted to use database, only later I went to only serialization). But I have 2 questions, which I don't see to them answers in your articles, maybe you resolved them too - Martin Vondráček 2012-04-05 08:32
1) Maybe I am doing sth. wrong, but I think, in your (and my) way, the lookup, which is shared by the nodes, is growing and growing, because after each call of setChildren via the ReloadAction, the old nodes are not removed, just new (often of the same value) nodes are added - Martin Vondráček 2012-04-05 08:36
2) How would you share the lookup between more windows? In my case, I can't open the other "views" on the same tree from some first window, because I have ie. Chapters and Characters (which appear in those chapters) data. I open new views to look at Characters in the particular Chapter. But of course, some characters appear in many Chapters, so I need to update the Character Adam in every view, where it is visible, after it's edit. And unfortunately, this example is not the only one, I can open Characters window from many sources. That is why I thought about some central lookup - Martin Vondráček 2012-04-05 08:41
And sorry for the 3rd problem/question:-): Have you ever solved the tree structure ie. in the OutlineView, so that after reloading the nodes, it expands like it was befor reloading? I am just asking, if you made it. I have read somewhere some approach, which I will try (make my own class, which will extend OutlineView and remember the expanded nodes, but the example was for C#). Sorry for this "kind of spam":-), the most important thing is the growing lookup, which I encounter while doing central lookup and putting all capabilities there (in the Node's constructor, like you add it to ic) - Martin Vondráček 2012-04-05 08:46
Hi, well, maybe a mailing list is more appropriate for this discussion. Regarding 1) there's no memory leaks as far as I can tell, previous node are replaced with new ones. 2) In my approach I don't "share" lookups between windows: the entity model is a single one, and windows (views) just show a portion of the entity model. If this changes the windows change too, but views don't "share" anything. 3) I think the OutlineView retains the opened nodes if you use a Children.Keys and not a ChildFactory, and if you avoid using setChildren. Consider using a mailing list (I can't add more stuff here - NoName 2012-04-06 16:14
Ad 1) You are right, because you don't have tree structure. I got growing list, because all nodes had ReloadableCapability and every setChildren in refresh method of that capability added children nodes with new capabilities again. So I had to remove all of them at the same time. It is not good solution, I will see later. Ad 3) Thx for info, I will try to look at it and probably ask something on NB forums. I now don't get, what to do in my capability instead of setChildren, when I need to create children of node. But this problem must wait for a while - Martin Vondráček 2012-04-06 19:27
Ok. Feel free to drop me an email in case of need - NoName 2012-04-06 19:45