Changes for grid properties and linking datasource to the grid
authorMartin Taal <martin.taal@openbravo.com>
Tue, 14 Dec 2010 07:11:13 +0100
changeset 9112 917bf3aaadc1
parent 9111 1f9e0c090e86
child 9113 84c12a38ee1f
Changes for grid properties and linking datasource to the grid
modules/org.openbravo.client.querylist/src-db/database/sourcedata/AD_REFERENCE.xml
modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListWidgetProvider.java
modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js
--- a/modules/org.openbravo.client.querylist/src-db/database/sourcedata/AD_REFERENCE.xml	Tue Dec 14 06:10:40 2010 +0100
+++ b/modules/org.openbravo.client.querylist/src-db/database/sourcedata/AD_REFERENCE.xml	Tue Dec 14 07:11:13 2010 +0100
@@ -12,6 +12,20 @@
 <!--0FCD269097054C5790CFDC3E9CBEFD21-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
 <!--0FCD269097054C5790CFDC3E9CBEFD21--></AD_REFERENCE>
 
+<!--B36DF126DF5F4077A37F1E5B963AA636--><AD_REFERENCE>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <AD_REFERENCE_ID><![CDATA[B36DF126DF5F4077A37F1E5B963AA636]]></AD_REFERENCE_ID>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <NAME><![CDATA[Grid Properties Reference]]></NAME>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <DESCRIPTION><![CDATA[Reference used to identify grid properties.]]></DESCRIPTION>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <HELP><![CDATA[Reference used to identify grid properties. ]]></HELP>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <AD_MODULE_ID><![CDATA[0A060B2AF1974E8EAA8DB61388E9AECC]]></AD_MODULE_ID>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <ISBASEREFERENCE><![CDATA[N]]></ISBASEREFERENCE>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <PARENTREFERENCE_ID><![CDATA[10]]></PARENTREFERENCE_ID>
+<!--B36DF126DF5F4077A37F1E5B963AA636-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
+<!--B36DF126DF5F4077A37F1E5B963AA636--></AD_REFERENCE>
+
 <!--B5730B21173B4AA9BB44ADAE2660A853--><AD_REFERENCE>
 <!--B5730B21173B4AA9BB44ADAE2660A853-->  <AD_REFERENCE_ID><![CDATA[B5730B21173B4AA9BB44ADAE2660A853]]></AD_REFERENCE_ID>
 <!--B5730B21173B4AA9BB44ADAE2660A853-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml	Tue Dec 14 06:10:40 2010 +0100
+++ b/modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml	Tue Dec 14 07:11:13 2010 +0100
@@ -18,6 +18,27 @@
 <!--3A93E12C289149CCB2CD1ECA2643469C-->  <EM_OBKMO_WIDGET_CLASS_ID><![CDATA[2A32CF26F3F64FE39C7F94E9D82497D1]]></EM_OBKMO_WIDGET_CLASS_ID>
 <!--3A93E12C289149CCB2CD1ECA2643469C--></OBUIAPP_PARAMETER>
 
+<!--3C7A51E5281F418589AEBA8EE8659A1C--><OBUIAPP_PARAMETER>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <OBUIAPP_PARAMETER_ID><![CDATA[3C7A51E5281F418589AEBA8EE8659A1C]]></OBUIAPP_PARAMETER_ID>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <AD_MODULE_ID><![CDATA[0A060B2AF1974E8EAA8DB61388E9AECC]]></AD_MODULE_ID>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <NAME><![CDATA[Grid Properties]]></NAME>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <DESCRIPTION><![CDATA[Grid Properties]]></DESCRIPTION>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <SEQNO><![CDATA[0]]></SEQNO>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <AD_REFERENCE_ID><![CDATA[10]]></AD_REFERENCE_ID>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <AD_REFERENCE_VALUE_ID><![CDATA[B36DF126DF5F4077A37F1E5B963AA636]]></AD_REFERENCE_VALUE_ID>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <COLUMNNAME><![CDATA[dummy]]></COLUMNNAME>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <FIELDLENGTH><![CDATA[0]]></FIELDLENGTH>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <ISFIXED><![CDATA[Y]]></ISFIXED>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <FIXEDVALUE><![CDATA[{canMultiSort: false}]]></FIXEDVALUE>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <EVALUATEFIXEDVALUE><![CDATA[N]]></EVALUATEFIXEDVALUE>
+<!--3C7A51E5281F418589AEBA8EE8659A1C-->  <EM_OBKMO_WIDGET_CLASS_ID><![CDATA[D1E4261099AE4095B2F2DAEE0F7E7784]]></EM_OBKMO_WIDGET_CLASS_ID>
+<!--3C7A51E5281F418589AEBA8EE8659A1C--></OBUIAPP_PARAMETER>
+
 <!--8D90A3CDDBC44282992A9858F16EA9A8--><OBUIAPP_PARAMETER>
 <!--8D90A3CDDBC44282992A9858F16EA9A8-->  <OBUIAPP_PARAMETER_ID><![CDATA[8D90A3CDDBC44282992A9858F16EA9A8]]></OBUIAPP_PARAMETER_ID>
 <!--8D90A3CDDBC44282992A9858F16EA9A8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java	Tue Dec 14 06:10:40 2010 +0100
