Parcourir la source

Fixes RightClickDelte not removing empty connections&links

Andreas T. Meyer-Berg il y a 5 ans
Parent
commit
ff9159dee1

+ 13 - 7
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/Controller.java

@@ -226,19 +226,16 @@ public class Controller {
 	public void deleteSmartDevice(SmartDevice toDelete) {
 		if (toDelete == null)
 			return;
-		// Remove from Links
-		for (Link link : toDelete.getLinks())
-			removeSmartDeviceFromLink(toDelete, link);
-		// Remove Links from Device
-		toDelete.getLinks().clear();
 
 		// Delete Connections
 		for (Port p : toDelete.getPorts()) {
 			//Skip ports that are not connected
 			if(p.getConnection()==null)continue;
+			this.removeDeviceFromConnection(p, p.getConnection());
+			
 			/**
 			 * Connection of the current port
-			 */
+			 *
 			Connection c = p.getConnection();
 			
 			//remove from protocol
@@ -253,8 +250,17 @@ public class Controller {
 					if (sd != null && sd != p)
 						sd.getOwner().removePort(sd);
 				}
-			}
+			}*/
 		}
+		
+		// Remove from Links
+		LinkedList<Link> links = new LinkedList<Link>(toDelete.getLinks());
+		for (Link link : links)
+			removeSmartDeviceFromLink(toDelete, link);
+		links.clear();
+		// Remove Links from Device
+		toDelete.getLinks().clear();
+				
 		//Remove all ports from the device
 		toDelete.getPorts().clear();
 		model.getDevices().remove(toDelete);

+ 7 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Connection.java

@@ -60,6 +60,13 @@ public interface Connection {
 	 */
 	public Collection<Port> getParticipants();
 
+	/**
+	 * Returns the SmartDevices that are part of this connection, and the removed ones, which did not sent their last packages yet
+	 * 
+	 * @return SmartDevices participating in this connection, and the removed ones, which haven't sent their terminating packages
+	 */
+	public Collection<Port> getParticipantsAndRemoved();
+	
 	/**
 	 * Removes the SmartDevice from the Connection. Should create terminating
 	 * packages, that are returned on the next call of simulateTimeIntervall.<br> If

+ 6 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/ConnectionPerformance.java

@@ -65,6 +65,12 @@ public class ConnectionPerformance implements Connection {
 
 	@Override
 	public Collection<Port> getParticipants() {
+		LinkedList<Port> out = new LinkedList<Port>();
+		out.addAll(participants);
+		return out;
+	}
+	@Override
+	public Collection<Port> getParticipantsAndRemoved() {
 		LinkedList<Port> out = new LinkedList<Port>();
 		out.addAll(participants);
 		out.addAll(removedParticipants);

+ 5 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/simpleImplementation/SimpleConnection.java

@@ -127,6 +127,11 @@ public class SimpleConnection implements Connection {
 	public Collection<Port> getParticipants() {
 		return new LinkedList<Port>(Arrays.asList(source, destination));
 	}
+	
+	@Override
+	public Collection<Port> getParticipantsAndRemoved() {
+		return new LinkedList<Port>(Arrays.asList(source, destination));
+	}
 
 	@Override
 	public boolean removeSmartDevice(Port sd) {