com.google.gwt.dom.client.OptionElement Java Examples

The following examples show how to use com.google.gwt.dom.client.OptionElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultipleSelect.java    From gwtbootstrap3-extras with Apache License 2.0 6 votes vote down vote up
@Override
protected void setSelectedValue(List<String> value) {
    if (isAttached()) {
        final JsArrayString arr = JavaScriptObject.createArray().cast();
        for (final String val : value) {
            arr.push(val);
        }
        setValue(getElement(), arr);
    } else {
        for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
            Option opt = entry.getValue();
            boolean selected = value.contains(opt.getValue());
            opt.setSelected(selected);
        }
    }
}
 
Example #2
Source File: GroupedListBox.java    From gwt-traction with Apache License 2.0 6 votes vote down vote up
protected OptionElement getOption(int index) {
    checkIndex(index);

    int childIndex = index;
    for (OptGroup group : groups) {
        int count = group.getCount();
        if (childIndex < count) {
            return group.getChildOption(childIndex);
        }
        else {
            childIndex -= count;
        }
    }

    throw new IndexOutOfBoundsException("problem in getOption: index="+index+" range=[0-"+(getItemCount()-1)+"]");
}
 
Example #3
Source File: SelectBase.java    From gwtbootstrap3-extras with Apache License 2.0 6 votes vote down vote up
void updateItemMap(Widget widget, boolean toAdd) {
    // Option ==> update with this option
    if (widget instanceof Option) {
        Option option = (Option) widget;
        if (toAdd)
            itemMap.put(option.getSelectElement(), option);
        else
            itemMap.remove(option.getSelectElement());
    } else if (widget instanceof OptGroup) {
        // OptGroup ==> update with all optGroup options
        OptGroup optGroup = (OptGroup) widget;
        if (toAdd)
            itemMap.putAll(optGroup.getItemMap());
        else
            for (Entry<OptionElement, Option> entry : optGroup.getItemMap().entrySet()) {
                OptionElement optElem = entry.getKey();
                itemMap.remove(optElem);
            }
    }
}
 
Example #4
Source File: Select.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
private String getSelectedValue() {
    for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
        Option opt = entry.getValue();
        if (opt.isSelected())
            return opt.getValue();
    }
    return null;
}
 
Example #5
Source File: GroupedListBox.java    From swcv with MIT License 5 votes vote down vote up
protected OptionElement getOption(int index)
{
    checkIndex(index);

    // first check ungrouped
    Element elm = getElement();
    int sz = elm.getChildCount();
    int firstGroup = getIndexOfFirstGroup();
    if (index >= 0 && index < firstGroup && index < sz)
    {
        return option(elm.getChild(index));
    }

    // then go through the groups
    int childIndex = index - firstGroup;
    for (int i = firstGroup; i <= index && i < sz; i++)
    {
        Node child = elm.getChild(i);
        if (isGroup(child))
        {
            if (childIndex < child.getChildCount())
            {
                return option(child.getChild(childIndex));
            }
            else
            {
                childIndex -= child.getChildCount();
            }
        }
    }
    return null;
}
 
Example #6
Source File: GroupedListBox.java    From swcv with MIT License 5 votes vote down vote up
protected OptionElement createOption(String item, String value)
{
    OptionElement option = Document.get().createOptionElement();
    option.setText(item);
    option.setInnerText(item);
    option.setValue(value);
    return option;
}
 
Example #7
Source File: GroupedListBox.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
public void removeItem(int index) {

    int childIndex = index;
    for (int i=0; i<groups.size(); i++) {
        OptGroup group = groups.get(i);
        int count = group.getCount();
        if (childIndex < count) {

            // do the remove
            OptionElement element = group.getChildOption(childIndex);
            element.removeFromParent();

            group.decrement();

            // remove empty groups
            if (group.getCount() <= 0) {
                group.remove();
                groups.remove(i);
            }

            return;
        }
        else {
            childIndex -= count;
        }
    }

    throw new IndexOutOfBoundsException("problem in removeItem: index="+index+" range=[0-"+(getItemCount()-1)+"]");
}
 
Example #8
Source File: GroupedListBox.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
public void setItemText(int index, String text) {
    if (text == null) {
        throw new NullPointerException("Cannot set an option to have null text");
    }
    OptionElement option = getOption(index);
    option.setText(text);
}
 
