示例#1
0
  private static VBox createVMPopOverContent(VM vmObject, 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(vmObject.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 (VM name)
    // each row of the form contains a label and a Textfield
    addRow("Name: ", vmObject.getName(), 15, content, false);

    addRow("OS:", vmObject.getOs(), 15, content, false);

    // Row 3 (VM ver)
    addRow("Ver:", vmObject.getVer().toString(), 15, content, false);

    // Row 4 (VM src)
    addRow("Src:", vmObject.getSrc(), 15, content, false);

    for (Map.Entry<String, String> entry : vmObject.getInterfaces().entrySet()) {
      String key = entry.getKey();
      String value = entry.getValue();

      addRow(key, value, 15, content, false);
    }
    vmBtnListener(content, vmObject, canvas, contextMenu);
    addButtonRow("Add Interfaces", content, "vm");
    return content;
  }
示例#2
0
  private static void vmNodeHidingListener(
      PopOver popover, VM vmObject, 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
      VM oldVM = vmObject;

      // only update with it's not in edit mode
      if (!toggleBtn.isSelected()) {
        VM newVmObject = new VM();
        TreeMap<String, String> newInterfaces = new TreeMap<String, 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 vmName = ((TextField) childNode.get(i + 1)).getText();
                  // only validate name if it's different than
                  // the current one
                  if (!oldVM.getName().equals(vmName)) {
                    // make sure name input is a valid name
                    if (Validator.validateName(vmName)) {
                      newVmObject.setName(vmName);
                    } else {
                      // if input is not valid, warn user
                      // and keep the old one
                      creatAlert(((Label) childNode.get(i)).getText(), "VM");
                      newVmObject.setName(oldVM.getName());
                    }
                  } else {
                    // set it to old name if it did not
                    // change
                    newVmObject.setName(oldVM.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("OS.*")) {
                  String vmOs = ((TextField) childNode.get(i + 1)).getText();
                  if (Validator.validateOs(vmOs)) {
                    newVmObject.setOs(vmOs);
                  } else {
                    creatAlert(((Label) childNode.get(i)).getText(), "VM");
                    newVmObject.setOs(oldVM.getOs());
                  }
                } else if (((Label) childNode.get(i)).getText().matches("Ver.*")) {
                  String vmVer = ((TextField) childNode.get(i + 1)).getText();
                  if (Validator.validateVer(vmVer)) {
                    newVmObject.setVer(Double.parseDouble(vmVer));
                  } else {
                    creatAlert(((Label) childNode.get(i)).getText(), "VM");
                    newVmObject.setVer(oldVM.getVer());
                  }
                } else if (((Label) childNode.get(i)).getText().matches("Src.*")) {
                  String vmSrc = ((TextField) childNode.get(i + 1)).getText();
                  if (Validator.validateSrc(vmSrc)) {
                    newVmObject.setSrc(vmSrc);
                  } else {
                    creatAlert(((Label) childNode.get(i)).getText(), "VM");
                    newVmObject.setSrc(oldVM.getSrc());
                  }
                } else if (((Label) childNode.get(i)).getText().matches("(\\w+?).(\\w+?\\d+?.*)")) {
                  String ipLabel = ((Label) childNode.get(i)).getText();
                  String vmIp = ((TextField) childNode.get(i + 1)).getText().trim();
                  // does the eth# interface already exist?
                  if (oldVM.getInterfaces().containsKey(ipLabel)) {
                    // is the new ip value equal to the old
                    // one
                    if (!oldVM.getInterfaces().get(ipLabel).equals(vmIp)) {
                      // if it's a new ip, validate and
                      // set it
                      if (Validator.validateIp(vmIp)) {
                        newInterfaces.put(ipLabel, vmIp);
                      } else {
                        // if not, alert user and set to
                        // old ip
                        creatAlert(ipLabel, "VM");
                        newInterfaces.put(ipLabel, oldVM.getInterfaces().get(ipLabel));
                      }
                    } else {
                      // if ip value didn't change just
                      // set to old value
                      newInterfaces.put(ipLabel, oldVM.getInterfaces().get(ipLabel));
                    }
                  } else {
                    // if that eth# doesn't exist yet
                    // validate it and set it
                    // only set the new eth# if the new ip
                    // value is valid
                    if (!vmIp.isEmpty()) {
                      if (Validator.validateIp(vmIp)) {
                        newInterfaces.put(ipLabel, vmIp);
                      } else {
                        // tell user there was an error
                        // and don't insert the new eth#
                        // interface
                        creatAlert(ipLabel, "VM");
                      }
                    }
                  }
                }
              }
            }
          }
        }
        newVmObject.setInterfaces(newInterfaces);
        Data.vmMap.replace(oldVM.getName(), newVmObject);
        // 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 VM
        // Object name
        LinkedHashMap<String, VM> updatedMap =
            Data.replaceVMKey(Data.vmMap, oldVM.getName(), newVmObject.getName());
        Data.vmMap = updatedMap;
        draw(canvas, contextMenu);
      }
    } catch (IndexOutOfBoundsException e) {
      System.out.println("Something went Wrong");
    }
  }
