Example #1
0
 /**
  * Return the change request to delete the given object.
  *
  * @param originator The originator of the change request.
  * @param object The object to be deleted.
  * @return The change request.
  */
 public static MoMLChangeRequest getDeletionChangeRequest(Object originator, NamedObj object) {
   String moml;
   if (object instanceof Attribute) {
     moml = "<deleteProperty name=\"" + object.getName() + "\"/>";
   } else if (object instanceof Entity) {
     moml = "<deleteEntity name=\"" + object.getName() + "\"/>";
   } else if (object instanceof Port) {
     moml = "<deletePort name=\"" + object.getName() + "\"/>";
   } else if (object instanceof Relation) {
     moml = "<deleteRelation name=\"" + object.getName() + "\"/>";
   } else {
     return null;
   }
   return new MoMLChangeRequest(originator, object.getContainer(), moml);
 }
Example #2
0
 /** Refreshes the visual properties of the TreeItem for this part. */
 protected void refreshVisuals() {
   if (getWidget() instanceof Tree) return;
   NamedObj model = getNamedObjectModel();
   // Set Image
   if (model instanceof Director)
     setWidgetImage(DirectorEditPart.IMAGE_DESCRIPTOR_DIRECTOR, model);
   else if (model instanceof Parameter)
     setWidgetImage(ActorEditPart.IMAGE_DESCRIPTOR_PARAMETER, model);
   else if (model instanceof IOPort) {
     IOPort port = (IOPort) model;
     if (port.isInput()) setWidgetImage(ActorEditPart.IMAGE_DESCRIPTOR_INPUTPORT, model);
     else setWidgetImage(ActorEditPart.IMAGE_DESCRIPTOR_OUTPUTPORT, model);
   } else if (model instanceof TypedAtomicActor) {
     setWidgetImage(ActorEditPart.IMAGE_DESCRIPTOR_ACTOR, model);
   } else if (model instanceof CompositeActor) {
     setWidgetImage(PaletteBuilder.getInstance().getIcon(model.getClass()), model);
   }
   // Set Text
   if (model instanceof Parameter) {
     Parameter param = (Parameter) model;
     String name = param.getName();
     String value = param.getExpression();
     setWidgetText(name + "=" + (value == null ? "" : value));
   } else setWidgetText(model.getName());
 }
  /**
   * Get the change request to update the object in the host model.
   *
   * @param pattern The pattern of the transformation rule.
   * @param replacement The replacement of the transformation rule.
   * @param matchResult The match result.
   * @param patternObject The object in the pattern, or null.
   * @param replacementObject The object in the replacement that corresponds to the object in the
   *     pattern.
   * @param hostObject The object in the host model corresponding to the object in the replacement.
   * @return The change request.
   * @exception IllegalActionException If error occurs in generating the change request.
   */
  @Override
  public ChangeRequest getChangeRequest(
      Pattern pattern,
      Replacement replacement,
      MatchResult matchResult,
      NamedObj patternObject,
      NamedObj replacementObject,
      NamedObj hostObject)
      throws IllegalActionException {
    if (_valueParseTree == null) {
      _reparse();
    }

    ParserScope scope = NamedObjVariable.getNamedObjVariable(hostObject, true).getParserScope();
    GTParameter.Evaluator evaluator = new GTParameter.Evaluator(pattern, matchResult);

    String name;
    if (_valueParseTree instanceof ASTPtSumNode) {
      StringBuffer buffer = new StringBuffer();
      for (int i = 0; i < _valueParseTree.jjtGetNumChildren(); i++) {
        ASTPtRootNode child = (ASTPtRootNode) _valueParseTree.jjtGetChild(i);
        if (!(child.isConstant() && child.getToken() instanceof StringToken)) {
          ASTPtLeafNode newNode = _evaluate(child, evaluator, scope);
          buffer.append(_parseTreeWriter.parseTreeToExpression(newNode));
        } else {
          buffer.append(((StringToken) child.getToken()).stringValue());
        }
      }
      name = buffer.toString();
    } else if (!(_valueParseTree.isConstant()
        && _valueParseTree.getToken() instanceof StringToken)) {
      ASTPtRootNode newRoot = _evaluate(_valueParseTree, evaluator, scope);
      name = _parseTreeWriter.parseTreeToExpression(newRoot);
    } else {
      name = _name.get();
    }

    NamedObj parent = hostObject.getContainer();
    String moml =
        "<entity name=\"" + hostObject.getName() + "\"><rename name=\"" + name + "\"/></entity>";
    return new MoMLChangeRequest(this, parent, moml, null);
  }
