Exemple #1
0
 /**
  * Get the children of the given object. The children can be either attributes, ports, entities,
  * or relations if permitted by the arguments.
  *
  * @param object The object.
  * @param includeAttributes Whether the children can be attributes.
  * @param includePorts Whether the children can be ports.
  * @param includeEntities Whether the children can be entities.
  * @param includeRelations Whether the children can be relations.
  * @return The collection of children.
  */
 public static Collection<NamedObj> getChildren(
     NamedObj object,
     boolean includeAttributes,
     boolean includePorts,
     boolean includeEntities,
     boolean includeRelations) {
   Collection<NamedObj> collection = new CombinedCollection<NamedObj>();
   if (includeAttributes) {
     collection.addAll(object.attributeList());
   }
   if (includePorts && object instanceof Entity) {
     Entity entity = (Entity) object;
     collection.addAll(entity.portList());
   }
   if (object instanceof CompositeEntity) {
     CompositeEntity entity = (CompositeEntity) object;
     if (includeEntities) {
       collection.addAll(entity.entityList());
     }
     if (includeRelations) {
       collection.addAll(entity.relationList());
     }
   }
   return collection;
 }
  /**
   * Generate string of evaluated tokens of parameters of the agent.
   *
   * @param agent whether the parameters belong to.
   * @return string of evaluated parameters.
   */
  private String _agentParameterTokens(NamedObj agent) throws IllegalActionException {
    LinkedList parameterList = (LinkedList) agent.attributeList(Parameter.class);
    ListIterator parameters = parameterList.listIterator();

    String tokenString = "";

    while (parameters.hasNext()) {
      Parameter parameter = (Parameter) parameters.next();
      String parameterName = parameter.getName();

      if (parameterName.startsWith("_")) {
        continue;
      }

      String tokenValue = parameter.getToken().toString();

      if (tokenString == "") {
        tokenString += tokenValue;
      } else {
        tokenString += (", " + tokenValue);
      }
    }

    return tokenString;
  }
  /**
   * Generate string of parameters of the agent.
   *
   * @param agent whether the parameters belong to.
   * @param typed indicates whether the parameters have type.
   * @return string of parameters.
   */
  private String _agentParameters(NamedObj agent, boolean typed) {
    LinkedList parameterList = (LinkedList) agent.attributeList(Parameter.class);
    ListIterator parameters = parameterList.listIterator();

    String prefix = "";

    if (typed) {
      prefix = "real ";
    }

    String parameterString = "";

    while (parameters.hasNext()) {
      String parameterName = ((NamedObj) parameters.next()).getName();

      if (parameterName.startsWith("_")) {
        continue;
      }

      if (parameterString == "") {
        parameterString += (prefix + parameterName);
      } else {
        parameterString += (", " + prefix + parameterName);
      }
    }

    return parameterString;
  }
Exemple #4
0
  /**
   * Open an edit parameters dialog. This is a modal dialog, so this method returns only after the
   * dialog has been dismissed.
   *
   * @param parent A frame to serve as a parent for the dialog, or null if there is none.
   * @param target The object whose parameters are to be edited.
   */
  public void openDialog(Frame parent, NamedObj target) {
    List attributeList = target.attributeList(EditorFactory.class);

    if (attributeList.size() > 0) {
      EditorFactory factory = (EditorFactory) attributeList.get(0);
      factory.createEditor(target, parent);
    } else {
      new EditParametersDialog(parent, target);
    }
  }
Exemple #5
0
 /**
  * Find an attribute in the object or its container (if searchContainers is true) in the given
  * class.
  *
  * @param object The object to which the attribute longs.
  * @param attributeClass The attribute class.
  * @param searchContainers Whether containers of the object are searched.
  * @return The attribute if found, or null otherwise.
  */
 public static Attribute findMatchingAttribute(
     Object object, Class<? extends Attribute> attributeClass, boolean searchContainers) {
   if (object instanceof NamedObj) {
     NamedObj namedObj = (NamedObj) object;
     List<?> list = namedObj.attributeList(attributeClass);
     if (!list.isEmpty()) {
       return (Attribute) list.get(0);
     } else if (searchContainers) {
       return findMatchingAttribute(namedObj.getContainer(), attributeClass, searchContainers);
     }
   }
   return null;
 }
