コード例 #1
0
  /**
   * Returns the default option from the given list of select options, or <code>null</code> in case
   * there is no default option in the given list.
   *
   * <p>If an element found in the given list is not of type <code>{@link CmsSelectWidgetOption}
   * </code>, this is ignored.
   *
   * <p>
   *
   * @param options the list of select options to get the default from
   * @return the default option from the given list of select options, or <code>null</code> in case
   *     there is no default option
   */
  public static CmsSelectWidgetOption getDefaultOption(List<CmsSelectWidgetOption> options) {

    if ((options == null) || (options.size() == 0)) {
      return null;
    }
    for (int i = 0; i < options.size(); i++) {
      Object o = options.get(i);
      if (o instanceof CmsSelectWidgetOption) {
        CmsSelectWidgetOption option = (CmsSelectWidgetOption) o;
        if (option.isDefault()) {
          return option;
        }
      }
    }
    return null;
  }
コード例 #2
0
  /**
   * Returns a list of default options from the given list of select options.
   *
   * <p>If an element found in the given list is not of type <code>{@link CmsSelectWidgetOption}
   * </code>, this is ignored.
   *
   * <p>
   *
   * @param options the list of select options to get the default from
   * @return a list of <code>{@link CmsSelectWidgetOption}</code> objects
   */
  public static List<CmsSelectWidgetOption> getDefaultOptions(List<CmsSelectWidgetOption> options) {

    List<CmsSelectWidgetOption> defaults = new ArrayList<CmsSelectWidgetOption>();
    if ((options == null) || (options.size() == 0)) {
      return defaults;
    }
    for (int i = 0; i < options.size(); i++) {
      Object o = options.get(i);
      if (o instanceof CmsSelectWidgetOption) {
        CmsSelectWidgetOption option = (CmsSelectWidgetOption) o;
        if (option.isDefault()) {
          defaults.add(option);
        }
      }
    }
    return defaults;
  }
コード例 #3
0
  /**
   * Returns a select widget configuration String created from the given list of select options.
   *
   * <p>If an element found in the given list is not of type <code>{@link CmsSelectWidgetOption}
   * </code>, it is ignored.
   *
   * <p>
   *
   * @param options the list of select options to create the configuration String for
   * @return a select widget configuration String created from the given list of select options
   */
  public static String createConfigurationString(List<CmsSelectWidgetOption> options) {

    if ((options == null) || (options.size() == 0)) {
      return "";
    }
    StringBuffer result = new StringBuffer(256);
    boolean first = true;
    for (int i = 0; i < options.size(); i++) {
      CmsSelectWidgetOption o = options.get(i);
      if (!first) {
        result.append(CmsSelectWidgetOption.INPUT_DELIMITER);
      } else {
        first = false;
      }
      result.append(o.toString());
    }
    return result.toString();
  }