// 3. Clone the object
// 4. Add the cloned object to the dummy process
// 5. Re-establish the object references (now based on the elements of the dummy process)
// If this fails, the object will be removed from the dummy process again.
StandardMsgContainer msgContainer = ModelConnector.getInstance().getMsgContainer();
msgContainer.clearMsgs();
for (FigureEnumeration fe = workspaceView.selectionElements(); fe.hasMoreElements();)
{
Figure next = fe.nextFigure();
if (next instanceof FlowConnection)
{
FlowConnection flowConnection = (FlowConnection) next;
ControlLink link = flowConnection.getControlLink();
if (! copiedSourceNodes.contains(link.getSourceSocket().getNode())
|| ! copiedSourceNodes.contains(link.getTargetSocket().getNode()))
{
// Link source or target has not been copied
continue;
}
flowConnection.encodeGeometry();
link = (ControlLink) link.clone();
process.addControlLink(link);
if (! msgContainer.isEmpty())
{
// One of the end points of the link is not present in the copied set,
// so remove the link from the dummy process again.
process.removeControlLink(link);
msgContainer.clearMsgs();
}
}
else if (next instanceof ParamConnection)
{
ParamConnection paramConnection = (ParamConnection) next;
DataLink link = paramConnection.getDataLink();
Param sourceParam = link.getSourceParam();
Param targetParam = link.getTargetParam();
if (sourceParam instanceof NodeParam)
{
if (! copiedSourceNodes.contains(((NodeParam) sourceParam).getSocket().getNode()))
{
// Link source or target has not been copied
continue;
}
}
else
{
// Don't copy process variable links
continue;
}
if (targetParam instanceof NodeParam)
{
if (! copiedSourceNodes.contains(((NodeParam) targetParam).getSocket().getNode()))
{
// Link source or target has not been copied
continue;
}
}
else
{
// Don't copy process variable links
continue;
}
paramConnection.encodeGeometry();
link = (DataLink) link.clone();
process.addDataLink(link);
if (! msgContainer.isEmpty())
{
// One of the end points of the link is not present in the copied set,
// so remove the link from the dummy process again.
process.removeDataLink(link);
msgContainer.clearMsgs();
}
}
}
// Re-establish inter-object links and links to other items