@Override public void renderFromLocation(List<AmtrakCascadesStationItem> stations) { fromLocation.clear(); if (!isLocationEnabled()) { fromLocation.addItem("Select your point of origin"); fromLocation.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true); } for (AmtrakCascadesStationItem station: stations) { fromLocation.addItem(station.getStationName(), station.getStationCode()); } int stationIndex = 0; if (isLocationEnabled()) { Collections.sort(stations, AmtrakCascadesStationItem.stationDistanceComparator); AmtrakCascadesStationItem closestStation = stations.get(0); Collections.sort(stations, AmtrakCascadesStationItem.stationNameComparator); stationIndex = stations.indexOf(closestStation); } fromLocation.setSelectedIndex(stationIndex); }
/** * Inserts an item into the list box, specifying its direction and an initial value for the item. If the index is less than zero, or greater than or equal * to the length of the list, then the item will be appended to the end of the list. * * @param item the text of the item to be inserted * @param dir the item's direction. If {@code null}, the item is displayed in the widget's overall direction, or, if a direction estimator has been set, in * the item's estimated direction. * @param value the item's value, to be submitted if it is part of a {@link FormPanel}. * @param index the index at which to insert it */ public void insertItem(String item, Direction dir, String value, int index) { SelectElement select = getSelectElement(); OptionElement option = Document.get().createOptionElement(); setOptionText(option, item, dir); option.setValue(value); int itemCount = select.getLength(); if (index < 0 || index > itemCount) { index = itemCount; } if (index == itemCount) { select.add(option, null); } else { OptionElement before = select.getOptions().getItem(index); select.add(option, before); } }
@SuppressWarnings("unchecked") @Override public void onBrowserEvent(Context context, Element parent, T value, NativeEvent event, ValueUpdater<T> valueUpdater) { super.onBrowserEvent(context, parent, value, event, valueUpdater); String type = event.getType(); if (BrowserEvents.CHANGE.equals(type)) { Object key = context.getKey(); SelectElement select = parent.getFirstChild().cast(); T newValue = getValueAtIndex((K) key, select.getSelectedIndex()); setViewData(key, newValue); finishEditing(parent, newValue, key, valueUpdater); if (valueUpdater != null) { valueUpdater.update(newValue); } } }
@Override public void onBrowserEvent(Context context, Element parent, T value, NativeEvent event, ValueUpdater<T> valueUpdater) { super.onBrowserEvent(context, parent, value, event, valueUpdater); String type = event.getType(); if (BrowserEvents.CHANGE.equals(type)) { Object key = context.getKey(); SelectElement select = parent.getFirstChild().cast(); T newValue = options.get(select.getSelectedIndex()); //setViewData(key, newValue); finishEditing(parent, newValue, key, valueUpdater); if (valueUpdater != null) { valueUpdater.update(newValue); } } }
@Override public void insertItem(String item, Direction dir, String value, int index) { SelectElement select = getElement().cast(); OptionElement option = Document.get().createOptionElement(); setOptionText(option, item, dir); option.setValue(value); option.setTitle(item); int itemCount = select.getLength(); if (index < 0 || index > itemCount) { index = itemCount; } if (index == itemCount) { select.add(option, null); } else { OptionElement before = select.getOptions().getItem(index); select.add(option, before); } }
@Override public void onBrowserEvent(final Context context, final Element parent, final String value, final NativeEvent event, final ValueUpdater<String> valueUpdater) { super.onBrowserEvent(context, parent, value, event, valueUpdater); final String type = event.getType(); if ("change".equals(type)) { final Object key = context.getKey(); final SelectElement select = parent.getFirstChild().cast(); final String newValue = options.get(select.getSelectedIndex()); setViewData(key, newValue); finishEditing(parent, newValue, key, valueUpdater); if (valueUpdater != null) { valueUpdater.update(newValue); } } }
@Override public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) { super.onBrowserEvent(context, parent, value, event, valueUpdater); String type = event.getType(); if (BrowserEvents.CHANGE.equals(type)) { Object key = context.getKey(); SelectElement select = parent.getFirstChild().cast(); String newValue = options.get(select.getSelectedIndex()); setViewData(key, newValue); finishEditing(parent, newValue, key, valueUpdater); if (valueUpdater != null) { valueUpdater.update(newValue); } } }
private OptionElement createChildOption(Document document, SelectElement select, String value, String label) { OptionElement option = document.createOptionElement(); option.setValue(value); option.setInnerText(label); select.add(option, null); return option; }
private void setupLocaleSelect() { final SelectElement select = (SelectElement) Document.get().getElementById(LANG_ELEMENT_ID); String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName(); String[] localeNames = LocaleInfo.getAvailableLocaleNames(); for (String locale : localeNames) { if (!DEFAULT_LOCALE.equals(locale)) { String displayName = LocaleInfo.getLocaleNativeDisplayName(locale); OptionElement option = Document.get().createOptionElement(); option.setValue(locale); option.setText(displayName); select.add(option, null); if (locale.equals(currentLocale)) { select.setSelectedIndex(select.getLength() - 1); } } } EventDispatcherPanel.of(select).registerChangeHandler(null, new WaveChangeHandler() { @Override public boolean onChange(ChangeEvent event, Element context) { UrlBuilder builder = Location.createUrlBuilder().setParameter( LOCALE_URLBUILDER_PARAMETER, select.getValue()); Window.Location.replace(builder.buildString()); localeService.storeLocale(select.getValue()); return true; } }); }
@Override public Integer getData(final SelectElement input, String attribute) throws ConversionException { String integerString = input.getValue().trim(); if (!integerString.matches(REGEX_INTEGER)) { String message = "Expected an integer, but was " + integerString; throw new ConversionException(message); } return Integer.parseInt(integerString); }
@Override public Double getData(final SelectElement selectElement, String attribute) throws ConversionException { String doubleString = selectElement.getValue().trim(); if (!doubleString.matches(REGEX_DECIMAL)) { String message = "Expected a floating point number, but was " + doubleString; throw new ConversionException(message); } return Double.parseDouble(doubleString); }
@Override public Float getData(final SelectElement input, String attribute) throws ConversionException { String floatString = input.getValue().trim(); if (!floatString.matches(REGEX_DECIMAL)) { String message = "Expected a floating point number, but was " + floatString; throw new ConversionException(message); } return Float.parseFloat(floatString); }
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); 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); }
protected void showHint(String hint) { if (hintEnabled) { SelectElement selectElement = SelectElement.as(listBox.getElement()); NodeList<OptionElement> options = selectElement.getOptions(); options.getItem(0).setText(hint); } else { listBox.addItem(hint); hintEnabled = true; } }
@Override public void setItemTitle(int index, String title) { SelectElement selectElement = SelectElement.as(listBox.getElement()); NodeList<OptionElement> options = selectElement.getOptions(); OptionElement optionElement = options.getItem(index + (hintEnabled ? 1: 0)); if (optionElement != null) { optionElement.setTitle(title); } }
private SelectElement getSelectElement() { return getElement().cast(); }
public void addItemWithStyle(String item, String value) { final SelectElement select = getElement().cast(); final OptionElement option = Document.get().createOptionElement(); option.setText(item); option.setValue(value); option.setClassName(styleName); select.add(option, null); }
@Override public void onBrowserEvent(Context context, Element parent, Pair<Long, String> value, NativeEvent event, ValueUpdater<Pair<Long, String>> valueUpdater) { super.onBrowserEvent(context, parent, value, event, valueUpdater); String type = event.getType(); if ("change".equals(type)) { Object key = context.getKey(); SelectElement select = parent.getFirstChild().cast(); Pair<Long, String> newValue = options.get(select.getSelectedIndex()); setViewData(key, newValue); finishEditing(parent, newValue, key, valueUpdater); if (valueUpdater != null) { valueUpdater.update(newValue); } } }
@Override public void onBrowserEvent(Context context, Element parent, ComboItem value, NativeEvent event, ValueUpdater<ComboItem> valueUpdater) { super.onBrowserEvent(context, parent, value, event, valueUpdater); String type = event.getType(); if ("change".equals(type)) { Object key = context.getKey(); SelectElement select = parent.getFirstChild().cast(); ComboItem newValue = options.get(select.getSelectedIndex()); setViewData(key, newValue); finishEditing(parent, newValue, key, valueUpdater); if (valueUpdater != null) { valueUpdater.update(newValue); } } }
private void setupLocaleSelect() { final SelectElement select = (SelectElement) Document.get().getElementById("lang"); String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName(); String[] localeNames = LocaleInfo.getAvailableLocaleNames(); for (String locale : localeNames) { if (!DEFAULT_LOCALE.equals(locale)) { String displayName = LocaleInfo.getLocaleNativeDisplayName(locale); OptionElement option = Document.get().createOptionElement(); option.setValue(locale); option.setText(displayName); select.add(option, null); if (locale.equals(currentLocale)) { select.setSelectedIndex(select.getLength() - 1); } } } EventDispatcherPanel.of(select).registerChangeHandler(null, new WaveChangeHandler() { @Override public boolean onChange(ChangeEvent event, Element context) { UrlBuilder builder = Location.createUrlBuilder().setParameter( "locale", select.getValue()); Window.Location.replace(builder.buildString()); localeService.storeLocale(select.getValue()); return true; } }); }
@Override public void renderToLocation(List<AmtrakCascadesStationItem> stations) { toLocation.clear(); toLocation.addItem("Select your destination (Optional)"); toLocation.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true); for (AmtrakCascadesStationItem station: stations) { toLocation.addItem(station.getStationName(), station.getStationCode()); } toLocation.setSelectedIndex(0); }
public MultiValueTagsInput(final Collection<? extends Dataset<T>> datasets) { SelectElement tagsSelect = Document.get().createSelectElement(); tagsSelect.setMultiple(true); tagsSelect.setAttribute("data-role", "tagsinput"); setElement(tagsSelect); setDatasets(datasets); }
private SelectElement createSelect(Document document, String className) { SelectElement result = document.createSelectElement(); result.addClassName(className); return result; }
private SelectElement createChildSelect(Document document, Element parent, String nameId) { SelectElement result = createSelect(document, nameId); parent.appendChild(result); return result; }
public OptionAdapter(SelectElement parentElement) { super(parentElement); }
@SuppressWarnings("unchecked") @Override public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) { super.onBrowserEvent(context, parent, value, event, valueUpdater); String type = event.getType(); if ("change".equals(type)) { Object key = context.getKey(); SelectElement select = parent.getFirstChild().cast(); String newValue = options.get(select.getSelectedIndex()); // Get the prior value of the view data. String lastValue = getViewData(key); boolean changed = true; if ( lastValue != null && newValue != null && lastValue.equals(newValue) ) { changed = false; } if ( validationPredicate != null && !validationPredicate.isValid(newValue, (T) key) ) { // either there is no change in value // or the validation failed. // restore drop-down to prior value... newValue = lastValue; changed = false; } // update backing map with whatever we ended up with... setViewData(key, newValue); // redraw our parent with the value we ended up with... SafeHtmlBuilder sb = new SafeHtmlBuilder(); render(context, newValue, sb); parent.setInnerHTML(sb.toSafeHtml().asString()); // remove keyboard focus on this element... finishEditing(parent, newValue, key, valueUpdater); if ( changed ) { // do value-change action... if (valueUpdater != null) { valueUpdater.update(newValue); } } } }
protected SelectElement getSelectElement() { return listBox.getElement().cast(); }
@Override public String getData(final SelectElement gqueryInput, String attribute) { return gqueryInput.getValue(); }
private void registerTargetAdapters() { // CheckBoxBooleanAdapter register(GQuery.class, /*Boolean.class,*/ new GQueryBooleanAdapter(), AssertFalse.class, AssertTrue.class, Checked.class); register(InputElement.class, /*Boolean.class,*/ new InputElementBooleanAdapter(), AssertFalse.class, AssertTrue.class, Checked.class); // SpinnerIndexAdapter register(GQuery.class, /*Integer.class,*/ new GQueryIntegerAdapter(), Select.class); register(SelectElement.class, /*Integer.class,*/ new SelectElementIntegerAdapter(), Select.class); // TextViewDoubleAdapter register(GQuery.class, /*Double.class,*/ new GQueryDoubleAdapter(), DecimalMax.class, DecimalMin.class); register(InputElement.class, /*Double.class,*/ new InputElementDoubleAdapter(), DecimalMax.class, DecimalMin.class); // TextViewIntegerAdapter register(GQuery.class, /*Integer.class,*/ new GQueryIntegerAdapter(), Max.class, Min.class); register(InputElement.class, /*Integer.class,*/ new InputElementIntegerAdapter(), Max.class, Min.class); // TextViewStringAdapter register(GQuery.class, /*String.class,*/ new GQueryStringAdapter(), ConfirmEmail.class, ConfirmPassword.class, CreditCard.class, Digits.class, Domain.class, Email.class, FutureDate.class, IpAddress.class, Isbn.class, Length.class, Required.class, RequiredIfAttributeNotEmpty.class, Password.class, PastDate.class, Pattern.class, Url.class); register(InputElement.class, /*String.class,*/ new InputElementStringAdapter(), ConfirmEmail.class, ConfirmPassword.class, CreditCard.class, Digits.class, Domain.class, Email.class, FutureDate.class, IpAddress.class, Isbn.class, Length.class, Required.class, RequiredIfAttributeNotEmpty.class, Password.class, PastDate.class, Pattern.class, Url.class); }
public OptionElement getItem(int aIndex) { checkIndex(aIndex); return getElement().<SelectElement> cast().getOptions().getItem(aIndex); }
public String getItemStyleName(int aIndex) { checkIndex(aIndex); OptionElement option = getElement().<SelectElement> cast().getOptions().getItem(aIndex); return option.getClassName(); }
public void setItemStyleName(int aIndex, String aValue) { checkIndex(aIndex); OptionElement option = getElement().<SelectElement> cast().getOptions().getItem(aIndex); option.setClassName(aValue); }
protected SelectElement getSelectElement() { return getElement().cast(); }
public static void addListPreference(Element panel, final SharedPreferences sharedPrefs, final String key, String label, String summary, final String[] values, String[] labels, String defaultValue) { String value = sharedPrefs.getString(key, defaultValue); Element inputLabel = DOM.createLabel(); inputLabel.addClassName(Res.R.style().preferencesElement()); final Element listBoxE = DOM.createSelect(); listBoxE.addClassName(Res.R.style().preferencesListBox()); listBoxE.addClassName(Res.R.style().materialSelect()); int selectedPosition = MobialiaUtil.arrayPosition(values, value); int i = 0; for (String text : labels) { Element optionE = DOM.createOption(); optionE.setInnerHTML(text); if (i++ == selectedPosition) { optionE.setPropertyString("selected", "selected"); } listBoxE.appendChild(optionE); } Event.setEventListener(listBoxE, new EventListener() { @Override public void onBrowserEvent(Event event) { SharedPreferences.Editor editor = sharedPrefs.edit(); editor.putString(key, values[((SelectElement) listBoxE).getSelectedIndex()]); editor.commit(); } }); Event.sinkEvents(listBoxE, Event.ONCHANGE); inputLabel.appendChild(listBoxE); Element labelG = DOM.createDiv(); labelG.addClassName(Res.R.style().preferencesLabel()); labelG.setInnerHTML(label); inputLabel.appendChild(labelG); Element summaryG = DOM.createDiv(); summaryG.addClassName(Res.R.style().preferencesSummary()); summaryG.setInnerHTML(summary); inputLabel.appendChild(summaryG); panel.appendChild(inputLabel); }
public void setSelection(int index) { SelectElement.as(element).setSelectedIndex(index); }
public int getSelectedItemPosition() { int i = SelectElement.as(element).getSelectedIndex(); return (i < 0 ? 0 : i); }