Example #9
Source File: GroupedListBox.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
protected OptionElement createOption(String item, String value) {
    OptionElement option = Document.get().createOptionElement();
    option.setText(item);
    option.setInnerText(item);
    option.setValue(value);
    return option;
}
 
Example #10
Source File: SelectorDisplayerView.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
protected void showHint(String hint) {
    if (hintEnabled) {
        SelectElement selectElement = SelectElement.as(listBox.getElement());
        NodeList<OptionElement> options = selectElement.getOptions();
        options.getItem(0).setText(hint);
    } else {
        listBox.addItem(hint);
        hintEnabled = true;
    }
}
 
Example #11
Source File: SelectorDisplayerView.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
@Override
public void setItemTitle(int index, String title) {
    SelectElement selectElement = SelectElement.as(listBox.getElement());
    NodeList<OptionElement> options = selectElement.getOptions();
    OptionElement optionElement = options.getItem(index + (hintEnabled ? 1: 0));
    if (optionElement != null) {
        optionElement.setTitle(title);
    }
}
 
Example #12
Source File: WebClient.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private void setupLocaleSelect() {
  final SelectElement select = (SelectElement) Document.get().getElementById("lang");
  String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
  String[] localeNames = LocaleInfo.getAvailableLocaleNames();
  for (String locale : localeNames) {
    if (!DEFAULT_LOCALE.equals(locale)) {
      String displayName = LocaleInfo.getLocaleNativeDisplayName(locale);
      OptionElement option = Document.get().createOptionElement();
      option.setValue(locale);
      option.setText(displayName);
      select.add(option, null);
      if (locale.equals(currentLocale)) {
        select.setSelectedIndex(select.getLength() - 1);
      }
    }
  }
  EventDispatcherPanel.of(select).registerChangeHandler(null, new WaveChangeHandler() {

    @Override
    public boolean onChange(ChangeEvent event, Element context) {
      UrlBuilder builder = Location.createUrlBuilder().setParameter(
              "locale", select.getValue());
      Window.Location.replace(builder.buildString());
      localeService.storeLocale(select.getValue());
      return true;
    }
  });
}
 
Example #13
Source File: CubaListSelectWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
public CubaListSelectWidget() {
    getOptionsContainer().addDoubleClickHandler(event -> {
        if (!isEnabled() || isReadonly()) {
            return;
        }

        Element element = WidgetUtil.getElementUnderMouse(event.getNativeEvent());

        if (OptionElement.is(element)) {
            doubleClickListener.accept(((OptionElement) element).getIndex());
        }
    });
}
 
Example #14
Source File: Select.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
@Override
protected void setSelectedValue(String value) {
    if (isAttached()) {
        setValue(getElement(), value);
    } else {
        for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
            Option opt = entry.getValue();
            opt.setSelected(opt.getValue().equals(value));
        }
    }
}
 
Example #15
Source File: Select.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the selected item or <code>null</code> if no item is selected.
 *
 * @return the selected items list
 */
public Option getSelectedItem() {
    for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
        Option opt = entry.getValue();
        if (opt.isSelected())
            return opt;
    }
    return null;
}
 
Example #16
Source File: SelectBase.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the item list.
 *
 * @return the item list
 */
public List<Option> getItems() {
    List<Option> selectedItems = new ArrayList<>(0);
    NodeList<OptionElement> items = selectElement.getOptions();
    for (int i = 0; i < items.getLength(); i++) {
        OptionElement item = items.getItem(i);
        Option option = itemMap.get(item);
        if (option != null)
            selectedItems.add(option);
    }
    return selectedItems;
}
 
Example #17
Source File: MultipleSelect.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
private List<String> getSelectedValues() {
    final List<String> allSelected = new ArrayList<>(0);
    for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
        Option opt = entry.getValue();
        if (opt.isSelected())
            allSelected.add(opt.getValue());
    }
    return allSelected;
}
 
Example #18
Source File: MultipleSelect.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the selected items list. If no item is selected, this method
 * returns an empty list.
 *
 * @return the selected items list
 */
