|
@@ -287,14 +287,14 @@ public class NetworkController {
|
|
|
public void removeDeviceFromConnectionAndProtocol(Port p, Connection connection){
|
|
|
if(connection != null){
|
|
|
connection.removeSmartDevice(p);
|
|
|
- connection.getProtocol().removeDevice(p);
|
|
|
//TODO: Protocol ?
|
|
|
- if(connection.getProtocol()!=null)
|
|
|
+ if(connection.getProtocol()!=null){
|
|
|
connection.getProtocol().removeDevice(p);
|
|
|
- if(connection.getParticipants().size() == 0)
|
|
|
- deleteConnection(connection);
|
|
|
+ if(connection.getParticipants().size() == 0)
|
|
|
+ deleteConnection(connection);
|
|
|
+ }
|
|
|
}
|
|
|
- if(p!=null)
|
|
|
+ if(p!=null && p.getConnection() == connection)
|
|
|
p.setConnection(null);
|
|
|
}
|
|
|
|
|
@@ -409,14 +409,19 @@ public class NetworkController {
|
|
|
try{
|
|
|
newCon = newConnectionClass.newInstance();
|
|
|
newCon.setProtocol(connection.getProtocol());
|
|
|
- addConnectionToLink(newCon, connection.getLink());
|
|
|
newCon.setStatus(connection.getStatus());
|
|
|
newCon.setPacketLossProbability(connection.getPacketLossProbability());
|
|
|
newCon.setName(connection.getName());
|
|
|
+ if(getConnections().contains(connection)){
|
|
|
+ removeConnection(connection);
|
|
|
+ addConnection(newCon);
|
|
|
+ }
|
|
|
+ addConnectionToLink(newCon, connection.getLink());
|
|
|
+ connection.setProtocol(null);
|
|
|
for (Iterator<Port> p = connection.getParticipants().iterator(); p.hasNext();) {
|
|
|
Port type = (Port) p.next();
|
|
|
removeDeviceFromConnection(type, connection);
|
|
|
- addDeviceToConnection(type, connection);
|
|
|
+ addDeviceToConnection(type, newCon);
|
|
|
|
|
|
}
|
|
|
}catch(Exception e){
|
|
@@ -425,7 +430,14 @@ public class NetworkController {
|
|
|
* Restore old connection on Failure
|
|
|
*/
|
|
|
if(newCon != null){
|
|
|
- newCon.setProtocol(null);
|
|
|
+ if(getConnections().contains(newCon)){
|
|
|
+ removeConnection(newCon);
|
|
|
+ addConnection(connection);
|
|
|
+ }
|
|
|
+ if(newCon.getProtocol()!=null){
|
|
|
+ connection.setProtocol(newCon.getProtocol());
|
|
|
+ newCon.setProtocol(null);
|
|
|
+ }
|
|
|
if(newCon.getLink()!=null)
|
|
|
newCon.getLink().removeConnection(newCon);
|
|
|
newCon.setLink(null);
|
|
@@ -434,27 +446,14 @@ public class NetworkController {
|
|
|
if(type.getConnection()!=connection)
|
|
|
type.setConnection(connection);
|
|
|
newCon.removeSmartDevice(type);
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
- if(getConnections().contains(connection)){
|
|
|
- removeConnection(connection);
|
|
|
- }
|
|
|
- addConnection(newCon);
|
|
|
+
|
|
|
controller.getSettingsController().getConfigurationManager().getSelectionModel().clickedConnection.clear();
|
|
|
-
|
|
|
-
|
|
|
- connection.setLink(null);
|
|
|
connection.setProtocol(null);
|
|
|
- connection.setStatus(Connection.TERMINATED);
|
|
|
- connection.setName("deleted");
|
|
|
- for(Port p: newCon.getParticipants()){
|
|
|
- connection.removeSmartDevice(p);
|
|
|
- }
|
|
|
+ deleteConnection(connection);
|
|
|
|
|
|
controller.notifyObservers();
|
|
|
|
|
@@ -497,7 +496,9 @@ public class NetworkController {
|
|
|
* @param c Connection to be deleted
|
|
|
*/
|
|
|
public void deleteConnection(Connection c) {
|
|
|
- if(c == null)return;
|
|
|
+ if(c == null)
|
|
|
+ return;
|
|
|
+ c.setName("Deleted");
|
|
|
LinkedList<Port> ports = new LinkedList<Port>(c.getParticipants());
|
|
|
for(Port p:ports)
|
|
|
removeDeviceFromConnectionAndProtocol(p, c);
|
|
@@ -548,8 +549,6 @@ public class NetworkController {
|
|
|
public Link changeLinkType(Link oldLink, Class<? extends Link> newType) {
|
|
|
if(newType == null)
|
|
|
return null;
|
|
|
- System.out.println("Change Link:");
|
|
|
- printLinkHelp(oldLink);
|
|
|
/**
|
|
|
* New Link which was created
|
|
|
*/
|
|
@@ -565,6 +564,12 @@ public class NetworkController {
|
|
|
// Set old Name
|
|
|
newLink.setName(oldLink.getName());
|
|
|
|
|
|
+ // Add to Model
|
|
|
+ if(getLinks().contains(oldLink)){
|
|
|
+ removeLink(oldLink);
|
|
|
+ addLink(newLink);
|
|
|
+ }
|
|
|
+
|
|
|
//Connection to the new Link
|
|
|
for(Connection c: new LinkedList<Connection>(oldLink.getConnections())){
|
|
|
addConnectionToLink(c, newLink);
|
|
@@ -575,30 +580,7 @@ public class NetworkController {
|
|
|
removeLinkFromDevice(oldLink, device);
|
|
|
addLinkToDevice(newLink, device);
|
|
|
}
|
|
|
-
|
|
|
- System.out.println("oldLink:");
|
|
|
- printLinkHelp(oldLink);
|
|
|
- System.out.println("new Link:");
|
|
|
- printLinkHelp(newLink);
|
|
|
-
|
|
|
- // Add to Mode
|
|
|
- if(getLinks().contains(oldLink)){
|
|
|
- removeLink(oldLink);
|
|
|
- addLink(newLink);
|
|
|
- }
|
|
|
return newLink;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private void printLinkHelp(Link l){
|
|
|
- System.out.println("Link: "+l.getName());
|
|
|
- for(SmartDevice d:l.getDevices()){
|
|
|
- System.out.println(d.getName());
|
|
|
- }
|
|
|
- System.out.println("Connections:");
|
|
|
- for(Connection c:l.getConnections()){
|
|
|
- System.out.println(c.getName());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|