|
@@ -120,8 +120,7 @@ public class ConnectionCreationPanel extends JScrollPane {
|
|
|
public ConnectionCreationPanel(Collection<Port> ports, Link l,
|
|
|
Controller controller) {
|
|
|
this.controller = controller;
|
|
|
- connection = new ConnectionImplementation(l, new SimpleProtocol(null,
|
|
|
- null));
|
|
|
+ connection = new ConnectionImplementation(l, new SimpleProtocol());
|
|
|
this.ports = new Port[ports.size()];
|
|
|
int i = 0;
|
|
|
for (Port d : ports) {
|
|
@@ -188,8 +187,11 @@ public class ConnectionCreationPanel extends JScrollPane {
|
|
|
// Set Index to selected Protocol
|
|
|
for (int i = 0; i < availableProtocols.size(); i++)
|
|
|
if (connection.getProtocol().getClass()
|
|
|
- .equals(availableProtocols.get(i)))
|
|
|
+ .equals(availableProtocols.get(i))){
|
|
|
+ //Select the right protocol and save last index
|
|
|
cmbLinkType.setSelectedIndex(i);
|
|
|
+ lastIndex = i;
|
|
|
+ }
|
|
|
|
|
|
// Add Functionality for changing protocol
|
|
|
cmbLinkType.addActionListener(new ActionListener() {
|
|
@@ -217,7 +219,7 @@ public class ConnectionCreationPanel extends JScrollPane {
|
|
|
cmbLinkType.setSelectedIndex(lastIndex);
|
|
|
System.out
|
|
|
.println("WARNING: Invalid Protocol Selected - restore last index");
|
|
|
- } else {
|
|
|
+ } else if(connection.setProtocol(newProtocol)){
|
|
|
/**
|
|
|
* New Roles as Strings
|
|
|
*/
|
|
@@ -228,6 +230,10 @@ public class ConnectionCreationPanel extends JScrollPane {
|
|
|
int oldDisconnected = oldProtocol.getNumberOfRoles();
|
|
|
//Update to new disconnected Index
|
|
|
disconnectedIndex = newProtocol.getNumberOfRoles();
|
|
|
+ //Update Protocol
|
|
|
+
|
|
|
+ // Update lastIndex to new Index
|
|
|
+ lastIndex = cmbLinkType.getSelectedIndex();
|
|
|
//Update Boxes
|
|
|
for (int i = 0; i < boxes.length; i++) {
|
|
|
/**
|
|
@@ -243,22 +249,21 @@ public class ConnectionCreationPanel extends JScrollPane {
|
|
|
if (oldSelected < 0 || oldSelected >= disconnectedIndex
|
|
|
|| oldSelected == oldDisconnected) {
|
|
|
//Invalid Index -> Disconnected
|
|
|
+ controller.removeDeviceFromConnection(ports[i], connection);
|
|
|
boxes[i].setSelectedIndex(disconnectedIndex);
|
|
|
} else {
|
|
|
- if (newProtocol.addDeviceOfRole(ports[i],
|
|
|
- oldSelected)) {
|
|
|
+ if (controller.addDeviceToConnection(ports[i], connection, oldSelected)){
|
|
|
//Set to Box to display role
|
|
|
boxes[i].setSelectedIndex(oldSelected);
|
|
|
} else {
|
|
|
//Could not be added -> Disconnected
|
|
|
+ controller.removeDeviceFromConnection(ports[i], connection);
|
|
|
boxes[i].setSelectedIndex(disconnectedIndex);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // Update all Boxes, Roles etc.
|
|
|
- connection.setProtocol(newProtocol);
|
|
|
- // Update lastIndex to new Index
|
|
|
- lastIndex = cmbLinkType.getSelectedIndex();
|
|
|
+ } else {
|
|
|
+ cmbLinkType.setSelectedIndex(lastIndex);
|
|
|
}
|
|
|
//Set Mutex back to false - allow changes
|
|
|
protocolChange = false;
|
|
@@ -394,16 +399,17 @@ public class ConnectionCreationPanel extends JScrollPane {
|
|
|
int n = 5;
|
|
|
for(int j = 0; j <= n; j++){
|
|
|
if(j == 0){//Try to add Router first
|
|
|
- if(connection.getProtocol().addDeviceOfRole(currentPort, 0)){
|
|
|
+ if(controller.addDeviceToConnection(currentPort, connection, 0)){
|
|
|
boxes[pos].setSelectedIndex(0);
|
|
|
break;
|
|
|
}
|
|
|
}else if(j == n){//If it could not be added
|
|
|
boxes[pos].setSelectedIndex(disconnectedIndex);
|
|
|
+ controller.removeDeviceFromConnection(currentPort, connection);
|
|
|
break;
|
|
|
}else{
|
|
|
int randomRole = ThreadLocalRandom.current().nextInt(0, disconnectedIndex);
|
|
|
- if(connection.getProtocol().addDeviceOfRole(currentPort, randomRole)){
|
|
|
+ if(controller.addDeviceToConnection(currentPort, connection, randomRole)){
|
|
|
boxes[pos].setSelectedIndex(randomRole);
|
|
|
break;
|
|
|
}
|
|
@@ -424,7 +430,7 @@ public class ConnectionCreationPanel extends JScrollPane {
|
|
|
/**
|
|
|
* True if role was successfully changed
|
|
|
*/
|
|
|
- boolean successfullChange = controller.changeRoleOfDevice(connection.getProtocol(),
|
|
|
+ boolean successfullChange = controller.changeRoleOfDevice(connection.getProtocol(),connection,
|
|
|
ports[pos], selected);
|
|
|
/**
|
|
|
* Set to Disconnected, if role could not be changed
|