private static VBox createHUBPopOverContent(HUB hubObject, Pane canvas, ContextMenu contextMenu) { // this content container is everything that is going to go on the // PopOver VBox content = new VBox(5); content.getStyleClass().add("popover-content"); content.setId("contentPane"); // the first row contains the big label and the toggle button addHeader(hubObject.getName(), controller.MyController.btnEdit, 25, content); // just a line separator Separator hr = new Separator(Orientation.HORIZONTAL); hr.minWidth(Control.USE_COMPUTED_SIZE); content.getChildren().add(hr); // the first row of the form (Hub name) addRow("Name: ", hubObject.getName(), 15, content, false); // Here is the same layout as row 1 (Hub subnet) addRow("Subnet:", hubObject.getSubnet(), 15, content, false); // Row 3 (Hub netmask) addRow("Netmask:", hubObject.getNetmask(), 15, content, false); // this will dynamically add rows to the formPane base on the # of inf // entries for (String inf : hubObject.getInfs()) { addRow("Inf:", inf, 15, content, false); } hubBtnListener(content, hubObject, canvas, contextMenu); addButtonRow("Add Interfaces", content, "hub"); return content; }
private static void hubNodeHidingListener( PopOver popover, HUB hubObject, Pane canvas, ContextMenu contextMenu) { try { // eveything in the popover VBox contentPane = (VBox) popover.getContentNode(); // find the header row HBox headerRow = (HBox) contentPane.getChildren().get(0); // find the toggle button ToggleButton toggleBtn = (ToggleButton) headerRow.getChildren().get(1); // the old key used to find the correlating vmObject HUB oldHub = hubObject; // only update with it's not in edit mode if (!toggleBtn.isSelected()) { HUB newHubObject = new HUB(); TreeSet<String> newInterfaces = new TreeSet<String>(); for (Node row : contentPane.getChildren()) { if (row instanceof HBox) { ObservableList<Node> childNode = ((HBox) row).getChildren(); for (int i = 0; i < childNode.size(); i++) { if (childNode.get(i) instanceof Label) { if (((Label) childNode.get(i)).getText().matches("Name.*")) { String hubName = ((TextField) childNode.get(i + 1)).getText(); // only validate name if it's different than // the current one if (!oldHub.getName().equals(hubName)) { // make sure name input is a valid name if (Validator.validateName(hubName)) { newHubObject.setName(hubName); } else { // if input is not valid, warn user // and keep the old one creatAlert(((Label) childNode.get(i)).getText(), "HUB"); newHubObject.setName(oldHub.getName()); } } else { // set it to old name if it did not // change newHubObject.setName(oldHub.getName()); } // same general idea goes for the rest of // the labels // if input is different // then test it's validation before making // changes // if it's not valid then warn the user // else just set it to the old one } else if (((Label) childNode.get(i)).getText().matches("Subnet.*")) { String hubSubnet = ((TextField) childNode.get(i + 1)).getText(); if (!oldHub.getSubnet().equals(hubSubnet)) { if (Validator.validateIp(hubSubnet)) { newHubObject.setSubnet(hubSubnet); } else { creatAlert(((Label) childNode.get(i)).getText(), "HUB"); newHubObject.setSubnet(oldHub.getSubnet()); } } else { newHubObject.setSubnet(oldHub.getSubnet()); } } else if (((Label) childNode.get(i)).getText().matches("Netmask.*")) { String hubNetmask = ((TextField) childNode.get(i + 1)).getText(); if (Validator.validateNetmask(hubNetmask)) { newHubObject.setNetmask(hubNetmask); } else { creatAlert(((Label) childNode.get(i)).getText(), "HUB"); newHubObject.setNetmask(oldHub.getNetmask()); } } else if (((Label) childNode.get(i)).getText().matches("Inf.*")) { String infValue = ((TextField) childNode.get(i + 1)).getText(); // if field is not empty if (!infValue.isEmpty()) { // if the interface is not in the old // ones if (!oldHub.getInfs().contains(infValue)) { String hubNetmask = null; if (!hubObject.getSubnet().equals(hubNetmask)) { hubNetmask = newHubObject.getNetmask(); } else { hubNetmask = oldHub.getNetmask(); } // if new inf value is valid then // insert the new one if (Validator.validateHubInf(infValue) && Validator.validateSubnetting( newHubObject.getNetmask(), infValue, newHubObject.getSubnet())) { newInterfaces.add(infValue); } else { creatAlert("Inf.", "HUB"); } } else { newInterfaces.add(infValue); } } } } } } } newHubObject.setInfs(newInterfaces); Data.hubMap.replace(oldHub.getName(), newHubObject); // here we don't want to simply delete old entry because of the // coordinates // so we update the key to a different key if they change the // Hub Object name LinkedHashMap<String, HUB> updatedMap = Data.replaceHUBKey(Data.hubMap, oldHub.getName(), newHubObject.getName()); Data.hubMap = updatedMap; draw(canvas, contextMenu); } } catch (IndexOutOfBoundsException e) { System.out.println("Something went wrong"); } }