Exemple #6
0
 /**
  * Remove all the attributes in the given class from the given container and all of its children
  * including ports, entities and relations, but not including attributes.
  *
  * @param container The container.
  * @param attributeClass The attribute class.
  * @exception IllegalActionException If an attribute cannot be removed.
  */
 public static void deepRemoveAttributes(
     NamedObj container, Class<? extends Attribute> attributeClass) throws IllegalActionException {
   List<Object> attributes = new LinkedList<Object>(container.attributeList(attributeClass));
   for (Object attribute : attributes) {
     try {
       ((Attribute) attribute).setContainer(null);
     } catch (NameDuplicationException e) {
       // This should not happen.
     }
   }
   for (Object child : getChildren(container, false, true, true, true)) {
     deepRemoveAttributes((NamedObj) child, attributeClass);
   }
 }
Exemple #7
0
 /**
  * Remove the EditorIcons defined for the entity.
  *
  * @param entity The entity.
  * @return true if at least one EditorIcon is found and removed; false otherwise.
  * @exception KernelException If error occurs while removing the EditorIcons.
  */
 private static boolean _removeEditorIcons(GTEntity entity) throws KernelException {
   NamedObj object = (NamedObj) entity;
   boolean foundPersistentIcon = false;
   try {
     object.workspace().getReadAccess();
     for (Object iconObject : object.attributeList(EditorIcon.class)) {
       EditorIcon icon = (EditorIcon) iconObject;
       if (icon.isPersistent()) {
         foundPersistentIcon = true;
       } else {
         icon.setContainer(null);
       }
     }
   } finally {
     object.workspace().doneReading();
   }
   return !foundPersistentIcon;
 }
  /**
   * Get the string to render in the icon. This string is the expression giving the value of the
   * attribute of the container having the name <i>attributeName</i>, truncated so that it is no
   * longer than <i>displayWidth</i> characters. If it is truncated, then the string has a trailing
   * "...". If the string is empty, then return a string with one space (diva fails on empty
   * strings).
   *
   * @return The string to display, or null if none is found.
   */
  protected String _displayString() {
    NamedObj container = getContainer();

    if (container != null) {
      StringBuffer buffer = new StringBuffer();
      Iterator settables = container.attributeList(Settable.class).iterator();

      while (settables.hasNext()) {
        Settable settable = (Settable) settables.next();

        if ((settable.getVisibility() != Settable.FULL)
            && (settable.getVisibility() != Settable.NOT_EDITABLE)) {
          continue;
        }

        String name = settable.getDisplayName();
        String value = settable.getExpression();
        String line = name + ": " + value;
        String truncated = line;

        try {
          int width = ((IntToken) displayWidth.getToken()).intValue();

          if (line.length() > width) {
            truncated = line.substring(0, width) + "...";
          }
        } catch (IllegalActionException ex) {
          // Ignore... use whole string.
        }

        buffer.append(truncated);

        if (settables.hasNext()) {
          buffer.append("\n");
        }
      }

      return buffer.toString();
    }

    return null;
  }
Exemple #9
0
  /**
   * Check whether the attribute is unique in the given container.
   *
   * @param attribute The attribute to check.
   * @param container The container.
   * @exception IllegalActionException If the container already has an attribute in the same class.
   */
  public static void checkUniqueness(Attribute attribute, NamedObj container)
      throws IllegalActionException {
    if (container instanceof EntityLibrary) {
      return;
    }

    try {
      container.workspace().getReadAccess();
      List<? extends Attribute> attributeList = container.attributeList(attribute.getClass());
      for (Attribute existingAttribute : attributeList) {
        if (existingAttribute != attribute && existingAttribute.isPersistent()) {
          _delete(attribute);
          throw new IllegalActionException(
              "Only 1 " + attribute.getClass().getSimpleName() + " can be used.");
        }
      }
    } finally {
      container.workspace().doneReading();
    }
  }
Exemple #10
0
  /**
   * Remove the decorated attributes.
   *
   * @param target The decorated attribute to remove
   */
  public void removeDecoratedAttributes(NamedObj target) {
    if (_debugging) {
      _debug("create decorated attributes to be called for Giotto quantityManager");
    }
    for (Actor actor :
        (List<Actor>) ((TypedCompositeActor) target.getContainer()).deepEntityList()) {
      NamedObj temp = (NamedObj) actor;
      if (_debugging) {
        _debug("temp has name " + temp.getDisplayName());
      }

      List<Parameter> paramList = temp.attributeList();

      for (Parameter param : paramList) {
        if (param.getDisplayName().equals("WCET")) {
          param.setPersistent(false);
        }
      }
    }
  }
