All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.extjs.gxt.ui.client.widget.form.SimpleComboBox Maven / Gradle / Ivy

There is a newer version: 2.3.1-gwt22
Show newest version
/*
 * Sencha GXT 2.3.1 - Sencha for GWT
 * Copyright(c) 2007-2013, Sencha, Inc.
 * [email protected]
 * 
 * http://www.sencha.com/products/gxt/license/
 */
 package com.extjs.gxt.ui.client.widget.form;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.store.ListStore;

/**
 * A ComboBox subclass that supports any simple data types.
 * SimpleComboBox creates and manages a ListStore of
 * SimpleComboBox instances. You can call
 * {@link SimpleComboValue#getValue()} to obtain the simple value.
 * 
 * 

 * SimpleComboBox combo = new SimpleComboBox();
 * combo.add("Darrell");
 * combo.add("Maro");
 * combo.add("Lia");
 * combo.setSimpleValue("Maro");
 * 
* * @param the data type */ public class SimpleComboBox extends ComboBox> { /** * Creates a new simple combo box. */ public SimpleComboBox() { setDisplayField("value"); setStore(new ListStore>()); } /** * Adds the values to the list. * * @param values the values */ @SuppressWarnings({"unchecked", "rawtypes"}) public void add(List values) { List list = new ArrayList(); for (T t : values) { list.add(new SimpleComboValue(t)); } store.add(list); } /** * Adds the value. * * @param value the value */ public void add(T value) { store.add(new SimpleComboValue(value)); } /** * Returns the model for the given value. * * @param value the value * @return the corresponding model for the value */ public SimpleComboValue findModel(T value) { SimpleComboValue val = null; for (SimpleComboValue c : store.getModels()) { if (c.getValue().equals(value)) { val = c; break; } } return val; } /** * Returns the selected index. * * @return the index or -1 if no selection */ public int getSelectedIndex() { SimpleComboValue c = getValue(); if (c != null) { return store.indexOf(c); } return -1; } /** * Returns the simple value. * * @return the value */ @SuppressWarnings("unchecked") public T getSimpleValue() { SimpleComboValue c = getValue(); if (c != null) { return c. get("value"); } try { return (T) getRawValue(); } catch (Exception e) { return null; } } /** * Removes the value. * * @param value the value */ public void remove(T value) { for (SimpleComboValue c : store.getModels()) { if (c.getValue().equals(value)) { store.remove(c); } } } /** * Removes all the values. */ public void removeAll() { store.removeAll(); } /** * Sets the combo value. * * @param value the value */ public void setSimpleValue(T value) { SimpleComboValue c = findModel(value); if (c != null) { setValue(c); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy