Restore state of subgraphs

I saved state of my view-objects in own data structure

Then i try to restore it
1.creating all ? extends JGoNode (collapse/expand nodes if it's needed)
2. calling addObjectAtTail() for all nodes
3. creating of links
4. call addJGoLink() for all links
[code]
public void addJGoLink(JGoLink jGoLink) {
JGoDocument doc = getDocument();
if (doc == null)
return;

JGoSubGraphBase.reparentToCommonSubGraph(jGoLink, jGoLink.getFromPort(), jGoLink.getToPort(), true, doc.getLinksLayer());
fireUpdate(JGoViewEvent.LINK_CREATED, 0, jGoLink);
doc.endTransaction(getEditPresentationName(4));
}
[/code]
there're links outside subgraphs
after expand:
after collapse all links recalculates almost correctly.
How to achieve this arrangement without programmatically expand|collapse ?

When saving collapsed subgraph nodes, are you also saving and restoring the getSavedBounds() and getSavedPaths() HashMaps that remember the relative position and size of the child nodes and the relative points of the strokes of the child links?

Unrelated issue: in your addJGoLink method, you probably don’t want to fire a LINK_CREATED event, because that’s just supposed to be for user-drawn links, whereas it appears that you are calling this method for programmatic (re-)construction of a subgraph.

SavedBounds - yes
SavedPaths - no (I read source code and didn't find in expand() any getSavedPath() usage, but now I see it in expandChild())
2.
Yes. It isn't needed.
I get realization from View.newLink()

Actually, if you are just depending on the standard routing of the links, you probably don’t need to save the routes of the links in the collapsed subgraphs, since you can depend on the normal results of calculateStroke() to produce the right routes.

So I think the problem isn’t with saving/restoring the routes of the links.

I’m wondering if you are restoring the positions of the (invisible) child nodes correctly, relative to the subgraph’s Handle.

About positions of internal nodes.

I use JGoDocumentListener to track changes in jGoObjects locations and other properties.
here is test code:
[code]
public void documentChanged(JGoDocumentEvent e) {
if (e.getHint() == JGoDocumentEvent.CHANGED) {
...
//here is code that remembers position of e.getJGoObject()
...
System.out.println("MODIFIED OBJECT: " + e.getJGoObject() + "Loc" + e.getJGoObject().getLocation());
if (e.getJGoObject() instanceof JGoSubGraph) {
JGoSubGraph groupNode = (JGoSubGraph)e.getJGoObject();

JGoListPosition pos= groupNode.getFirstObjectPos();
while (pos != null) {
JGoObject obj = groupNode.getObjectAtPos(pos);
pos = groupNode.getNextObjectPos(pos);
System.out.println(" INT OBJECT: " + obj + "Loc" + obj.getLocation());
}
}
}
[/code]
After expanding see something like this:
MODIFIED OBJECT: com.nwoods.jgo.JGoSubGraph$402ecbLocjava.awt.Point[x=76,y=259]
INT OBJECT: com.nwoods.jgo.JGoRectangle$1c47573Locjava.awt.Point[x=86,y=269]
INT OBJECT: com.nwoods.jgo.JGoSubGraphPort$c194adLocjava.awt.Point[x=86,y=269]
INT OBJECT: com.nwoods.jgo.JGoIconicNode$1b28fb5Locjava.awt.Point[x=127,y=285]
INT OBJECT: com.nwoods.jgo.JGoIconicNode$175b132Locjava.awt.Point[x=127,y=285]
INT OBJECT: com.nwoods.jgo.JGoText$121b1f2Locjava.awt.Point[x=118,y=278]
INT OBJECT: com.nwoods.jgo.JGoSubGraphHandle$1299f0aLocjava.awt.Point[x=86,y=269]
MODIFIED OBJECT: com.nwoods.jgo.JGoSubGraph...
x 3 times
MODIFIED OBJECT: com.nwoods.jgo.JGoIconicNode$1b28fb5Locjava.awt.Point[x=127,y=285]
MODIFIED OBJECT: com.nwoods.jgo.JGoIconicNode$1b28fb5Locjava.awt.Point[x=127,y=285]
MODIFIED OBJECT: com.nwoods.jgo.JGoImage$17c3833Locjava.awt.Point[x=386,y=293]
MODIFIED OBJECT: com.nwoods.jgo.JGoText$4db085Locjava.awt.Point[x=402,y=328]
MODIFIED OBJECT: com.nwoods.jgo.JGoIconicNodePort$c8411Locjava.awt.Point[x=399,y=306]
MODIFIED OBJECT: com.nwoods.jgo.JGoSubGraph$402ecbLocjava.awt.Point[x=76,y=259]
INT OBJECT: com.nwoods.jgo.JGoRectangle$1c47573Locjava.awt.Point[x=86,y=269]
INT OBJECT: com.nwoods.jgo.JGoSubGraphPort$c194adLocjava.awt.Point[x=86,y=269]
INT OBJECT: com.nwoods.jgo.JGoIconicNode$1b28fb5Locjava.awt.Point[x=402,y=309]
INT OBJECT: com.nwoods.jgo.JGoIconicNode$175b132Locjava.awt.Point[x=127,y=285]
INT OBJECT: com.nwoods.jgo.JGoText$121b1f2Locjava.awt.Point[x=118,y=278]
INT OBJECT: com.nwoods.jgo.JGoSubGraphHandle$1299f0aLocjava.awt.Point[x=86,y=269]
MODIFIED OBJECT: com.nwoods.jgo.JGoIconicNode$175b132Locjava.awt.Point[x=127,y=285]
MODIFIED OBJECT: com.nwoods.jgo.JGoIconicNode$175b132Locjava.awt.Point[x=127,y=285]
MODIFIED OBJECT: com.nwoods.jgo.JGoImage$1f02b4bLocjava.awt.Point[x=121,y=337]
MODIFIED OBJECT: com.nwoods.jgo.JGoText$aa4bf8Locjava.awt.Point[x=137,y=372]
MODIFIED OBJECT: com.nwoods.jgo.JGoIconicNodePort$24f1a9Locjava.awt.Point[x=134,y=350]

MODIFIED OBJECT: com.nwoods.jgo.JGoSubGraph$402ecbLocjava.awt.Point[x=76,y=259]
INT OBJECT: com.nwoods.jgo.JGoRectangle$1c47573Locjava.awt.Point[x=86,y=269]
INT OBJECT: com.nwoods.jgo.JGoSubGraphPort$c194adLocjava.awt.Point[x=86,y=269]
INT OBJECT: com.nwoods.jgo.JGoIconicNode$1b28fb5Locjava.awt.Point[x=402,y=309]
INT OBJECT: com.nwoods.jgo.JGoIconicNode$175b132Locjava.awt.Point[x=137,y=353]
INT OBJECT: com.nwoods.jgo.JGoText$121b1f2Locjava.awt.Point[x=118,y=278]
INT OBJECT: com.nwoods.jgo.JGoSubGraphHandle$1299f0aLocjava.awt.Point[x=86,y=269]
MODIFIED OBJECT: com.nwoods.jgo.JGoRectangle$1c47573Locjava.awt.Point[x=86,y=269]
MODIFIED OBJECT: com.nwoods.jgo.JGoSubGraph...
x 6 times...
In other words JGoDocumentEvent contains JGoIconicNodes with old coordinates. The same is on collapsing.
Why is it so?

You should look at the value of e.getHint() to see why each document change is happening.

When saving the state of a collapsed JGoSubGraph, you should be saving the locations of each of the child nodes as well as the SavedBounds for those same nodes, so that you can restore the same state upon reconstruction of the subgraph.

But you probably know that already, so I’m afraid I don’t understand what you are asking.

thanks, I made out all aforesaid. It seems that all works correctly now.

But I can't save WasExpanded property
Methods isWasExpanded(), setWasExpanded() aren't public
How can I save it and set it afterwards ?

Yes, this property should be public. Please just make the property public in your JGo sources and we’ll do the same in our next release.