groupIndex = groupCount - 1;
}
GQuery optgroup = optgroupList.eq(groupIndex);
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);
}