/**
   * Adds the option (and create the associated DOM node if needed) before the specified one or at
   * the end if the specified one in null.
   *
   * @param newOptionObject the new option to add
   * @param beforeOption the option that should be after the option to add
   */
  protected void addBefore(final HTMLOptionElement newOptionObject, final HtmlOption beforeOption) {
    final HtmlSelect select = getHtmlSelect();

    HtmlOption htmlOption = newOptionObject.getDomNodeOrNull();
    if (htmlOption == null) {
      htmlOption =
          (HtmlOption)
              HTMLParser.getFactory(HtmlOption.TAG_NAME)
                  .createElement(select.getPage(), HtmlOption.TAG_NAME, null);
    }

    if (beforeOption == null) {
      select.appendChild(htmlOption);
    } else {
      beforeOption.insertBefore(htmlOption);
    }
  }