Reparent JGoLabeledLink doesnt reparent the text

I have a problem when reparenting links in and out of subgraphs.

When calling: getSelection().addCollection(deflayer.addCollection(getSelection(), true, deflayer));

It seems to reparent the link correctly so its parent is null and the labels’ parent is null. (when dragging to the top level).

However when I then drag two nodes back into the subgraph and call:
subgraph.addCollection(getSelection(), true, deflayer);

It correctly makes the links’ parent the subgraph however the labels’ parent stays as null which then causes it to not be drawn correctly.

I have found this is also an issue with the BoxApp example.
By overriding the method in

public void newLink(JGoPort from, JGoPort to) {
JGoDocument doc = getDocument();
if (doc == null) return;

  JGoLabeledLink link = new JGoLabeledLink(from, to);
  JGoLinkLabel label = new JGoLinkLabel("Hello");

  JGoSubGraphBase.reparentToCommonSubGraph(link, from, to, true, doc.getLinksLayer());

  fireUpdate(JGoViewEvent.LINK_CREATED, 0, link);


Put two nodes in the subgraph, make a link between them. Works fine.
Drag both nodes out of the subgraph. Works fine.
Drag both nodes back in the subgraph. Works fine. (However the labels parent is incorrect but it draws it correctly).
Move the subgraph (this causes it to get reinserted into the document) and you now notice that the link line goes over the top of the text (this is because the order it is drawing the objects).

I’ve tried a few things to circumvent this problem but no luck.

Any ideas?


First of all, you win the prize for “best problem report of the month”! Well explained and easy to reproduce with your additions to BoxView. Thanks very much.
This appears to be an omission in the reparentAllLinksToSubGraphs method in JGoSubGraphBase. While this method is successfully reparenting all JGoLinks, it is not reparenting the labels of JGoLabeledLinks.

You can correct his by modifying the reparentToCommonSubGraph method in JGoSubGraphBase. Add the following code to the end of this method:
if (obj instanceof JGoLabeledLink) {
JGoLabeledLink ll = (JGoLabeledLink) obj;
if (ll.getFromLabel() != null)
reparentToCommonSubGraph(ll.getFromLabel(), child1, child2, behind, layer);
if (ll.getMidLabel() != null)
reparentToCommonSubGraph(ll.getMidLabel(), child1, child2, behind, layer);
if (ll.getToLabel() != null)
reparentToCommonSubGraph(ll.getToLabel(), child1, child2, behind, layer);
This change will be included in the next release of JGo.