List of usage examples for com.google.gwt.query.client GQuery size
public int size()
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 ww. j a v a2 s .c o 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
/** * 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 w w w . j a v a 2 s . c om*/ * @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:gwtquery.samples.client.GwtQueryDemoModule.java
License:Apache License
public void onModuleLoad() { // Ask GWT compiler to generate our interface final Slide s = GWT.create(Slide.class); final GQuery slides = $(s.allSlides()); // we initially hide all slides and bullets slides.hide().eq(0).as(Effects).clipAppear(); $(s.allSlideBullets()).hide();//from ww w .j a v a 2s. c o m // add onclick handler to body element $(slides).click(new Function() { // two state variables to note current slide being shown // and current bullet int curSlide = 0; int curBullets = 0; // query and store all bullets of current slide GQuery bullets = $(s.slideBulletsCtx(slides.get(curSlide))); public boolean f(Event e) { // onclick, if not all bullets shown, show a bullet and increment if (curBullets < bullets.size()) { bullets.eq(curBullets++).as(Effects).fadeIn(Speed.SLOW); } else { // all bullets shown, hide them and current slide bullets.hide(); // move to next slide, checking for wrap around int lastSlide = curSlide++; if (curSlide == slides.size()) { curSlide = 0; } // query for new set of bullets, and show next slide curBullets = 0; bullets = $(s.slideBulletsCtx(slides.get(curSlide))); // Hide the last slide and show the next when the effects finishes slides.eq(lastSlide).as(Effects).fadeOut(new Function() { public void f(Element e) { slides.eq(curSlide).as(Effects).clipAppear(); } }); } return true; } }); }
From source file:org.kaaproject.avro.ui.gwt.client.widget.choosen.AvroChoosenListBox.java
License:Apache License
public static void updateChoosenListBoxMaxTextWidth(ChosenListBox box, int width, TextWidthFunction function) { ChosenImpl impl = $(box.getElement()).data(CHOSEN_DATA_KEY, ChosenImpl.class); if (impl != null) { GQuery results = impl.getContainer().find("li." + avroChoosenResources.css().activeResult(), "li." + avroChoosenResources.css().resultSelected()); GQuery searchchoiceSpan = impl.getContainer().find("li." + avroChoosenResources.css().searchChoice()) .find("span"); results = results.add(searchchoiceSpan); results = results.add($(box.getElement()).find("option")); for (int i = 0; i < results.size(); i++) { Element e = results.get(i); GQuery ge = $(e);// www . j a v a2 s .c om ge.text(function.updateTextWidth(ge.text(), width)); } } }
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 ww.jav a 2 s . com 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); } }