Example #4
0
  /**
   * Description of the Method
   *
   * @exception IllegalActionException Description of the Exception
   */
  private void buildResultTree(EntityLibrary newRoot) throws IllegalActionException {
    if (isDebugging) log.debug("buildResultTree()");

    // iterate over each treepath in results
    for (int i = 0; i < results.size(); i++) {

      try {

        TreePath currentPath = results.getTreePath(i);
        if (isDebugging) log.debug(currentPath);

        EntityLibrary treeCurrent = newRoot;
        for (int j = 1; j < currentPath.getPathCount(); j++) {

          NamedObj pathCurrent = (NamedObj) currentPath.getPathComponent(j);

          if (pathCurrent instanceof EntityLibrary) {

            List<EntityLibrary> children = treeCurrent.entityList(EntityLibrary.class);

            boolean alreadyThere = false;
            for (EntityLibrary child : children) {
              if (isDebugging) log.debug(child.getName());
              if (child.getName().equals(pathCurrent.getName())) {
                // this EntityLibrary is already there
                treeCurrent = child;
                alreadyThere = true;
                break;
              }
            }
            if (!alreadyThere) {
              // create it
              EntityLibrary newEntity = copyEntityLibrary((EntityLibrary) pathCurrent);
              setContainer(treeCurrent, newEntity);
              treeCurrent = newEntity;
            }

          } else {
            List<NamedObj> children = treeCurrent.entityList(NamedObj.class);

            boolean alreadyThere = false;
            for (NamedObj child : children) {
              if (child.getName().equals(pathCurrent.getName())) {
                // this NamedObj is already there
                alreadyThere = true;
                break;
              }
            }
            if (!alreadyThere) {
              // create it
              NamedObj newEntity = cloneEntity((NamedObj) pathCurrent);
              setContainer(treeCurrent, newEntity);
              // Leaf node, all done
              break;
            }
          }
        }

      } catch (IllegalActionException iae) {
        throw new IllegalActionException("cannot build search result tree: " + iae);
      } catch (NameDuplicationException nde) {
        log.error("EXCEPTION CAUGHT: " + nde.getMessage());
      } catch (Exception e) {
        log.error("EXCEPTION CAUGHT: " + e.getMessage());
      }
    } // end for loop
  }
Example #5
0
 /**
  * Get the unique string description containing the type and name of the\ object within the given
  * container.
  *
  * @param object The object.
  * @param topContainer The container used as the top level.
  * @return The description.
  * @see #getObjectFromCode(String, NamedObj)
  */
 public static String getCodeFromObject(NamedObj object, NamedObj topContainer) {
   String replacementAbbrev = getObjectTypeAbbreviation(object);
   String name = topContainer == null ? object.getName() : object.getName(topContainer);
   return replacementAbbrev + name;
 }