+++ b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java	Tue Dec 14 07:11:13 2010 +0100
@@ -49,7 +49,7 @@
    * @return the total number of objects
    */
   protected int getCount(Map<String, String> parameters) {
-    return getData(parameters, 0, Integer.MAX_VALUE).size();
+    return getData(parameters, 0, (Integer.MAX_VALUE - 1)).size();
   }
 
   /*
@@ -62,22 +62,22 @@
       int endRow) {
     OBContext.setAdminMode();
     try {
-      // WidgetInstance widgetInstance = OBDal.getInstance().get(WidgetInstance.class,
-      // parameters.get("widgetId"));
+      WidgetInstance widgetInstance = OBDal.getInstance().get(WidgetInstance.class,
+          parameters.get("widgetInstanceId"));
       WidgetClass widgetClass = OBDal.getInstance().get(WidgetClass.class,
           "D1E4261099AE4095B2F2DAEE0F7E7784");
-      WidgetInstance widgetInstance = widgetClass.getOBKMOWidgetInstanceList().get(0);
+      // WidgetInstance widgetInstance = widgetClass.getOBKMOWidgetInstanceList().get(0);
       IncludeIn includeIn = QueryListUtils.IncludeIn.WidgetView;
       List<OBCQL_QueryColumn> columns = QueryListUtils.getColumns(widgetClass
           .getOBCQLWidgetQueryList().get(0), includeIn);
-      Query widgetQuery = OBDal.getInstance().getSession()
-          .createQuery(widgetClass.getOBCQLWidgetQueryList().get(0).getHQL());
+      Query widgetQuery = OBDal.getInstance().getSession().createQuery(
+          widgetClass.getOBCQLWidgetQueryList().get(0).getHQL());
       String[] queryAliases = widgetQuery.getReturnAliases();
       if (startRow > 0) {
         widgetQuery.setFirstResult(startRow);
       }
       if (endRow > startRow) {
-        widgetQuery.setFetchSize(endRow - startRow + 1);
+        widgetQuery.setMaxResults(endRow - startRow + 1);
       }
       String[] params = widgetQuery.getNamedParameters();
       if (params.length > 0) {
@@ -138,15 +138,15 @@
     HashMap<String, Object> parameterValues = new HashMap<String, Object>();
     for (ParameterValue value : widgetInstance
         .getOBUIAPPParameterValueEMObkmoWidgetInstanceIDList()) {
-      parameterValues.put(value.getParameter().getDBColumnName(),
-          ApplicationUtils.getParameterValue(value));
+      parameterValues.put(value.getParameter().getDBColumnName(), ApplicationUtils
+          .getParameterValue(value));
     }
 
     for (Parameter parameter : widgetInstance.getWidgetClass()
         .getOBUIAPPParameterEMObkmoWidgetClassIDList()) {
       if (!parameterValues.containsKey(parameter.getDBColumnName()) && parameter.isFixed()) {
-        parameterValues.put(parameter.getDBColumnName(),
-            ApplicationUtils.getParameterFixedValue(parameters, parameter));
+        parameterValues.put(parameter.getDBColumnName(), ApplicationUtils.getParameterFixedValue(
+            parameters, parameter));
       }
     }
     return parameterValues;
--- a/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListWidgetProvider.java	Tue Dec 14 06:10:40 2010 +0100
+++ b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListWidgetProvider.java	Tue Dec 14 07:11:13 2010 +0100
@@ -21,6 +21,7 @@
 import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.base.exception.OBException;
+import org.openbravo.client.application.Parameter;
 import org.openbravo.client.kernel.KernelConstants;
 import org.openbravo.client.myob.WidgetInstance;
 import org.openbravo.client.myob.WidgetProvider;
@@ -32,10 +33,27 @@
  */
 public class QueryListWidgetProvider extends WidgetProvider {
 
+  private static String GRID_PROPERTIES_REFERENCE = "B36DF126DF5F4077A37F1E5B963AA636";
   private static final Logger log = Logger.getLogger(QueryListWidgetProvider.class);
 
   @Override
   public String generate() {
+    JSONObject gridPropertiesObject = null;
+    for (Parameter parameter : getWidgetClass().getOBUIAPPParameterEMObkmoWidgetClassIDList()) {
+      // fixed parameters are not part of the fielddefinitions
+      if (parameter.getReferenceSearchKey() != null
+          && parameter.getReferenceSearchKey().getId().equals(GRID_PROPERTIES_REFERENCE)) {
+        try {
+          gridPropertiesObject = new JSONObject(parameter.getFixedValue());
+        } catch (Exception e) {
+          // ignore, invalid grid properties
+          log.error("Grid properties parameter " + parameter + " has an illegal format "
+              + e.getMessage(), e);
+        }
+      }
+    }
+    String gridProperties = (gridPropertiesObject == null ? "" : ", gridProperties: "
+        + gridPropertiesObject.toString());
     return "isc.defineClass('"
         + KernelConstants.ID_PREFIX
         + getWidgetClass().getId()
@@ -43,7 +61,8 @@
         + getWidgetClass().getId()
         + "', fields:"
         + QueryListUtils
-            .getWidgetClassFields(getWidgetClass(), QueryListUtils.IncludeIn.WidgetView) + "});";
+            .getWidgetClassFields(getWidgetClass(), QueryListUtils.IncludeIn.WidgetView)
+        + gridProperties + "});";
   }
 
   @Override
@@ -62,6 +81,7 @@
     try {
       final JSONObject jsonObject = new JSONObject();
       addDefaultWidgetProperties(jsonObject, widgetInstance);
+      jsonObject.put("widgetInstanceId", widgetInstance.getId());
       final JSONObject parameters = jsonObject.getJSONObject(WidgetProvider.PARAMETERS);
       return jsonObject;
     } catch (Exception e) {
--- a/modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js	Tue Dec 14 06:10:40 2010 +0100
+++ b/modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js	Tue Dec 14 07:11:13 2010 +0100
@@ -22,51 +22,90 @@
 //
 isc.defineClass('OBQueryListWidget', isc.OBWidget).addProperties({
 
-  widgetId : null,
-  fields : null,
-  grid : null,
-
-  createWindowContents : function() {
+  widgetId: null,
+  widgetInstanceId: null,
+  fields: null,
+  grid: null,
+  gridProperties: {},
+  
+  createWindowContents: function(){
     var layout = isc.VStack.create({
-      height : '100%',
-      width : '100%',
-      styleName : ''
+      height: '100%',
+      width: '100%',
+      styleName: ''
     }), url, params = {};
-
-    this.grid = isc.OBQueryListGrid.create({
-      widget : this,
-      fields : this.fields
-    });
-
+    
+    this.grid = isc.OBQueryListGrid.create(isc.addProperties({
+      widget: this,
+      fields: this.fields
+    }, this.gridProperties));
+    
     layout.addMembers(this.grid);
     return layout;
+  },
+  
+  refresh: function(){
+    this.grid.invalidateCache();
+    this.grid.filterData();
   }
-
+  
 });
 
 isc.ClassFactory.defineClass('OBQueryListGrid', isc.ListGrid);
 
 isc.OBQueryListGrid.addProperties({
-  width : '100%',
-  height : '100%',
-  dataSource : OB.Datasource.get('DD17275427E94026AD721067C3C91C18'),
-
+  width: '100%',
+  height: '100%',
+  dataSource: null,
+  
   // some common settings
   //showFilterEditor: false,
   //filterOnKeypress: false,
-
+  
   canEdit: false,
   alternateRecordStyles: true,
   canReorderFields: true,
   canFreezeFields: false,
   canGroupBy: false,
+  autoFetchData: true,
   //canAutoFitFields: false,
-
+  
   //autoFitFieldWidths: true,
   //autoFitWidthApproach: 'title',
-
-  setDataSource : function(ds) {
-    ds.fields = this.widget.fields;
-    this.dataSource = ds;
-  }
+  
+  initWidget: function(){
+    this.setDataSource(OB.Datasource.get('DD17275427E94026AD721067C3C91C18', this));
+    return this.Super('initWidget', arguments);
+  },
+  
+  setDataSource: function(ds){
+    if (ds) {
+      ds.fields = this.widget.fields;
+      this.dataSource = ds;
+    }
+  },
+  
+  filterData: function(criteria, callback, requestProperties){
+    if (!criteria) {
+      criteria = {};
+    }
+    if (!requestProperties) {
+      requestProperties = {};
+    }
+    requestProperties.showPrompt = false;
+    criteria.widgetInstanceId = this.widget.dbInstanceId;
+    return this.Super('filterData', [criteria, callback, requestProperties]);
+  },
+  
+  fetchData: function(criteria, callback, requestProperties){
+    if (!criteria) {
+      criteria = {};
+    }
+    if (!requestProperties) {
+      requestProperties = {};
+    }
+    requestProperties.showPrompt = false;
+    criteria.widgetInstanceId = this.widget.dbInstanceId;
+    return this.Super('fetchData', [criteria, callback, requestProperties]);
+  }  
 });