I’m allowing a user to change a selected JGoObject from one subclass of JGoBasicNode to another subclass, to effectively change it’s visual properties.
A node can have different visual properties (see init() method)…
[code]
public abstract class Node extends JGoBasicNode {
public Node() {
super("");
init();
}
public abstract void init();
public Node(Node that) {
//super((JGoBasicNode)that);
this();
this.setLocation(that.getLocation());
this.setPort(that.getPort());
}
}
public class BasicNode extends Node {
public BasicNode() {super(); }
public BasicNode(Node that) {
super(that);
init();
}
public void init() {
setBrush(JGoBrush.white);
setPen(JGoPen.darkGray);
}
}[/code]
is ‘converted’ (think horizontal casting, would such a thing exist)
myContextMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
JGoDocument doc = constNode.getDocument();
doc.startTransaction();
doc.addObjectAtTail(<span style="font-weight: bold;">new BasicNode(constNode)</span>);
doc.removeObject(constNode);
doc.endTransaction("converted to basic node");
}
});
I don’t care about any visual properties being copied, I’d actually prefer that the copied object start default as a clean JGoBasicNode. I do need to maintain the links, and any other ‘important’ (i.e. non-visual - the ‘soul’ of the object) assets or children that the JGoBasicNode had.
Is there a convenient way to do this? Am I going about it the right way, generally speaking? Right now the links are all discarded and it appears that the port object (that I can left drag new links from) is also discarded. I was hoping this would work by reusing the port object but that won’t work.
Is the best way to do this simply to iterate through each link attached to the port, and manually attach it to the new port, as if the user had dragged the link handle to a new port a la default behavior?
some pictures to demonstrate:
corrupted: