Example usage for com.google.gwt.dom.client SelectElement as

List of usage examples for com.google.gwt.dom.client SelectElement as

Introduction

In this page you can find the example usage for com.google.gwt.dom.client SelectElement as.

Prototype

public static SelectElement as(Element elem) 

Source Link

Document

Assert that the given Element is compatible with this class and automatically typecast it.

Usage

From source file:com.agnie.gwt.common.client.widget.ListBox.java

License:Open Source License

/**
 * To set ListItem Label as it's Title(tooltip) for each ListItem.
 *//*w  ww. jav a2s  .co m*/
private void setTitle() {
    SelectElement selectElement = SelectElement.as(this.getElement());
    NodeList<OptionElement> options = selectElement.getOptions();
    for (int i = 0; i < options.getLength(); i++) {
        T t = this.list.get(i);
        options.getItem(i).setTitle(gt.getText(t));
    }
}

From source file:com.arcbees.chosen.client.Chosen.java

License:Apache License

public Chosen chosen(final ChosenOptions options, final EventBus eventBus) {
    ChosenImplFactory factory = new ChosenImplFactory();

    for (Element e : elements()) {

        if ("select".equalsIgnoreCase(e.getTagName()) && !$(e).hasClass("chzn-done")) {
            SelectElement selectElement = SelectElement.as(e);
            ChosenImpl impl = factory.createChosenImpl(selectElement, options);
            impl.init(selectElement, options, eventBus);
            $(e).data(CHOSEN_DATA_KEY, impl);
        }//  w w  w.j  a  v  a  2s  . co m
    }
    return this;
}

From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java

License:Apache License

/**
 * Return the values of all selected options in an array.
 * Usefull to know which options are selected in case of multiple ChosenListBox
 *
 * @return the values of all selected options in an array
 *//*from   www  .  j ava  2  s  . c  om*/
public String[] getValues() {
    ChosenImpl impl = getChosenImpl();

    if (impl != null) {
        List<String> selectedValues = impl.getSelectedValues();
        return selectedValues.toArray(new String[selectedValues.size()]);
    } else {
        JsArrayString values = JsArrayString.createArray().cast();
        NodeList<OptionElement> options = SelectElement.as(getElement()).getOptions();
        for (int i = 0; i < options.getLength(); i++) {
            OptionElement option = options.getItem(i);
            if (option.isSelected()) {
                values.push(option.getValue());
            }
        }

        String[] result = new String[values.length()];
        for (int i = 0; i < values.length(); i++) {
            result[i] = values.get(i);
        }

        return result;
    }
}

From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java

License:Apache License

/**
 * Insert a group to the list box.//from   ww w  .  j  a  v a  2s.  c o 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.google.gerrit.client.change.ChangeScreen.java

License:Apache License

private void renderDiffBaseListBox(ChangeInfo info) {
    JsArray<RevisionInfo> list = info.revisions().values();
    RevisionInfo.sortRevisionInfoByNumber(list);
    int selectedIdx = list.length();
    for (int i = list.length() - 1; i >= 0; i--) {
        RevisionInfo r = list.get(i);/*w ww.ja  va  2 s .  c o m*/
        diffBase.addItem(r.id() + ": " + r.name().substring(0, 6), r.id());
        if (r.name().equals(revision)) {
            SelectElement.as(diffBase.getElement()).getOptions().getItem(diffBase.getItemCount() - 1)
                    .setDisabled(true);
        }
        if (base.isPatchSet() && base.asPatchSetId().get() == r._number()) {
            selectedIdx = diffBase.getItemCount() - 1;
        }
    }

    RevisionInfo rev = info.revisions().get(revision);
    JsArray<CommitInfo> parents = rev.commit().parents();
    if (parents.length() > 1) {
        diffBase.addItem(Util.C.autoMerge(), DiffObject.AUTO_MERGE);
        for (int i = 0; i < parents.length(); i++) {
            int parentNum = i + 1;
            diffBase.addItem(Util.M.diffBaseParent(parentNum), String.valueOf(-parentNum));
        }

        if (base.isParent()) {
            selectedIdx = list.length() + base.getParentNum();
        }
    } else {
        diffBase.addItem(Util.C.baseDiffItem(), "");
    }

    diffBase.setSelectedIndex(selectedIdx);
}

From source file:com.google.gerrit.client.change.ChangeScreen2.java

License:Apache License

private void renderDiffBaseListBox(ChangeInfo info) {
    JsArray<RevisionInfo> list = info.revisions().values();
    RevisionInfo.sortRevisionInfoByNumber(list);
    int selectedIdx = list.length();
    for (int i = list.length() - 1; i >= 0; i--) {
        RevisionInfo r = list.get(i);/*from  w  w w. jav a2 s.  c  o m*/
        diffBase.addItem(r._number() + ": " + r.name().substring(0, 6), r.name());
        if (r.name().equals(revision)) {
            SelectElement.as(diffBase.getElement()).getOptions().getItem(diffBase.getItemCount() - 1)
                    .setDisabled(true);
        }
        if (base != null && base.equals(String.valueOf(r._number()))) {
            selectedIdx = diffBase.getItemCount() - 1;
        }
    }

    RevisionInfo rev = info.revisions().get(revision);
    JsArray<CommitInfo> parents = rev.commit().parents();
    diffBase.addItem(parents.length() > 1 ? Util.C.autoMerge() : Util.C.baseDiffItem(), "");

    diffBase.setSelectedIndex(selectedIdx);
}

From source file:com.watopi.chosen.client.Chosen.java

License:Open Source License

public Chosen chosen(final ChosenOptions options, final EventBus eventBus) {

    for (Element e : elements()) {

        if ("select".equalsIgnoreCase(e.getTagName()) && !$(e).hasClass("chzn-done")) {

            ChosenImpl impl = GWT.create(ChosenImpl.class);
            impl.init(SelectElement.as(e), options, eventBus);
            $(e).data(CHOSEN_DATA_KEY, impl);

        }// ww w  .ja  v a  2  s.c o m
    }
    return this;
}

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:org.dashbuilder.renderer.client.selector.SelectorDisplayer.java

License:Apache License

protected void populateSelector() {
    listBox.clear();/*  w  w w  .j  av  a2  s .  c  om*/
    final DataColumn firstColumn = dataSet.getColumnByIndex(0);
    final String firstColumnId = firstColumn.getId();
    ColumnSettings columnSettings = displayerSettings.getColumnSettings(firstColumn);
    final String firstColumnName = columnSettings.getColumnName();

    listBox.addItem(
            "- " + SelectorConstants.INSTANCE.selectorDisplayer_select() + " " + firstColumnName + " -");
    SelectElement selectElement = SelectElement.as(listBox.getElement());
    NodeList<OptionElement> options = selectElement.getOptions();

    // Generate the list entries from the current data set
    List<Integer> currentFilter = super.filterIndexes(firstColumnId);
    for (int i = 0; i < dataSet.getRowCount(); i++) {

        Object obj = dataSet.getValueAt(i, 0);
        if (obj == null)
            continue;

        String value = super.formatValue(obj, firstColumn);
        listBox.addItem(value);
        if (currentFilter != null && currentFilter.contains(i)) {
            listBox.setSelectedIndex(i + 1);
        }

        // Generate an option tooltip (only if extra data set columns are defined)
        int ncolumns = getNumberOfColumns(dataSet);
        if (ncolumns > 1) {
            StringBuilder out = new StringBuilder();
            for (int j = 1; j < ncolumns; j++) {
                DataColumn extraColumn = dataSet.getColumnByIndex(j);
                columnSettings = displayerSettings.getColumnSettings(extraColumn);
                String extraColumnName = columnSettings.getColumnName();
                Object extraValue = dataSet.getValueAt(i, j);

                if (extraValue != null) {
                    if (j > 1)
                        out.append("  ");
                    String formattedValue = super.formatValue(extraValue, extraColumn);
                    out.append(extraColumnName).append("=").append(formattedValue);
                }
            }
            OptionElement optionElement = options.getItem(i + 1);
            if (optionElement != null)
                optionElement.setTitle(out.toString());
        }
    }
}

From source file:org.dashbuilder.renderer.client.selector.SelectorDisplayerView.java

License:Apache License

protected void showHint(String hint) {
    if (hintEnabled) {
        SelectElement selectElement = SelectElement.as(listBox.getElement());
        NodeList<OptionElement> options = selectElement.getOptions();
        options.getItem(0).setText(hint);
    } else {//from  w  w  w  . j a va2s  .  com
        listBox.addItem(hint);
        hintEnabled = true;
    }
}