Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    PickListCriteria ignored for ListGridEditorCustomizer

    1. SmartGWT 5.1 power edition - v9.1p_2014-06-24/PowerEdition Deployment 2014-06-24
    2. Google Chrome Version 49.0.2623.87 (64-bit)
    PickListCriteria that has been defined on ListGrid editorType via the ListGridEditorCustomizer is not taken into account when there is also a pickListCriteria defined on the editorType of the DataSourceField.
    In our usecase these criteria need to be different:
    • ListGrid: filter out inactive records in order to be able to only select active records
    • DataSourceField: allow using the FilterBuilder with inactive records
    If you could fix this problem or find a workaround, this would be highly appreciated.

    Test case:
    Code:
    package test.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.AdvancedCriteria;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.types.OperatorId;
    import com.smartgwt.client.widgets.Button;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.FilterBuilder;
    import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridEditorContext;
    import com.smartgwt.client.widgets.grid.ListGridEditorCustomizer;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class Test implements EntryPoint {
    
        /**
         * This is the entry point method.
         */
    
        public void onModuleLoad() {
            VLayout vlayout = new VLayout();
            
            vlayout.setWidth100();
            vlayout.setHeight100();
    
            // Setting picklist criteria on datasource editor type, in order to
            // be able to filter on both active and inactive records in the FilterBuilder
            ContentDS.getInstance().getField("cntn_fk_contentType").setEditorProperties(createContentTypeCombobox(new Criteria()));
    
            Button button = new Button("editFilter");
            vlayout.addMember(button);
            button.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    FilterBuilder filterBuilder = new FilterBuilder();
                    filterBuilder.setDataSource(ContentDS.getInstance());
                    Window window = new Window();
                    window.setWidth(800);
                    window.setHeight(300);
                    window.addItem(filterBuilder);
                    window.show();
                }
            });
    
            ListGrid listGrid = new ListGrid();
            listGrid.setCanEdit(true);
            listGrid.setAutoFetchData(true);
            listGrid.setDataSource(ContentDS.getInstance());
            listGrid.setFields(new ListGridField("cntn_id"), new ListGridField("cntn_fk_contentType"));
            listGrid.setEditorCustomizer(new ListGridEditorCustomizer() {
                @Override
                public FormItem getEditor(ListGridEditorContext context) {
                    if ("cntn_fk_contentType".equals(context.getEditField().getName())) {
                        // Setting picklist criteria on listGrid editor type, in order to
                        // be able to filter only active records
                        return createContentTypeCombobox(new AdvancedCriteria("cntp_active", OperatorId.EQUALS, true));
                    } else {
                        return context.getDefaultProperties();
                    }
                }
            });
            
            vlayout.addMember(listGrid);
            
            vlayout.draw();
        }
    
        private ComboBoxItem createContentTypeCombobox(Criteria criteria) {
            ComboBoxItem item = new ComboBoxItem("cntn_fk_contentType", "cntn_fk_contentType");
            item.setOptionDataSource(ContentTypeDS.getInstance());
            item.setPickListFields(new ListGridField("cntp_pk"), new ListGridField("cntp_active"));
            item.setPickListCriteria(criteria);
            return item;
        }
    
    }
    First DataSource:
    Code:
    package test.client;
    
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.fields.DataSourceIntegerField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    
    public class ContentDS extends DataSource {
    
        private static ContentDS instance = null;
    
        public static ContentDS getInstance() {
            if (instance == null) {
                instance = new ContentDS("Content");
            }
            return instance;
        }
    
        private ContentDS(String id) {
            setID(id);
            setClientOnly(true);
    
            DataSourceIntegerField pkField = new DataSourceIntegerField("cntn_pk");  
            pkField.setHidden(true);  
            pkField.setPrimaryKey(true);
            
            DataSourceTextField idField = new DataSourceTextField("cntn_id");
            
            DataSourceIntegerField contentTypeField = new DataSourceIntegerField("cntn_fk_contentType");
            
            setFields(pkField, idField, contentTypeField);
            
            setTestData(
                    new ContentRecord(1, "001", 11),
                    new ContentRecord(2, "002", 11),
                    new ContentRecord(3, "003", 22),
                    new ContentRecord(4, "004", 33));
        }
        
        private class ContentRecord extends Record {
            public ContentRecord(Integer pk, String name, Integer contentType) {
                setAttribute("cntn_pk", pk);
                setAttribute("cntn_id", name);
                setAttribute("cntn_fk_contentType", contentType);
            }        
        }
    }
    Second DataSource:
    Code:
    package test.client;
    
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.fields.DataSourceBooleanField;
    import com.smartgwt.client.data.fields.DataSourceIntegerField;
    
    public class ContentTypeDS extends DataSource {
    
        private static ContentTypeDS instance = null;
    
        public static ContentTypeDS getInstance() {
            if (instance == null) {
                instance = new ContentTypeDS("ContentType");
            }
            return instance;
        }
    
        private ContentTypeDS(String id) {
            setID(id);
            setClientOnly(true);
    
            DataSourceIntegerField pkField = new DataSourceIntegerField("cntp_pk");  
            pkField.setPrimaryKey(true);
            
            DataSourceBooleanField activeField = new DataSourceBooleanField("cntp_active");
    
            setFields(pkField, activeField);
            
            setTestData(
                    new ContentRecord(11, true),
                    new ContentRecord(22, true),
                    new ContentRecord(33, false),
                    new ContentRecord(44, false));
        }
    
        private class ContentRecord extends Record {
            public ContentRecord(Integer pk, boolean active) {
                setAttribute("cntp_pk", pk);
                setAttribute("cntp_active", active);
            }        
        }
    }

    #2
    By design, the more specific setting overrides the less specific one.

    If you are trying to *combine* two sets of criteria, setPickListFilterCriteriaFunction() would allow you to do this.

    Comment


      #3
      You could argue it's more specific setting picklistfiltercriteria on a field in the listgrid (via the editorcustomizer) than setting them on the datasourcefield, since there could be multiple listgrids for that datasource.

      We have tried using setPickListFilterCriteriaFunction too (inside the editorCustomizer) however that also gets ignored.

      I can see that this is a very "arbitrary" demo case. However it is the minimal to reproduce our problem. In our application we actually set the criteria on the editorProperties of the listGridField. In the editorCustomizer we return context.getDefaultProperties() for that field (this has the criteria on it). However due to the problem shown in our democase the criteria get ignored. If we do not set editorproperties on the datasource the criteria from the editorproperties of the listgridfield (that go through an editorcustomizer) do not get ignored. If you want we can add an extra reproducing example showing this behaviour tomorrow.
      Last edited by RubenSimoens; 31 Mar 2016, 09:47.

      Comment


        #4
        Are you trying to combine two sets of criteria or not?

        What do you mean setPickListFilterCriteriaFunction "gets ignored"? Please don't just dismiss a suggestion like that without some specifics of what you did and what happened.

        Also, before posting further, make sure you test against the latest patched version.

        Comment


          #5
          I just tried on the latest version and we still have the same issue (was also present in the 4.1 version if I retest it there).

          I'll do my best to make myself clearer:

          Case 1:

          Setup:
          - We set picklistcriteria A on the editorproperties of the datasourcefield
          - We set picklistcriteria B on the formitem returned in the editorcustomizer of the listgrid
          Expected:
          - The editor of the listgridfield is filtered to picklistcriteria B
          Result:
          - The editor of the listgridfield is filtered to picklistcriteria A

          Case 2:

          Setup:
          - We set picklistcriteria A on the editorproperties of the datasourcefield
          - We set picklistcriteria B on the editorproperties of the listgridfield
          - We use an editorcustomizer that always returns Context.getDefaultProperties
          Expected:
          - The editor of the listgridfield is filtered to picklistcriteria B
          Result:
          - The editor of the listgridfield is filtered to picklistcriteria A


          Note that in both cases if we do not set picklistcriteria on the editorproperties of the datasourcefield everything works as expected.

          We do not want to combine picklistcriteria A and B.


          Code for case 1:

          Code:
          package com.genohm.slims.client.gui;
          
          import com.google.gwt.core.client.EntryPoint;
          import com.smartgwt.client.data.AdvancedCriteria;
          import com.smartgwt.client.data.Criteria;
          import com.smartgwt.client.types.OperatorId;
          import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
          import com.smartgwt.client.widgets.form.fields.FormItem;
          import com.smartgwt.client.widgets.grid.ListGrid;
          import com.smartgwt.client.widgets.grid.ListGridEditorContext;
          import com.smartgwt.client.widgets.grid.ListGridEditorCustomizer;
          import com.smartgwt.client.widgets.grid.ListGridField;
          import com.smartgwt.client.widgets.layout.VLayout;
          
          public class Test implements EntryPoint {
          
              public void onModuleLoad() {
                  VLayout vlayout = new VLayout();
                  
                  vlayout.setWidth100();
                  vlayout.setHeight100();
          
                  // Setting picklist criteria on datasource editor type, in order to
                  // be able to filter on both active and inactive records in the FilterBuilder (not demonstrated in this testcase)
                  ContentDS.getInstance().getField("cntn_fk_contentType").setEditorProperties(createContentTypeCombobox(new Criteria()));
          
                  ListGrid listGrid = new ListGrid();
                  listGrid.setCanEdit(true);
                  listGrid.setAutoFetchData(true);
                  listGrid.setDataSource(ContentDS.getInstance());
                  listGrid.setFields(new ListGridField("cntn_id"), new ListGridField("cntn_fk_contentType"));
                  listGrid.setEditorCustomizer(new ListGridEditorCustomizer() {
                      @Override
                      public FormItem getEditor(ListGridEditorContext context) {
                          if ("cntn_fk_contentType".equals(context.getEditField().getName())) {
                              // Setting picklist criteria on listGrid editor type, in order to onle be able to select active ones in the grid
                              return createContentTypeCombobox(new AdvancedCriteria("cntp_active", OperatorId.EQUALS, true));
                          } else {
                              return context.getDefaultProperties();
                          }
                      }
                  });
                  
                  vlayout.addMember(listGrid);
                  
                  vlayout.draw();
              }
          
              private ComboBoxItem createContentTypeCombobox(Criteria criteria) {
                  ComboBoxItem item = new ComboBoxItem("cntn_fk_contentType", "cntn_fk_contentType");
                  item.setOptionDataSource(ContentTypeDS.getInstance());
                  item.setPickListFields(new ListGridField("cntp_pk"), new ListGridField("cntp_active"));
                  item.setPickListCriteria(criteria);
                  return item;
              }
          
          }


          Code for case 2:

          Code:
          package com.genohm.slims.client.gui;
          
          import com.google.gwt.core.client.EntryPoint;
          import com.smartgwt.client.data.AdvancedCriteria;
          import com.smartgwt.client.data.Criteria;
          import com.smartgwt.client.types.OperatorId;
          import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
          import com.smartgwt.client.widgets.form.fields.FormItem;
          import com.smartgwt.client.widgets.grid.ListGrid;
          import com.smartgwt.client.widgets.grid.ListGridEditorContext;
          import com.smartgwt.client.widgets.grid.ListGridEditorCustomizer;
          import com.smartgwt.client.widgets.grid.ListGridField;
          import com.smartgwt.client.widgets.layout.VLayout;
          
          public class Test implements EntryPoint {
          
              public void onModuleLoad() {
                  VLayout vlayout = new VLayout();
                  
                  vlayout.setWidth100();
                  vlayout.setHeight100();
          
                  // Setting picklist criteria on datasource editor type, in order to
                  // be able to filter on both active and inactive records in the FilterBuilder (not demonstrated in this testcase)
                  ContentDS.getInstance().getField("cntn_fk_contentType").setEditorProperties(createContentTypeCombobox(new Criteria()));
          
                  ListGrid listGrid = new ListGrid();
                  listGrid.setCanEdit(true);
                  listGrid.setAutoFetchData(true);
                  listGrid.setDataSource(ContentDS.getInstance());
                  ListGridField contentTypeField = new ListGridField("cntn_fk_contentType");
                  //Setting criteria on the content type editor so we cannot select inactive types in the grid
                  FormItem contentTypeEditorProperties = createContentTypeCombobox(new AdvancedCriteria("cntp_active", OperatorId.EQUALS, true));
                  contentTypeField.setEditorProperties(contentTypeEditorProperties);
                  listGrid.setFields(new ListGridField("cntn_id"), contentTypeField);
                  
                  listGrid.setEditorCustomizer(new ListGridEditorCustomizer() {
                      @Override
                      public FormItem getEditor(ListGridEditorContext context) {
                          return context.getDefaultProperties();
                      }
                  });
                  
                  vlayout.addMember(listGrid);
                  
                  vlayout.draw();
              }
          
              private ComboBoxItem createContentTypeCombobox(Criteria criteria) {
                  ComboBoxItem item = new ComboBoxItem("cntn_fk_contentType", "cntn_fk_contentType");
                  item.setOptionDataSource(ContentTypeDS.getInstance());
                  item.setPickListFields(new ListGridField("cntp_pk"), new ListGridField("cntp_active"));
                  item.setPickListCriteria(criteria);
                  return item;
              }
          
          }

          ContentDs.java
          Code:
          package com.genohm.slims.client.gui;
          
          import com.smartgwt.client.data.DataSource;
          import com.smartgwt.client.data.Record;
          import com.smartgwt.client.data.fields.DataSourceIntegerField;
          import com.smartgwt.client.data.fields.DataSourceTextField;
          
          public class ContentDS extends DataSource {
          
              private static ContentDS instance = null;
          
              public static ContentDS getInstance() {
                  if (instance == null) {
                      instance = new ContentDS("Content");
                  }
                  return instance;
              }
          
              private ContentDS(String id) {
                  setID(id);
                  setClientOnly(true);
          
                  DataSourceIntegerField pkField = new DataSourceIntegerField("cntn_pk");  
                  pkField.setHidden(true);  
                  pkField.setPrimaryKey(true);
                  
                  DataSourceTextField idField = new DataSourceTextField("cntn_id");
                  
                  DataSourceIntegerField contentTypeField = new DataSourceIntegerField("cntn_fk_contentType");
                  
                  setFields(pkField, idField, contentTypeField);
                  
                  setTestData(
                          new ContentRecord(1, "001", 11),
                          new ContentRecord(2, "002", 11),
                          new ContentRecord(3, "003", 22),
                          new ContentRecord(4, "004", 33));
              }
              
              private class ContentRecord extends Record {
                  public ContentRecord(Integer pk, String name, Integer contentType) {
                      setAttribute("cntn_pk", pk);
                      setAttribute("cntn_id", name);
                      setAttribute("cntn_fk_contentType", contentType);
                  }        
              }
          }
          ContentTypeDS.java

          Code:
          package com.genohm.slims.client.gui;
          
          import com.smartgwt.client.data.DataSource;
          import com.smartgwt.client.data.Record;
          import com.smartgwt.client.data.fields.DataSourceBooleanField;
          import com.smartgwt.client.data.fields.DataSourceIntegerField;
          
          public class ContentTypeDS extends DataSource {
          
              private static ContentTypeDS instance = null;
          
              public static ContentTypeDS getInstance() {
                  if (instance == null) {
                      instance = new ContentTypeDS("ContentType");
                  }
                  return instance;
              }
          
              private ContentTypeDS(String id) {
                  setID(id);
                  setClientOnly(true);
          
                  DataSourceIntegerField pkField = new DataSourceIntegerField("cntp_pk");  
                  pkField.setPrimaryKey(true);
                  
                  DataSourceBooleanField activeField = new DataSourceBooleanField("cntp_active");
          
                  setFields(pkField, activeField);
                  
                  setTestData(
                          new ContentRecord(11, true),
                          new ContentRecord(22, true),
                          new ContentRecord(33, false),
                          new ContentRecord(44, false));
              }
          
              private class ContentRecord extends Record {
                  public ContentRecord(Integer pk, boolean active) {
                      setAttribute("cntp_pk", pk);
                      setAttribute("cntp_active", active);
                  }        
              }
          }
          Attached Files
          Last edited by RubenSimoens; 1 Apr 2016, 04:07.

          Comment


            #6
            Any news on this? I hope my examples clarify my point OK.

            Comment


              #7
              We have just applied a fix all the way back to the 4.1p branch which should resolve this issue. Please try the next nightly build (Dated April 8 or above) on 4.1p, 5.1p, 6.0p or 6.1d to see the fix

              Regards
              Isomorphic Software

              Comment


                #8
                Awesome, the fix works! Thanks!

                Comment

                Working...
                X