PDA

View Full Version : NumericFilter with property editor type support



diegolovison
21 Oct 2010, 3:04 AM
this filter allow you specifie the number type used when converting a String to a Number instance (defaults to Double).



package com.example.client.widget.grid.filter;

import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.grid.filters.NumericFilter;
import com.extjs.gxt.ui.client.widget.grid.filters.RangeMenu;

public class XNumericFilter extends NumericFilter {

private Class<?> type;

public XNumericFilter(String dataIndex) {
super(dataIndex);

fixPropertyEditorType();
}

/**
* Specifies the number type used when converting a String to a Number
* instance (defaults to Double).
*
* @param type
* the number type (Short, Integer, Long, Float, Double).
*/
public void setPropertyEditorType(Class<?> type) {
this.type = type;
}

private void fixPropertyEditorType() {

final RangeMenu rangeMenu = getRangeMenu();

rangeMenu.addListener(Events.Render, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {

getNumberFieldLt(rangeMenu).setPropertyEditorType(type);
getNumberFieldGt(rangeMenu).setPropertyEditorType(type);
getNumberFieldEq(rangeMenu).setPropertyEditorType(type);
}
});
}

private native NumberField getNumberFieldLt(RangeMenu rangeMenu) /*-{
return rangeMenu.@com.extjs.gxt.ui.client.widget.grid.filters.RangeMenu::lt;
}-*/;

private native NumberField getNumberFieldGt(RangeMenu rangeMenu) /*-{
return rangeMenu.@com.extjs.gxt.ui.client.widget.grid.filters.RangeMenu::gt;
}-*/;

private native NumberField getNumberFieldEq(RangeMenu rangeMenu) /*-{
return rangeMenu.@com.extjs.gxt.ui.client.widget.grid.filters.RangeMenu::eq;
}-*/;

private native RangeMenu getRangeMenu() /*-{
return this.@com.extjs.gxt.ui.client.widget.grid.filters.NumericFilter::rangeMenu;
}-*/;
}