Hi Isomorphic,
as I couldn't get CriteriaEditing (using setCanEditCriterionPredicate, FormItemCanEditCriterionPredicate, setCriterionSetter, FormItemCriterionSetter, setCriterionGetter, FormItemCriterionGetter) to work as expected in my ListGrid, I tried to create a minimal version inside the BuiltInDs sample (using v9.0p_2014-01-14/EVAL Deployment + Jetty+DevMode, whereas my project uses Tomcat+DevMode).
This doesn't work at all, even the breakpoints inside the FormItemCriterionGetter methods are not hit, so I think there might be something wrong here (I'm returning true for hasAdvancedCriteria()).
Also, the items in the SelectItem filter change unpredictably after (not working) filtering on the LifeSpan field.
Could you have a look at this minimal testcase and tell me if there is something wrong here?
I'm using FF26 with Eclipse+DevMode Plugin.
Thank you,
Blama
BuiltInDS.java
ListGridFieldLS.java
as I couldn't get CriteriaEditing (using setCanEditCriterionPredicate, FormItemCanEditCriterionPredicate, setCriterionSetter, FormItemCriterionSetter, setCriterionGetter, FormItemCriterionGetter) to work as expected in my ListGrid, I tried to create a minimal version inside the BuiltInDs sample (using v9.0p_2014-01-14/EVAL Deployment + Jetty+DevMode, whereas my project uses Tomcat+DevMode).
This doesn't work at all, even the breakpoints inside the FormItemCriterionGetter methods are not hit, so I think there might be something wrong here (I'm returning true for hasAdvancedCriteria()).
Also, the items in the SelectItem filter change unpredictably after (not working) filtering on the LifeSpan field.
Could you have a look at this minimal testcase and tell me if there is something wrong here?
I'm using FF26 with Eclipse+DevMode Plugin.
Thank you,
Blama
BuiltInDS.java
Code:
package com.smartgwt.sample.client; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.util.KeyCallback; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.layout.VStack; /** * Entry point classes define <code>onModuleLoad()</code>. */ public class BuiltInDS implements EntryPoint { private VStack vStack; private ListGrid boundList; private ListGridField commonName; private ListGridFieldLS lifeSpan; /** * This is the entry point method. */ public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new KeyCallback() { public void execute(String keyName) { SC.showConsole(); } }); final DataSource ds = DataSource.get("animals"); vStack = new VStack() { { setHeight100(); setWidth100(); setMembersMargin(5); } }; lifeSpan = new ListGridFieldLS("lifeSpan"); commonName = new ListGridField("commonName"); boundList = new ListGrid() { { setDataSource(ds); setShowFilterEditor(true); setWidth("30%"); setHeight("50%"); setFields(lifeSpan, commonName); setAutoFetchData(true); } }; IButton btn = new IButton("Reload") { { addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { vStack.removeMember(boundList); boundList.destroy(); boundList = null; lifeSpan = new ListGridFieldLS("lifeSpan"); commonName = new ListGridFieldCN("commonName"); boundList = new ListGrid() { { setDataSource(ds); setShowFilterEditor(true); setWidth("30%"); setHeight("50%"); setFields(lifeSpan, commonName); setAutoFetchData(true); } }; vStack.addMember(boundList, 0); } }); } }; vStack.addMember(boundList); vStack.addMember(btn); vStack.draw(); } }
Code:
package com.smartgwt.sample.client; import java.util.LinkedHashMap; import com.smartgwt.client.data.AdvancedCriteria; import com.smartgwt.client.data.Criterion; import com.smartgwt.client.types.OperatorId; import com.smartgwt.client.types.TextMatchStyle; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.FormItemCanEditCriterionPredicate; import com.smartgwt.client.widgets.form.FormItemCriterionGetter; import com.smartgwt.client.widgets.form.FormItemCriterionSetter; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.grid.ListGridField; public class ListGridFieldLS extends ListGridField { public ListGridFieldLS(final String name) { super(name); /* * LinkedHashMap<Integer, String> vM = new LinkedHashMap<Integer, String>(); * does not work, Integer/String cast exception. Why? */ LinkedHashMap<String, String> vM = new LinkedHashMap<String, String>(); vM.put("3", "<= 9"); vM.put("8", "<= 9"); vM.put("9", "<= 9"); vM.put("10", "10 - 20"); vM.put("12", "10 - 20"); vM.put("15", "10 - 20"); vM.put("20", "10 - 20"); vM.put("25", ">= 21"); vM.put("30", ">= 21"); vM.put("35", ">= 21"); vM.put("40", ">= 21"); vM.put("50", ">= 21"); vM.put("60", ">= 21"); vM.put("999", ">= 21"); setValueMap(vM); setSortByDisplayField(false); SelectItem filterSelectItem = new SelectItem() { @Override public Boolean hasAdvancedCriteria() { return true; // return super.hasAdvancedCriteria(); } { LinkedHashMap<String, String> fevM = new LinkedHashMap<String, String>(); fevM.put("group1", "<= 9"); fevM.put("group2", "10 - 20"); fevM.put("group3", ">= 21"); setValueMap(fevM); setCriterionGetter(new FormItemCriterionGetter() { @Override public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) { return getCriterion(form, item); } @Override public Criterion getCriterion(DynamicForm form, FormItem item) { String name = item.getName(); Object value = item.getValue(); if (value == null) return null; if (value.toString().equals("group1")) return new Criterion(name, OperatorId.LESS_OR_EQUAL, 9); else if (value.toString().equals("group3")) return new Criterion(name, OperatorId.GREATER_OR_EQUAL, 21); else return new AdvancedCriteria(OperatorId.AND, new Criterion[] { new Criterion(name, OperatorId.GREATER_OR_EQUAL, 10), new Criterion(name, OperatorId.LESS_OR_EQUAL, 20) }); } }); setCriterionSetter(new FormItemCriterionSetter() { @SuppressWarnings("unused") @Override public void setCriterion(DynamicForm form, FormItem item, Criterion criterion) { if (isCriterionValue(criterion, 9)) item.setValue(0); else if (isCriterionValue(criterion, 10, 20)) item.setValue(1); else if (isCriterionValue(criterion, 21)) item.setValue(2); else { // Debug only Boolean hasSubCrit = (criterion.getCriteria() == null); OperatorId oId = criterion.getOperator(); String value = criterion.getValueAsString(); String field = criterion.getFieldName(); } } }); setCanEditCriterionPredicate(new FormItemCanEditCriterionPredicate() { @SuppressWarnings("unused") @Override public boolean canEditCriterion(DynamicForm form, FormItem item, Criterion criterion) { String fieldName = item.getName(); String criteriaField = criterion.getFieldName(); Criterion[] subCriteria = criterion.getCriteria(); boolean result = isFieldCriterion(criterion, fieldName); return false; } }); } private boolean isFieldCriterion(Criterion crit, String... fieldnames) { if (crit.getCriteria() != null && crit.getCriteria().length > 0) return isFieldCriterion(crit.getCriteria(), fieldnames); else { boolean retval = false; for (String fn : fieldnames) retval = retval || fn.equals(crit.getFieldName()); return retval; } } private boolean isFieldCriterion(Criterion[] critArray, String... fieldnames) { boolean retval = true; for (Criterion crit : critArray) retval = retval && isFieldCriterion(crit, fieldnames); return retval; } private boolean isCriterionValue(Criterion crit, Integer... values) { if (crit.getCriteria() != null && crit.getCriteria().length > 0) return isCriterionValue(crit.getCriteria(), values); else { boolean retval = false; for (Integer val : values) retval = retval || val.equals(crit.getValueAsInt()); return retval; } } private boolean isCriterionValue(Criterion[] critArray, Integer... values) { boolean retval = true; for (Criterion crit : critArray) retval = retval && isCriterionValue(crit, values); return retval; } }; setFilterEditorProperties(filterSelectItem); } };