Beispiel #1
0
 /**
  * Retrieves the text of an option element. If the text was set by {@link #setOptionText} and was
  * wrapped with Unicode bidi formatting characters, also removes those additional formatting
  * characters.
  *
  * @param option an option element
  * @return the element's text
  */
 protected String getOptionText(OptionElement option) {
   String text = option.getText();
   if (option.hasAttribute(BIDI_ATTR_NAME) && text.length() > 1) {
     text = text.substring(1, text.length() - 1);
   }
   return text;
 }
Beispiel #2
0
 private void insertItem(String item, Direction dir, String value, String optionStyle) {
   SelectElement select = getSelectElement();
   OptionElement option = createOption(item, dir, value);
   if (optionStyle != null) {
     option.setClassName(optionStyle);
   }
   select.appendChild(option);
 }
Beispiel #3
0
 private OptionElement createOption(String item, Direction dir, String value, String className) {
   OptionElement option = Document.get().createOptionElement();
   setOptionText(option, item, dir);
   option.setValue(value);
   if (className != null) {
     option.addClassName(className);
   }
   return option;
 }
Beispiel #4
0
  /**
   * Creates an <code>&lt;option&gt;</code> element and inserts it as a child of the specified
   * <code>&lt;select&gt;</code> element. If the index is less than zero, or greater than or equal
   * to the length of the list, then the option element will be appended to the end of the list.
   *
   * @param selectElem the <code>&lt;select&gt;</code> element
   * @param item the text of the new item; cannot be <code>null</code>
   * @param value the <code>value</code> attribute for the new <code>&lt;option&gt;</code>; cannot
   *     be <code>null</code>
   * @param index the index at which to insert the child
   */
  public static void insertListItem(Element selectElem, String item, String value, int index) {
    assert !PotentialElement.isPotential(selectElem) : "Cannot insert into a PotentialElement";

    SelectElement select = selectElem.<SelectElement>cast();
    OptionElement option = Document.get().createOptionElement();
    option.setText(item);
    option.setValue(value);

    if ((index == -1) || (index == select.getLength())) {
      select.add(option, null);
    } else {
      OptionElement before = select.getOptions().getItem(index);
      select.add(option, before);
    }
  }
Beispiel #5
0
 /**
  * Sets the text of an option element. If the direction of the text is opposite to the page's
  * direction, also wraps it with Unicode bidi formatting characters to prevent garbling, and
  * indicates that this was done by setting the option's <code>BIDI_ATTR_NAME</code> custom
  * attribute.
  *
  * @param option an option element
  * @param text text to be set to the element
  * @param dir the text's direction. If {@code null} and direction estimation is turned off,
  *     direction is ignored.
  */
 protected void setOptionText(OptionElement option, String text, Direction dir) {
   if (dir == null && estimator != null) {
     dir = estimator.estimateDirection(text);
   }
   if (dir == null) {
     option.setText(text);
     option.removeAttribute(BIDI_ATTR_NAME);
   } else {
     String formattedText =
         BidiFormatter.getInstanceForCurrentLocale()
             .unicodeWrapWithKnownDir(dir, text, false /* isHtml */, false /* dirReset */);
     option.setText(formattedText);
     if (formattedText.length() > text.length()) {
       option.setAttribute(BIDI_ATTR_NAME, "");
     } else {
       option.removeAttribute(BIDI_ATTR_NAME);
     }
   }
 }
Beispiel #6
0
  private void resultsReset(Event e) {
    OptionElement firstoption = selectElement.getOptions().getItem(0);
    if (firstoption != null) {
      firstoption.setSelected(true);
    }

    selectedItem.find("span").text(defaultText);
    if (!isMultiple) {
      selectedItem.addClass(css.chznDefault());
    }

    showSearchFieldDefault();
    resultsResetCleanup();

    fireEvent(new ChosenChangeEvent(null, this));
    if (activeField) {
      resultsHide();
    }
  }
Beispiel #7
0
  private void resultDeselect(int index) {
    OptionItem item = (OptionItem) selectItems.get(index);

    item.setSelected(false);

    // select option in original element
    OptionElement option = selectElement.getOptions().getItem(item.getOptionsIndex());
    option.setSelected(false);

    $("#" + containerId + "_o_" + index)
        .removeClass(css.resultSelected())
        .addClass(css.activeResult())
        .show();

    resultClearHighlight();
    winnowResults();

    fireEvent(new ChosenChangeEvent(option.getValue(), false, this));

    searchFieldScale();
  }