*
* @param newFigure The newly added {@link NodeFigure} or {@link SocketFigure}
*/
private void determineSocketFiguresFromSelection(Figure newFigure)
{
SocketFigure newSocketFigure = null;
if (newFigure instanceof NodeFigure)
{
newNodeFigure = (NodeFigure) newFigure;
}
else if (newFigure instanceof SocketFigure)
{
newSocketFigure = (SocketFigure) newFigure;
}
// Only one element selected?
if (workspaceView.selectionCount() != 1)
{
// No or multiple elements selected, can't autoconnect
return;
}
selectedFigure = (Figure) workspaceView.selection().get(0);
if (newNodeFigure != null)
{
// Selected is a node
if (selectedFigure instanceof NodeFigure)
{
NodeFigure selectedNodeFigure = (NodeFigure) selectedFigure;
if (newNodeFigure instanceof InitialNodeFigure)
{
// We inserted an initial node, link the exit socket of the new node
// with an entry socket of the selected node (reverse way)
sourceSocketFigure = selectedNodeFigure.getConnectableSocket(true);
targetSocketFigure = newNodeFigure.getConnectableSocket(false);
}
else
{
// For any other nodes, link the regular way
sourceSocketFigure = newNodeFigure.getConnectableSocket(true);
targetSocketFigure = selectedNodeFigure.getConnectableSocket(false);
}
}
else if (selectedFigure instanceof SocketFigure)
{
SocketFigure selectedSocketFigure = (SocketFigure) selectedFigure;
if (selectedSocketFigure.isEntrySocket())
{
// An entry socket is selected
targetSocketFigure = selectedSocketFigure;
sourceSocketFigure = newNodeFigure.getConnectableSocket(false);
}
else
{
// We may do this if the socket of the selected figure does not have a control link
// attached or if the node of the socket supports multiple exit links
NodeSocket socket = selectedSocketFigure.getNodeSocket();
if (!socket.hasControlLinks() || socket.getNode().isMultiExitLinkNode())
{
// An exit socket with no Links has been selected
sourceSocketFigure = selectedSocketFigure;
targetSocketFigure = newNodeFigure.getConnectableSocket(true);
}
}
}
}
else if (newSocketFigure != null)
{
// Selected is a node
if (selectedFigure instanceof NodeFigure)
{
NodeFigure selectedNodeFigure = (NodeFigure) selectedFigure;
if (newSocketFigure.isEntrySocket())
{
// We inserted an initial node, link the exit socket of the new node
// with an entry socket of the selected node (reverse way)
sourceSocketFigure = selectedNodeFigure.getConnectableSocket(false);
targetSocketFigure = newSocketFigure;
}
else
{
// For any other nodes, link the regular way
sourceSocketFigure = newSocketFigure;
targetSocketFigure = selectedNodeFigure.getConnectableSocket(true);
}
}
else if (selectedFigure instanceof SocketFigure)
{
SocketFigure selectedSocketFigure = (SocketFigure) selectedFigure;
if (selectedSocketFigure.isEntrySocket())
{
// An entry socket has been selected
sourceSocketFigure = selectedSocketFigure;
targetSocketFigure = newSocketFigure;
}