示例#1
0
    /** Perform the action. */
    public void actionPerformed(ActionEvent e) {
      super.actionPerformed(e);
      // Dialog to ask for a case name.
      Query query = new Query();
      List refinements = _case.entityList(Refinement.class);
      if (refinements.size() < 2) {
        MessageHandler.error("No cases to remove.");
      } else {
        String[] caseNames = new String[refinements.size() - 1];
        Iterator cases = refinements.iterator();
        int i = 0;
        while (cases.hasNext()) {
          String name = ((Nameable) cases.next()).getName();
          if (!name.equals("default")) {
            caseNames[i] = name;
            i++;
          }
        }
        query.addChoice("case", "Remove case", caseNames, caseNames[0]);
        ComponentDialog dialog = new ComponentDialog(CaseGraphFrame.this, "Remove Case", query);
        if (dialog.buttonPressed().equals("OK")) {
          final String name = query.getStringValue("case");
          String moml = "<deleteEntity name=\"" + StringUtilities.escapeForXML(name) + "\"/>";

          // The following is, regrettably, copied from ModalTransitionController.
          MoMLChangeRequest change =
              new MoMLChangeRequest(this, _case, moml) {
                protected void _execute() throws Exception {
                  super._execute();
                  // Find the tabbed pane that matches the name and remove it.
                  int count = _tabbedPane.getTabCount();
                  for (int i = 0; i < count; i++) {
                    if (name.equals(_tabbedPane.getTitleAt(i))) {
                      _tabbedPane.remove(i);
                      break;
                    }
                  }
                }
              };
          _case.requestChange(change);
        }
      }
    }
示例#2
0
    /** Perform the action. */
    public void actionPerformed(ActionEvent e) {
      super.actionPerformed(e);
      // Dialog to ask for a case name.
      Query query = new Query();
      query.addLine("case", "Pattern that the control input must match", "");
      ComponentDialog dialog = new ComponentDialog(CaseGraphFrame.this, "Add Case", query);
      if (dialog.buttonPressed().equals("OK")) {
        final String pattern = query.getStringValue("case");
        // NOTE: We do not use a TransitionRefinement because we don't
        // want the sibling input ports that come with output ports.
        String moml =
            "<entity name=\""
                + StringUtilities.escapeForXML(pattern)
                + "\" class=\""
                + _case.refinementClassName()
                + "\"/>";

        // The following is, regrettably, copied from ModalTransitionController.
        MoMLChangeRequest change =
            new MoMLChangeRequest(this, _case, moml) {
              protected void _execute() throws Exception {
                super._execute();

                // Mirror the ports of the container in the refinement.
                // Note that this is done here rather than as part of
                // the MoML because we have set protected variables
                // in the refinement to prevent it from trying to again
                // mirror the changes in the container.
                Refinement entity = (Refinement) _case.getEntity(pattern);

                // Get the initial port configuration from the container.
                Iterator ports = _case.portList().iterator();

                while (ports.hasNext()) {
                  Port port = (Port) ports.next();
                  // No need to mirror the control port, as it's a PortParameter.
                  // Hence, its value is available as a parameter.
                  if (port == _case.control.getPort()) {
                    continue;
                  }

                  try {
                    entity.setMirrorDisable(true);
                    Port newPort = entity.newPort(port.getName());
                    if (newPort instanceof RefinementPort && port instanceof IOPort) {
                      try {
                        ((RefinementPort) newPort).setMirrorDisable(true);

                        if (((IOPort) port).isInput()) {
                          ((RefinementPort) newPort).setInput(true);
                        }

                        if (((IOPort) port).isOutput()) {
                          ((RefinementPort) newPort).setOutput(true);
                        }

                        if (((IOPort) port).isMultiport()) {
                          ((RefinementPort) newPort).setMultiport(true);
                        }
                      } finally {
                        ((RefinementPort) newPort).setMirrorDisable(false);
                      }
                    }
                  } finally {
                    entity.setMirrorDisable(false);
                  }
                }
                _addTabbedPane(entity, true);
              }
            };

        _case.requestChange(change);
      }
    }