Example #1
0
 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) {
   }
 }
Example #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();
    }
  }
Example #3
0
  private void optionsComboBoxActionPerformed(ActionEvent e) {
    try {
      final int rowNumber = relationNodesetTable.getSelectedRow();
      TableCellEditor cell = relationNodesetTable.getCellEditor(rowNumber, 2);

      if (cell.getCellEditorValue().equals("Base Node")) {
        String nodeName =
            (String)
                JOptionPane.showInputDialog(
                    getRootPane(),
                    "Enter the name of the node:",
                    "Create a Node",
                    JOptionPane.PLAIN_MESSAGE);
        if (nodeName != null) {
          String currentNodesetValue =
              relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

          if (currentNodesetValue.isEmpty()) {
            relationNodesetTableModel.setValueAt(nodeName, rowNumber, 1);
          } else {
            relationNodesetTableModel.setValueAt(
                currentNodesetValue + ", " + nodeName, rowNumber, 1);
          }
        }

      } else if (cell.getCellEditorValue().equals("Variable Node")) {
        Node varNode = network.buildVariableNode();

        String currentNodesetValue = relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

        if (currentNodesetValue.isEmpty()) {
          relationNodesetTableModel.setValueAt(varNode.getIdentifier(), rowNumber, 1);
        } else {
          relationNodesetTableModel.setValueAt(
              currentNodesetValue + ", " + varNode.getIdentifier(), rowNumber, 1);
        }
      } else if (cell.getCellEditorValue().equals("build")) {

        JFrame popupFrame = new JFrame("build");
        popupFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        final cmdBuild buildPanel = new cmdBuild(network, frame, popupFrame);
        popupFrame.getContentPane().add(buildPanel);
        popupFrame.pack();
        popupFrame.setVisible(true);
        Point point = frame.getsNePSULPanel1().getMenuDrivenCommands().cascadePosition();
        popupFrame.setLocation(point);
        doneButton.setEnabled(false);
        popupFrame.addWindowListener(
            new WindowAdapter() {

              @Override
              public void windowClosed(WindowEvent e) {
                LinkedList<Node> nodes = buildPanel.getNodes();
                if (nodes.size() != 0) {
                  for (Node item : nodes) {

                    String currentNodesetValue =
                        relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

                    if (currentNodesetValue.isEmpty()) {
                      relationNodesetTableModel.setValueAt(item.getIdentifier(), rowNumber, 1);
                    } else {
                      relationNodesetTableModel.setValueAt(
                          currentNodesetValue + ", " + item.getIdentifier(), rowNumber, 1);
                    }
                  }
                }

                frame.getsNePSULPanel1().getMenuDrivenCommands().cascadeBack();
                doneButton.setEnabled(true);
              }
            });

      } else if (cell.getCellEditorValue().equals("assert")) {
        JFrame popupFrame = new JFrame("assert");
        popupFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        final cmdAssert assertPanel = new cmdAssert(network, frame, popupFrame);
        popupFrame.getContentPane().add(assertPanel);
        popupFrame.pack();
        popupFrame.setVisible(true);
        Point point = frame.getsNePSULPanel1().getMenuDrivenCommands().cascadePosition();
        popupFrame.setLocation(point);
        doneButton.setEnabled(false);
        popupFrame.addWindowListener(
            new WindowAdapter() {

              @Override
              public void windowClosed(WindowEvent e) {
                LinkedList<Node> nodes = assertPanel.getNodes();
                if (nodes.size() != 0) {
                  for (Node item : nodes) {

                    String currentNodesetValue =
                        relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

                    if (currentNodesetValue.isEmpty()) {
                      relationNodesetTableModel.setValueAt(item.getIdentifier(), rowNumber, 1);
                    } else {
                      relationNodesetTableModel.setValueAt(
                          currentNodesetValue + ", " + item.getIdentifier(), rowNumber, 1);
                    }
                  }
                }

                frame.getsNePSULPanel1().getMenuDrivenCommands().cascadeBack();
                doneButton.setEnabled(true);
              }
            });

      } else if (cell.getCellEditorValue().equals("find")) {
        JFrame popupFrame = new JFrame("find");
        popupFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        final cmdFind findPanel = new cmdFind(network, frame, popupFrame);
        popupFrame.getContentPane().add(findPanel);
        popupFrame.pack();
        popupFrame.setVisible(true);
        Point point = frame.getsNePSULPanel1().getMenuDrivenCommands().cascadePosition();
        popupFrame.setLocation(point);
        doneButton.setEnabled(false);
        popupFrame.addWindowListener(
            new WindowAdapter() {

              @Override
              public void windowClosed(WindowEvent e) {
                LinkedList<Node> nodes = findPanel.getNodes();
                if (nodes.size() != 0) {
                  for (Node item : nodes) {

                    String currentNodesetValue =
                        relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

                    if (currentNodesetValue.isEmpty()) {
                      relationNodesetTableModel.setValueAt(item.getIdentifier(), rowNumber, 1);
                    } else {
                      relationNodesetTableModel.setValueAt(
                          currentNodesetValue + ", " + item.getIdentifier(), rowNumber, 1);
                    }
                  }
                }

                frame.getsNePSULPanel1().getMenuDrivenCommands().cascadeBack();
                doneButton.setEnabled(true);
              }
            });
      } else if (cell.getCellEditorValue().equals("Existing Node")) {
        Node node = frame.getsNePSULPanel1().getMenuDrivenCommands().existingNodes();
        if (node != null) {
          String currentNodesetValue =
              relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

          if (currentNodesetValue.isEmpty()) {
            relationNodesetTableModel.setValueAt(node.getIdentifier(), rowNumber, 1);
          } else {
            relationNodesetTableModel.setValueAt(
                currentNodesetValue + ", " + node.getIdentifier(), rowNumber, 1);
          }
        }
      } else if (cell.getCellEditorValue().equals("Act Node")) {
        frame
            .getsNePSULPanel1()
            .getMenuDrivenCommands()
            .actNodes(this, relationNodesetTable, doneButton, relationNodesetTableModel);
      }
      relationNodesetTable.setValueAt(options.getItemAt(0), rowNumber, 2);
      validate();
    } catch (Exception e1) {
    }
  }