|
@@ -471,10 +471,32 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
if (mode == DRAG_CONNECTION && connectionFrom != null && connectionTo != null
|
|
|
&& connectionFrom != connectionTo) {
|
|
|
// Create new Connection
|
|
|
- Link l = new SimpleLink("Ethernet: " + connectionFrom.getName()
|
|
|
+ /**
|
|
|
+ * Link of the new Connection
|
|
|
+ */
|
|
|
+ Link l = null;
|
|
|
+ /**
|
|
|
+ * Devices of the connection -> to find common Link
|
|
|
+ */
|
|
|
+ LinkedList<SmartDevice> devices = new LinkedList<SmartDevice>();
|
|
|
+ devices.add(connectionFrom);
|
|
|
+ devices.add(connectionTo);
|
|
|
+ for(Link link:network.getLinks()){
|
|
|
+ if(link.getDevices().containsAll(devices)){
|
|
|
+ l = link;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Create new Connection if no link was found
|
|
|
+ */
|
|
|
+ if(l==null){
|
|
|
+ l= new SimpleLink("Ethernet: " + connectionFrom.getName()
|
|
|
+ " to " + connectionTo.getName());
|
|
|
- l.addDevice(connectionFrom);
|
|
|
- l.addDevice(connectionTo);
|
|
|
+ l.addDevice(connectionFrom);
|
|
|
+ l.addDevice(connectionTo);
|
|
|
+ }
|
|
|
+ //Create ports and add to controller
|
|
|
Port p1 = new Port(connectionFrom, (short) 1,(long) (Math.random()*300+300));
|
|
|
Port p2 = new Port(connectionTo, (short) 2,(long) (Math.random()*300+300));
|
|
|
Connection c = new ConnectionPerformance(l, new SimpleProtocol(p1, p2));
|
|
@@ -486,9 +508,10 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
connectionTo.addPort(p2);
|
|
|
connectionFrom.addLink(l);
|
|
|
connectionFrom.addPort(p1);
|
|
|
- l.addConnection(c);
|
|
|
- model.addConnection(c);
|
|
|
- model.addConnectionNetwork(l);
|
|
|
+ network.addConnectionToLink(c, l);
|
|
|
+ network.addConnection(c);
|
|
|
+ if(!network.getLinks().contains(l))
|
|
|
+ network.addLink(l);
|
|
|
|
|
|
}
|
|
|
connectionFrom = null;
|
|
@@ -853,10 +876,22 @@ public class VisualisationInteractor implements MouseInputListener,
|
|
|
// Create Connection
|
|
|
itemCreateConnection = new JMenuItem("Create Connection");
|
|
|
itemCreateConnection.addActionListener(e->{
|
|
|
+ LinkedList<SmartDevice> selectedDevices = new LinkedList<SmartDevice>(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices);
|
|
|
LinkedList<Port> ports = new LinkedList<Port>();
|
|
|
- for(SmartDevice d: controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices)
|
|
|
+ for(SmartDevice d: selectedDevices)
|
|
|
ports.add(new Port(d, (short) 12));
|
|
|
- new ConnectionCreationDialog(ports,new SimpleLink("TestLink"), controller, panel);
|
|
|
+ Link link = null;
|
|
|
+ for(Link l:network.getLinks()){
|
|
|
+ if(l.getDevices().containsAll(selectedDevices))
|
|
|
+ link = l;
|
|
|
+ }
|
|
|
+ if(link == null){
|
|
|
+ link = new SimpleLink("New Link");
|
|
|
+ for(SmartDevice device: selectedDevices){
|
|
|
+ controller.getNetworkController().addLinkToDevice(link, device);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ new ConnectionCreationDialog(ports,link, controller, panel);
|
|
|
if(controller.getSettingsController().getConfigurationManager().getSelectionModel().selectedDevices.isEmpty())
|
|
|
mode = NOTHING;
|
|
|
else
|