Example usage for com.google.gwt.query.client GQuery eq

List of usage examples for com.google.gwt.query.client GQuery eq

Introduction

In this page you can find the example usage for com.google.gwt.query.client GQuery eq.

Prototype

public GQuery eq(int pos) 

Source Link

Document

Reduce GQuery to element in the specified position.

Usage

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.//ww  w.  java  2 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.
 * /*  w w  w  .  j  ava  2  s  . c  o 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:gwtquery.plugins.enhance.client.gwt.TabPanelWidgetFactory.java

License:Apache License

public TabPanel create(Element e) {
    TabPanel tabPanel = new TabPanel();

    GQuery tabs = $(options.getTabSelector(), e);
    GQuery titles = $(options.getTitleSelector(), e);

    for (int i = 0; i < tabs.length(); i++) {
        GQuery tab = tabs.eq(i);
        GQuery title = titles.eq(i);/*from w w  w.  j a va 2  s .  c  om*/

        Widget tabWidget = tab.widget();
        if (tabWidget == null) {
            tabWidget = new WidgetsHtmlPanel(tab.get(0));
        }

        tabPanel.add(tabWidget, title.get(0) != null ? title.text() : "Tab " + (i + 1));

    }
    if (tabs.length() > 0) {
        tabPanel.selectTab(0);
    }

    WidgetsUtils.replaceOrAppend(e, tabPanel);
    return tabPanel;
}

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   w w w. ja v  a 2  s  . 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:jdramaix.client.ShowMorePagerPanel.java

License:Apache License

private void update() {
    int currentTopScroll = scrollable.getVerticalScrollPosition();
    int bottomScroll = $scrollable.offset().top + $scrollable.innerHeight() + currentTopScroll;

    JsObjectArray<GQuery> pastElements = JsObjectArray.create();
    JsObjectArray<GQuery> futureElements = JsObjectArray.create();

    // update current elements
    GQuery pastElement = $("." + resources.style().item() + ":not(." + resources.style().future() + ")",
            scrollable);//from w  w  w .  ja  v a2 s.  c om
    for (int i = pastElement.length() - 1; i > 0; i--) {
        GQuery element = pastElement.eq(i);

        if (isPast(element, bottomScroll)) {
            break;
        } else {
            futureElements.add(element);
        }
    }

    GQuery futureElement = $("." + resources.style().future(), scrollable);
    for (int i = 0; i < futureElement.length(); i++) {
        GQuery element = futureElement.eq(i);
        if (isPast(element, bottomScroll)) {
            pastElements.add(element);
        } else {
            break;
        }
    }

    // avoid browser reflows
    for (int i = 0; i < pastElements.length(); i++) {
        pastElements.get(i).removeClass(resources.style().future());
    }

    for (int i = 0; i < futureElements.length(); i++) {
        futureElements.get(i).addClass(resources.style().future());
    }
}

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. j  av a2  s  .co m*/
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);
    }

}