Exemple #1
0
  /**
   * Attach an attribute to an entry with name <i>entryName</i>, of a Query. This will cause the
   * attribute to be updated whenever the specified entry changes. In addition, a listener is
   * registered so that the entry will change whenever the attribute changes. If the entry has
   * previously been attached to a attribute, then it is detached first from that attribute. If the
   * attribute argument is null, this has the effect of detaching the entry from any attribute.
   *
   * @param attribute The attribute to attach to an entry.
   * @param entryName The entry to attach the attribute to.
   */
  public void attachParameter(Settable attribute, String entryName) {
    // Put the attribute in a Map from entryName -> attribute
    _attributes.put(entryName, attribute);

    // Make a record of the attribute value prior to the change,
    // in case a change fails and the user chooses to revert.
    // Use the translated expression in case the attribute
    // is a DoubleRangeParameter.
    _revertValue.put(entryName, _getTranslatedExpression(attribute));

    // Attach the entry to the attribute by registering a listener.
    attribute.addValueListener(this);

    // Put the attribute in a Map from attribute -> (list of entry names
    // attached to attribute), but only if entryName is not already
    // contained by the list.
    if (_varToListOfEntries.get(attribute) == null) {
      // No mapping for attribute exists.
      List<String> entryNameList = new LinkedList<String>();
      entryNameList.add(entryName);
      _varToListOfEntries.put(attribute, entryNameList);
    } else {
      // attribute is mapped to a list of entry names, but need to
      // check whether entryName is in the list. If not, add it.
      List<String> entryNameList = _varToListOfEntries.get(attribute);
      Iterator<String> entryNames = entryNameList.iterator();
      boolean found = false;

      while (entryNames.hasNext()) {
        // Check whether entryName is in the list. If not, add it.
        String name = entryNames.next();

        if (name.equals(entryName)) {
          found = true;
        }
      }

      if (found == false) {
        // Add entryName to the list.
        entryNameList.add(entryName);
      }
    }

    // Handle tool tips.  This is almost certainly an instance
    // of NamedObj, but check to be sure.
    if (attribute instanceof NamedObj) {
      Attribute tooltipAttribute = ((NamedObj) attribute).getAttribute("tooltip");

      if ((tooltipAttribute != null) && tooltipAttribute instanceof Documentation) {
        setToolTip(entryName, ((Documentation) tooltipAttribute).getValueAsString());
      } else {
        String tip = Documentation.consolidate((NamedObj) attribute);

        if (tip != null) {
          setToolTip(entryName, tip);
        }
      }
    }
  }
Exemple #2
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;
    }
  }