List of usage examples for com.google.gwt.dom.client OptionElement setAttribute
@Override
public void setAttribute(String name, String value)
From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java
License:Apache License
/** * Appends an item to the end of the list, adding the supplied class name to its class attribute. Specifying a * non-zero {@code indentLevel} will pad the item from the left by a fixed distance applied {@code indentLevel} * times.//w ww .j a va 2s .c om * <p/> * For example, a call: * <p/> * {@code * addStyledItem("My Item", "item1", "highlighted", 1); * } * <p/> * will result in the addition to the end of the {@code <select>} element of: * <p/> * {@code * <option value="item1" class="highlighted" style="padding-left: 15px;" >My Item</option> * } * * @param label the item label to display to the user * @param value the value of the item, meaningful in the context of an HTML form * @param className the class name to add to this item (pass {@code null} to add no class name) * @param indentLevel the number of times to indent the item from the left (pass 0 for no indentation) */ public void addStyledItem(String label, String value, String className, int indentLevel) { if (indentLevel < 0) { throw new IllegalArgumentException("[indentLevel] must be non-negative."); } GQuery $selectElem = $(getElement()); OptionElement option = Document.get().createOptionElement(); option.setValue(value); option.setText(label); if (!(className == null || className.trim().isEmpty())) { option.addClassName(className); } if (indentLevel > 0) { int leftPadding = options.getResources().css().indent() * indentLevel; option.setAttribute("style", "padding-left: " + leftPadding + "px;"); } $selectElem.append(option); }
From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java
License:Apache License
/** * Inserts an item into a group at the specified location. Additionally, the item can have an extra class name as * well as indent level assigned to it.//from ww w .j a va 2 s .c om * <p/> * <b>NB!</b> It is important to set text into the option after the option has been appended to the DOM * <br/>that's known bug in IE @see <a href="http://bugs.jquery.com/ticket/3041">jQuery bug tracker</a> * <p/> * * @param item the item label to display * @param value the value of the item in the HTML form context * @param className the class name to append to the option (pass {@code null} to append no class name) * @param dir allows specifying an RTL, LTR or inherited direction ({@code null} is LTR) * @param indentLevel the number of times to indent the item from the left (pass 0 for no indentation) * @param groupIndex the index of the group to insert the item into (if out of bounds, the last group will be used) * @param itemIndex the index of the item within a group (if out of bounds, item will be placed last in the group) */ public void insertStyledItemToGroup(String item, String value, String className, Direction dir, int indentLevel, int groupIndex, int itemIndex) { int pos = groupIndex; if (indentLevel < 0) { throw new IllegalArgumentException("[indentLevel] must be non-negative."); } GQuery optgroupList = $(OPTGROUP_TAG, getElement()); int groupCount = optgroupList.size(); if (groupCount == 0) { // simply insert the item to the listbox insertItem(item, dir, value, itemIndex); return; } if (pos < 0 || pos > groupCount - 1) { pos = groupCount - 1; } GQuery optgroup = optgroupList.eq(pos); OptionElement option = Document.get().createOptionElement(); if (!(className == null || className.trim().isEmpty())) { option.addClassName(className); } if (indentLevel > 0) { // Calculate total indentation, not forgetting that being in a group is adding one extra indent step int leftPadding = options.getResources().css().indent() * (indentLevel + 1); option.setAttribute("style", "padding-left: " + leftPadding + "px;"); } Element optGroupElement = optgroup.get(0); int itemCount = optGroupElement.getChildCount(); if (itemIndex < 0 || itemIndex > itemCount - 1) { optgroup.append(option); } else { GQuery before = $(optGroupElement.getChild(itemIndex)); before.before(option); } // setText must be after the element has been appended to the DOM - see javadoc setOptionText(option, item, dir); option.setValue(value); }
From source file:gwt.material.design.client.ui.MaterialListBox.java
License:Apache License
public void setPlaceholder(String placeholder) { super.insertItem(placeholder, 0); setItemSelected(0, true);/*from w w w . j ava 2 s .c o m*/ OptionElement option = getOptionElement(0); option.setAttribute("disabled", ""); initializeMaterial(); }
From source file:io.apiman.manager.ui.client.local.pages.common.SelectBox.java
License:Apache License
/** * Sets the select box's options./* w w w. j a va 2 s . c o m*/ * @param options */ public void setOptions(List<T> options) { clear(); this.options = options; for (T option : options) { String name = optionName(option); String value = optionValue(option); String dataContent = optionDataContent(option); if (value == null) this.addItem(name); else this.addItem(name, value); if (dataContent != null) { SelectElement select = getElement().cast(); NodeList<OptionElement> o = select.getOptions(); OptionElement item = o.getItem(o.getLength() - 1); item.setAttribute("data-content", dataContent); //$NON-NLS-1$ } } if (isAttached()) { refreshUI(getElement()); } }