Example #6
0
  /**
   * Queue a change request to alter the value of the attribute attached to the specified entry, if
   * there is one. This method is called whenever an entry has been changed. If no attribute is
   * attached to the specified entry, then do nothing.
   *
   * @param name The name of the entry that has changed.
   */
  public void changed(final String name) {
    // Check if the entry that changed is in the mapping.
    if (_attributes.containsKey(name)) {
      final Settable attribute = (Settable) (_attributes.get(name));

      if (attribute == null) {
        // No associated attribute.
        return;
      }

      ChangeRequest request;

      if (attribute instanceof PasswordAttribute) {
        // Passwords have to be handled specially because the password
        // is not represented in a string.
        request =
            new ChangeRequest(this, name) {
              protected void _execute() throws IllegalActionException {
                char[] password = getCharArrayValue(name);
                ((PasswordAttribute) attribute).setPassword(password);
                attribute.validate();

                Iterator<?> derived = ((PasswordAttribute) attribute).getDerivedList().iterator();

                while (derived.hasNext()) {
                  PasswordAttribute derivedPassword = (PasswordAttribute) derived.next();
                  derivedPassword.setPassword(password);
                }
              }
            };
      } else if (attribute instanceof NamedObj) {
        // NOTE: We must use a MoMLChangeRequest so that changes
        // propagate to any objects that have been instantiating
        // using this one as a class.  This is only an issue if
        // attribute is a NamedObj.
        NamedObj castAttribute = (NamedObj) attribute;

        String stringValue = getStringValue(name);

        // If the attribute is a DoubleRangeParameter, then we
        // have to translate the integer value returned by the
        // JSlider into a double.
        if (attribute instanceof DoubleRangeParameter) {
          try {
            int newValue = Integer.parseInt(stringValue);
            int precision =
                ((IntToken) ((DoubleRangeParameter) attribute).precision.getToken()).intValue();
            double max =
                ((DoubleToken) ((DoubleRangeParameter) attribute).max.getToken()).doubleValue();
            double min =
                ((DoubleToken) ((DoubleRangeParameter) attribute).min.getToken()).doubleValue();
            double newValueAsDouble = min + (((max - min) * newValue) / precision);
            stringValue = "" + newValueAsDouble;
          } catch (IllegalActionException e) {
            throw new InternalErrorException(e);
          }
        }

        // The context for the MoML should be the first container
        // above this attribute in the hierarchy that defers its
        // MoML definition, or the immediate parent if there is none.
        NamedObj parent = castAttribute.getContainer();
        String moml =
            "<property name=\""
                + castAttribute.getName()
                + "\" value=\""
                + StringUtilities.escapeForXML(stringValue)
                + "\"/>";
        request =
            new MoMLChangeRequest(
                this, // originator
                parent, // context
                moml, // MoML code
                null) { // base
              protected void _execute() throws Exception {
                synchronized (PtolemyQuery.this) {
                  try {
                    _ignoreChangeNotifications = true;
                    super._execute();
                  } finally {
                    _ignoreChangeNotifications = false;
                  }
                }
              }
            };
      } else {
        // If the attribute is not a NamedObj, then we
        // set its value directly.
        request =
            new ChangeRequest(this, name) {
              protected void _execute() throws IllegalActionException {
                attribute.setExpression(getStringValue(name));

                attribute.validate();

                /* NOTE: Earlier version:
                // Here, we need to handle instances of Variable
                // specially.  This is too bad...
                if (attribute instanceof Variable) {

                // Will this ever happen?  A
                // Variable that is not a NamedObj???
                // Retrieve the token to force
                // evaluation, so as to check the
                // validity of the new value.

                ((Variable)attribute).getToken();
                }
                */
              }
            };
      }

      // NOTE: This object is never removed as a listener from
      // the change request.  This is OK because this query will
      // be closed at some point, and all references to it will
      // disappear, and thus both it and the change request should
      // become accessible to the garbage collector.  However, I
      // don't quite trust Java to do this right, since it's not
      // completely clear that it releases resources when windows
      // are closed.  It would be better if this listener were
      // a weak reference.
      // NOTE: This appears to be unnecessary, since we register
      // as a change listener on the handler.  This results in
      // two notifications.  EAL 9/15/02.
      request.addChangeListener(this);

      if (_handler == null) {
        request.execute();
      } else {
        if (request instanceof MoMLChangeRequest) {
          ((MoMLChangeRequest) request).setUndoable(true);
        }

        // Remove the error handler so that this class handles
        // the error through the notification.  Save the previous
        // error handler to restore after this request has been
        // processes.
        _savedErrorHandler = MoMLParser.getErrorHandler();
        MoMLParser.setErrorHandler(null);
        _handler.requestChange(request);
      }
    }
  }
Example #7
0
 /**
  * Provide a title area attribute to the specified web exporter to be included in a web page for
  * the container of this object.
  *
  * @param exporter The exporter.
  * @param object The object.
  * @throws IllegalActionException If evaluating the value of this parameter fails.
  */
 protected void _provideOutsideContent(WebExporter exporter, NamedObj object)
     throws IllegalActionException {
   if (object != null) {
     exporter.defineAreaAttribute(object, "title", object.getName(), true);
   }
 }