public List<Option> getSelectedItems() {
    final List<Option> items = new ArrayList<>(0);
    for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
        Option opt = entry.getValue();
        if (opt.isSelected())
            items.add(opt);
    }
    return items;
}
 
Example #19
Source File: MultipleSelect.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
private void setSelectAll(boolean selected) {
    if (isAttached()) {
        String cmd = selected ? SelectCommand.SELECT_ALL : SelectCommand.DESELECT_ALL;
        command(getElement(), cmd);
    } else {
        for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
            entry.getValue().setSelected(selected);
        }
    }
}
 
Example #20
Source File: MVTagsInput.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
@Override
public void add(String tag) {
    if (isAttached())
        super.add(tag);
    else {
        OptionElement option = Document.get().createOptionElement();
        option.setValue(tag);
        option.setInnerText(tag);
        getElement().appendChild(option);
    }
}
 
Example #21
Source File: WebClient.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private void setupLocaleSelect() {
  final SelectElement select = (SelectElement) Document.get().getElementById("lang");
  String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
  String[] localeNames = LocaleInfo.getAvailableLocaleNames();
  for (String locale : localeNames) {
    if (!DEFAULT_LOCALE.equals(locale)) {
      String displayName = LocaleInfo.getLocaleNativeDisplayName(locale);
      OptionElement option = Document.get().createOptionElement();
      option.setValue(locale);
      option.setText(displayName);
      select.add(option, null);
      if (locale.equals(currentLocale)) {
        select.setSelectedIndex(select.getLength() - 1);
      }
    }
  }
  EventDispatcherPanel.of(select).registerChangeHandler(null, new WaveChangeHandler() {

    @Override
    public boolean onChange(ChangeEvent event, Element context) {
      UrlBuilder builder = Location.createUrlBuilder().setParameter(
              "locale", select.getValue());
      Window.Location.replace(builder.buildString());
      localeService.storeLocale(select.getValue());
      return true;
    }
  });
}
 
Example #22
Source File: CubaTwinColSelectWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
public List<String> getItems() {
    List<String> items = new ArrayList<>();
    for (int i = 0; i < getItemCount(); i++) {
        OptionElement optionElement = (OptionElement) getOptionElement(i);
        items.add(getOptionText(optionElement));
    }
    return items;
}
 
Example #23
Source File: MaterialListValueBox.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
protected void removeEmptyPlaceHolder() {
    // indeed the first item/value is emptyPlaceHolder
    listBox.removeItem(0);
    values.remove(0);

    OptionElement currentPlaceholder = getOptionElement(0);
    if (currentPlaceholder != null) {
        currentPlaceholder.setDisabled(false);
    }
}
 
Example #24
Source File: GroupedListBox.java    From swcv with MIT License 4 votes vote down vote up
private OptionElement option(Node node)
{
    if (node == null)
        return null;
    return OptionElement.as(Element.as(node));
}
 
Example #25
Source File: MaterialListBox.java    From gwt-material with Apache License 2.0 4 votes vote down vote up
public void add(Option option) {
    getSelectElement().add(OptionElement.as(option.getElement()), null);
    values.add(option.getValue());
}
 
Example #26
Source File: MaterialListValueBox.java    From gwt-material with Apache License 2.0 4 votes vote down vote up
public OptionElement getOptionElement(int index) {
    return getSelectElement().getOptions().getItem(index);
}
 
Example #27
Source File: Option.java    From gwt-material with Apache License 2.0 4 votes vote down vote up
public Option() {
    super(Document.get().createElement(OptionElement.TAG));
}
 
Example #28
Source File: Option.java    From gwt-material with Apache License 2.0 4 votes vote down vote up
/**
 * The index of this OPTION in its parent SELECT, starting from 0.
 */
public int getIndex() {
    return OptionElement.as(this.getElement()).getIndex();
}
 
Example #29
Source File: Option.java    From gwt-material with Apache License 2.0 4 votes vote down vote up
/**
 * The text contained within the option element.
 */
public String getText() {
    return OptionElement.as(this.getElement()).getText();
}
 
Example #30
Source File: OptGroup.java    From gwtbootstrap3-extras with Apache License 2.0 4 votes vote down vote up
Map<OptionElement, Option> getItemMap() {
    return itemMap;
}