Exemple #11
0
  /**
   * Return as a single string all the documentation associated with the specified object. Each
   * attribute of type of class Documentation that the object contains contributes to the
   * documentation. The text contributed by each such attribute starts on a new line. If there are
   * no such attributes, then null is returned.
   *
   * @param object The object to document.
   * @return The documentation for the object.
   */
  public static String consolidate(NamedObj object) {
    List docList = object.attributeList(Documentation.class);

    if (docList.size() > 0) {
      StringBuffer doc = new StringBuffer();
      Iterator segments = docList.iterator();

      while (segments.hasNext()) {
        Documentation segment = (Documentation) segments.next();
        doc.append(segment.getValueAsString());

        if (segments.hasNext()) {
          doc.append("\n");
        }
      }

      return doc.toString();
    } else {
      return null;
    }
  }
Exemple #12
0
  /**
   * Update the appearance (icons and ports) of the entity with the change in a
   * GTIngredientAttribute, such as a criterion or an operation.
   *
   * @param entity The entity.
   * @param attribute The attribute whose recent change leads to an update of the entity.
   */
  public static void updateAppearance(final GTEntity entity, GTIngredientsAttribute attribute) {

    NamedObj object = (NamedObj) entity;
    Workspace workspace = object.workspace();
    try {
      workspace.getWriteAccess();

      List<?> icons = object.attributeList(EditorIcon.class);
      boolean foundPersistentIcon = false;
      for (Object iconObject : icons) {
        EditorIcon icon = (EditorIcon) iconObject;
        if (icon.isPersistent()) {
          foundPersistentIcon = true;
          break;
        }
      }

      Set<String> preservedPortNames = new HashSet<String>();
      boolean isIconSet = false;
      int i = 1;
      GTIngredientList list = attribute.getIngredientList();
      for (GTIngredient ingredient : list) {
        if (ingredient instanceof PortCriterion) {
          PortCriterion criterion = (PortCriterion) ingredient;
          String portID = criterion.getPortID(list);
          preservedPortNames.add(portID);

          TypedIOPort port = (TypedIOPort) ((ComponentEntity) entity).getPort(portID);
          boolean isInput = criterion.isInput();
          boolean isOutput = criterion.isOutput();
          boolean isMultiport = !criterion.isMultiportEnabled() || criterion.isMultiport();
          if (port != null) {
            if (port instanceof PortMatcher) {
              port.setInput(isInput);
              port.setOutput(isOutput);
            } else {
              MoMLChangeRequest request =
                  new MoMLChangeRequest(
                      entity, object, "<deletePort name=\"" + port.getName() + "\"/>");
              request.setUndoable(true);
              request.setMergeWithPreviousUndo(true);
              request.execute();
              port =
                  new PortMatcher(criterion, (ComponentEntity) entity, portID, isInput, isOutput);
              port.setDerivedLevel(1);
            }
          } else {
            port = new PortMatcher(criterion, (ComponentEntity) entity, portID, isInput, isOutput);
            port.setDerivedLevel(1);
          }
          port.setMultiport(isMultiport);
        } else if (ingredient instanceof SubclassCriterion && !isIconSet && !foundPersistentIcon) {
          SubclassCriterion criterion = (SubclassCriterion) ingredient;
          final String superclass = criterion.getSuperclass();
          object.requestChange(
              new ChangeRequest(entity, "Deferred load actor icon action.") {
                protected void _execute() throws Exception {
                  _loadActorIcon(entity, superclass);
                }
              });
          isIconSet = true;
        }
        i++;
      }
      if (!isIconSet && !foundPersistentIcon) {
        object.requestChange(new RestoreAppearanceChangeRequest(entity));
      }

      ComponentEntity component = (ComponentEntity) entity;
      try {
        component.workspace().getReadAccess();
        List<?> portList = new LinkedList<Object>(component.portList());
        for (i = 0; i < portList.size(); i++) {
          Port port = (Port) portList.get(i);
          if (port instanceof PortMatcher && !preservedPortNames.contains(port.getName())) {
            ((PortMatcher) port)._setPortCriterion(null);
            port.setContainer(null);
          }
        }
      } finally {
        component.workspace().doneReading();
      }

    } catch (KernelException e) {
      throw new KernelRuntimeException(
          e, "Cannot update appearance for " + "actor " + entity.getName() + ".");

    } finally {
      workspace.doneWriting();
    }
  }