List of usage examples for com.google.gwt.query.client GQuery before
public GQuery before(String html)
From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java
License:Apache License
/** * Insert a group to the list box.//from ww w . ja v a 2 s. co m * * @param label the text of the group to be added * @param id the id of the optgroup element * @param index the index at which to insert it */ public void insertGroup(String label, String id, int index) { GQuery optGroup = $("<optgroup></optgroup>").attr("label", label); if (id != null) { optGroup.attr("id", id); } GQuery select = $(getElement()); int itemCount = SelectElement.as(getElement()).getLength(); if (index < 0 || index > itemCount) { select.append(optGroup); } else { GQuery before = select.children().eq(index); before.before(optGroup); } }
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 w w w . j av a 2s . co m * <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:com.watopi.chosen.client.gwt.ChosenListBox.java
License:Open Source License
/** * Insert a group to the list box.//from w w w . j a v a 2 s.c o m * * @param group * the text of the group to be added * @param index * the index at which to insert it */ public void insertGroup(String group, int index) { GQuery optGroup = $("<optgroup></optgroup>").attr("label", group); GQuery select = $(getElement()); int itemCount = SelectElement.as(getElement()).getLength(); if (index < 0 || index > itemCount) { select.append(optGroup); } else { GQuery before = select.children().eq(index); before.before(optGroup); } }
From source file:com.watopi.chosen.client.gwt.ChosenListBox.java
License:Open Source License
/** * Adds an item to the an optgroup of the list box. If no optgroup exists, * the item will be add at the end ot the list box. * //from ww w. j ava2s. co m * @param item * the text of the item to be added * @param value * the value of the item to be added * @param itemIndex * the index inside the optgroup at which to insert the item * @param groupIndex * the index of the optGroup where the item will be inserted */ public void insertItemToGroup(String item, Direction dir, String value, int groupIndex, int itemIndex) { GQuery select = $(getElement()); GQuery optgroupList = select.children("optgroup"); int groupCount = optgroupList.size(); if (groupCount == 0) { // simply insert the item to the listbox insertItem(item, dir, value, itemIndex); return; } if (groupIndex < 0 || groupIndex > groupCount - 1) { groupIndex = groupCount - 1; } GQuery optgroup = optgroupList.eq(groupIndex); OptionElement option = Document.get().createOptionElement(); setOptionText(option, item, dir); option.setValue(value); int itemCount = optgroup.children().size(); if (itemIndex < 0 || itemIndex > itemCount - 1) { optgroup.append(option); } else { GQuery before = optgroup.children().eq(itemIndex); before.before(option); } }
From source file:org.otalo.ao.client.widget.chlist.gwt.ChosenListBox.java
License:Apache License
/** * Adds an item to the an optgroup of the list box. If no optgroup exists, * the item will be add at the end ot the list box. * * @param item the text of the item to be added * @param value the value of the item to be added * @param itemIndex the index inside the optgroup at which to insert the item * @param groupIndex the index of the optGroup where the item will be inserted *//*from w w w. j a v a2s . c om*/ public void insertItemToGroup(String item, Direction dir, String value, int groupIndex, int itemIndex) { 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 (groupIndex < 0 || groupIndex > groupCount - 1) { groupIndex = groupCount - 1; } GQuery optgroup = optgroupList.eq(groupIndex); OptionElement option = Document.get().createOptionElement(); setOptionText(option, item, dir); option.setValue(value); int itemCount = optgroup.children().size(); if (itemIndex < 0 || itemIndex > itemCount - 1) { optgroup.append(option); } else { GQuery before = optgroup.children().eq(itemIndex); before.before(option); } }