private void addButtonMouseClicked(MouseEvent evt) {
   try {
     Node node = network.getNode(nodesetComboBox.getSelectedItem().toString());
     if (node.getUpCableSet().size() == 0) {
       nodesetModel.addElement(nodesetComboBox.getSelectedItem().toString());
       nodesetComboBox.setSelectedIndex(0);
       validate();
     } else {
       JOptionPane.showMessageDialog(
           this,
           "The node "
               + node.getIdentifier()
               + " cannot be deleted because it is connected to other nodes",
           "Error",
           JOptionPane.ERROR_MESSAGE);
     }
   } catch (CustomException e) {
   }
 }
Exemple #2
0
  private void doneButtonMouseClicked(MouseEvent evt) {
    LinkedList<Relation> relationlist = new LinkedList<Relation>();
    LinkedList<Object> nodelist = new LinkedList<Object>();

    try {
      for (int i = 0; i < relationNodesetTableModel.getRowCount(); i++) {
        Vector<Object> currentDataVector =
            (Vector<Object>) relationNodesetTableModel.getDataVector().elementAt(i);
        Relation relation = network.getRelation(currentDataVector.get(0).toString());

        String[] nodesetArray = currentDataVector.get(1).toString().split(",");
        if (!nodesetArray[0].isEmpty()) {
          for (int j = 0; j < nodesetArray.length; j++) {
            try {
              Node node = network.build(nodesetArray[j]);
              if (node != null) {
                nodelist.add(node);
                relationlist.add(relation);
                //								JOptionPane.showMessageDialog(this,
                //								"The node " + node.getIdentifier() + " was created successfully");
              }
            } catch (CustomException e) {
              //							JOptionPane.showMessageDialog(this,
              //					    			  "The node " + nodesetArray[j].toString() + "already exits",
              //					    			  "Error",
              //					    			  JOptionPane.ERROR_MESSAGE);
              nodelist.add(network.getNode(nodesetArray[j]));
              relationlist.add(relation);
            }
          }
        } else if (nodesetArray.length == 1
            && nodesetArray[0].isEmpty()
            && relation.getLimit() == 0) {
          nodelist.add(new NodeSet());
          relationlist.add(relation);
        } else {
          JOptionPane.showMessageDialog(
              this,
              "The relation " + relation.getName() + "has to have a node, its limit is not 0",
              "Error",
              JOptionPane.ERROR_MESSAGE);
          return;
        }
      }

      if (frame
          .getsNePSULPanel1()
          .getMenuDrivenCommands()
          .checkConsistency(relationlist, nodelist)) {
        try {
          Object[][] cableset = new Object[relationlist.size()][2];

          for (int i = 0; i < relationlist.size(); i++) {
            cableset[i][0] = relationlist.get(i);
            cableset[i][1] = nodelist.get(i);
          }

          CaseFrame caseframe =
              network.getCaseFrame(caseframeComboBox.getSelectedItem().toString());
          Node node = network.build(cableset, caseframe);
          nodes.add(node);
        } catch (CustomException e) {
          JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
      } else {
        JOptionPane.showMessageDialog(
            this,
            "The semantic classes of the given relations and nodes are inconsistent",
            "Error",
            JOptionPane.ERROR_MESSAGE);

        for (int i = 0; i < nodelist.size(); i++) {
          Object object = nodelist.get(i);
          if (object instanceof Node) {
            Node node = (Node) object;
            if (node.getUpCableSet().size() == 0) {
              network.removeNode(node);
            }
          } else if (object instanceof NodeSet) {
            break;
          }
        }
        return;
      }

    } catch (Exception e) {
    }

    relationNodesetTableModel.getDataVector().clear();

    frame.getNodesTreePanel1().initGUI();
    frame.getNodesTreePanel1().validate();
    frame.getNodesTreePanel1().repaint();

    if (windowFrame != null) {
      windowFrame.dispose();
    }
  }