示例#3
0
  public static void draw(Pane canvas, ContextMenu contextMenu) {
    System.out.println("Number of Vm's Present " + application.Data.vmMap.keySet().size());
    System.out.println("Number of Hub's Present " + application.Data.hubMap.keySet().size());
    // the pane should be cleared each time
    canvas.getChildren().clear();

    // if(!Data.vmMap.isEmpty() && !Data.hubMap.isEmpty()) {
    // if(!(Data.hubMap.size() == 0)) {
    canvas.getChildren().add(createVlanNode("V2", canvas, contextMenu));
    // }

    // we don't actually want to change the value of Data.hubStartPosY
    // instead we initially set our tempPosY to the startPos and alter that
    int tempPosX = Data.hubStartPosX;
    int tempPosY = Data.hubStartPosY;
    // Draw a Blue rectangle for each hub
    for (Map.Entry<String, HUB> hubEntry : application.Data.hubMap.entrySet()) {

      String currentHubName = hubEntry.getKey();
      HUB currentHub = application.Data.hubMap.get(currentHubName);
      currentHub.setPosX(tempPosX);
      currentHub.setPosY(tempPosY);
      canvas.getChildren().add(application.Graphics.createHUBNode(currentHub, canvas, contextMenu));
      // cashe wither the hub has connections
      // if it don't then theres no need to draw the lines
      boolean haveConnections = !currentHub.getInfs().isEmpty();
      // ----- Draws a horizontal line from the hub to the middle of the space
      // between hubs and vms
      if (haveConnections) {
        drawLine(canvas, tempPosX + 100, tempPosY + 50, tempPosX + 150, tempPosY + 50);
      }

      // Draw a Red rectangle for each vm
      tempPosX += 200;
      for (Map.Entry<String, VM> vmEntry : application.Data.vmMap.entrySet()) {
        String currentVMName = vmEntry.getKey();
        VM currentVM = application.Data.vmMap.get(currentVMName);
        for (Map.Entry<String, String> vmInterface : currentVM.getInterfaces().entrySet()) {
          // If the the first three octals of the vm's interface match
          // the first three octals of the hub's subnet
          // Draw the vm to the left of the hub as they are connected
          int ipClass = Data.getIPClass(application.Data.hubMap.get(currentHubName).getNetmask());
          String replaceRegex = "\\.\\d{1," + String.valueOf(ipClass) + "}\\z";
          if (vmInterface
              .getValue()
              .replaceAll(replaceRegex, "")
              .equals(
                  application.Data.hubMap
                      .get(currentHubName)
                      .getSubnet()
                      .replaceAll(replaceRegex, ""))) {
            application.Data.hubMap
                .get(currentHubName)
                .addInf(currentVM.getName() + "." + vmInterface.getKey());
            currentVM.setPosX(tempPosX);
            currentVM.setPosY(tempPosY);
            canvas
                .getChildren()
                .add(application.Graphics.createVMNode(currentVM, canvas, contextMenu));

            // draws a horizontal line from each vm to the middle of
            // the space between hubs and vms
            if (haveConnections) {
              drawLine(canvas, tempPosX, tempPosY + 50, tempPosX - 50, tempPosY + 50);
            }

            tempPosY += 150;
          }
        }
      }
      if (!haveConnections) {
        tempPosY += 150;
      }

      // draw vertical in the middle of the space between hubs and vms
      if (haveConnections) {
        drawLine(canvas, tempPosX - 50, currentHub.getPosY() + 50, tempPosX - 50, tempPosY - 100);
      }
      // draw horizontal line from the vlan to the hub
      drawLine(
          canvas,
          Data.vlanstartPosX + 100,
          currentHub.getPosY() + 50,
          currentHub.getPosX(),
          currentHub.getPosY() + 50);
      tempPosX += 200;
      // tempPosY += 150;
    }
  }