TheBuzzer
7 Oct 2008, 10:43 AM
Well I made a basic combobox which is like simple combobox but it holds a name and a value similer to a dropdown list.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.ottoos.client.Widgets;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
/**
*
* @author dlee
*/
public class BasicComboBox extends ComboBox<BasicComboValue> {
public BasicComboBox() {
setDisplayField("name");
setStore(new ListStore<BasicComboValue>());
}
public void add(String name) {
store.add(new BasicComboValue(name));
}
public void setStoredValue(String value) {
BasicComboValue c = findModel(value);
if (c != null) {
setValue(c);
} else if (!getForceSelection()) {
setValue(new BasicComboValue(value));
}
}
public BasicComboValue findModel(String vendornumber) {
BasicComboValue val = null;
for (BasicComboValue c : store.getModels()) {
if (c.getValue().equals(vendornumber)) {
val = c;
break;
}
}
return val;
}
public String getStoredValue() {
if (getValue() != null) {
return getValue().getValue();
} else if (!getForceSelection()) {
return getRawValue();
} else {
BasicComboValue val = findModel(getRawValue());
if (val != null) {
return val.getValue();
} else {
return null;
}
}
}
@Override
protected void onBlur(ComponentEvent arg0) {
if (getForceSelection()) {
BasicComboValue val = findModel(getRawValue());
if (val != null) {
setValue(val);
fireChangeEvent(focusValue, val);
} else {
doForce();
}
} else {
BasicComboValue val = findModel(getRawValue());
if (val != null) {
setValue(val);
fireChangeEvent(focusValue, val);
} else {
setValue(new BasicComboValue(getRawValue()));
fireChangeEvent(focusValue, getRawValue());
}
}
// super.onBlur(arg0);
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.ottoos.client.Widgets;
import com.extjs.gxt.ui.client.data.BaseModelData;
import java.io.Serializable;
/**
*
* @author dlee
*/
public class BasicComboValue extends BaseModelData implements Serializable {
public BasicComboValue() {
}
public BasicComboValue(String name) {
setName(name);
setValue(name);
}
public BasicComboValue(String name, String value) {
setName(name);
setValue(value);
}
public void setName(String name) {
set("name",name);
}
public String getName() {
return (String)get("name");
}
/**
* Returns the value.
*
* @return the value
*/
public String getValue() {
return (String)get("value");
}
/**
* Sets the value.
*
* @param value the value
*/
public void setValue(String value) {
set("value", value);
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.ottoos.client.Widgets;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
/**
*
* @author dlee
*/
public class BasicComboBox extends ComboBox<BasicComboValue> {
public BasicComboBox() {
setDisplayField("name");
setStore(new ListStore<BasicComboValue>());
}
public void add(String name) {
store.add(new BasicComboValue(name));
}
public void setStoredValue(String value) {
BasicComboValue c = findModel(value);
if (c != null) {
setValue(c);
} else if (!getForceSelection()) {
setValue(new BasicComboValue(value));
}
}
public BasicComboValue findModel(String vendornumber) {
BasicComboValue val = null;
for (BasicComboValue c : store.getModels()) {
if (c.getValue().equals(vendornumber)) {
val = c;
break;
}
}
return val;
}
public String getStoredValue() {
if (getValue() != null) {
return getValue().getValue();
} else if (!getForceSelection()) {
return getRawValue();
} else {
BasicComboValue val = findModel(getRawValue());
if (val != null) {
return val.getValue();
} else {
return null;
}
}
}
@Override
protected void onBlur(ComponentEvent arg0) {
if (getForceSelection()) {
BasicComboValue val = findModel(getRawValue());
if (val != null) {
setValue(val);
fireChangeEvent(focusValue, val);
} else {
doForce();
}
} else {
BasicComboValue val = findModel(getRawValue());
if (val != null) {
setValue(val);
fireChangeEvent(focusValue, val);
} else {
setValue(new BasicComboValue(getRawValue()));
fireChangeEvent(focusValue, getRawValue());
}
}
// super.onBlur(arg0);
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.ottoos.client.Widgets;
import com.extjs.gxt.ui.client.data.BaseModelData;
import java.io.Serializable;
/**
*
* @author dlee
*/
public class BasicComboValue extends BaseModelData implements Serializable {
public BasicComboValue() {
}
public BasicComboValue(String name) {
setName(name);
setValue(name);
}
public BasicComboValue(String name, String value) {
setName(name);
setValue(value);
}
public void setName(String name) {
set("name",name);
}
public String getName() {
return (String)get("name");
}
/**
* Returns the value.
*
* @return the value
*/
public String getValue() {
return (String)get("value");
}
/**
* Sets the value.
*
* @param value the value
*/
public void setValue(String value) {
set("value", value);
}
}