details:   /erp/devel/pi/rev/6fed35ef2c2b
changeset: 9439:6fed35ef2c2b
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Tue Dec 28 14:00:17 2010 +0100
summary:   Changed datasource implementation, different query widgets don't 
share a datasource anymore

diffstat:

 
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListComponentProvider.java
 |  13 +-
 
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
        |  58 +++++++++-
 
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListWidgetProvider.java
    |  34 +++++-
 
modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js
       |  23 +---
 4 files changed, 91 insertions(+), 37 deletions(-)

diffs (246 lines):

diff -r f966e2f3dd29 -r 6fed35ef2c2b 
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListComponentProvider.java
--- 
a/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListComponentProvider.java
 Tue Dec 28 13:58:45 2010 +0100
+++ 
b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListComponentProvider.java
 Tue Dec 28 14:00:17 2010 +0100
@@ -39,23 +39,14 @@
 
   @Override
   public Component getComponent(String componentId, Map<String, Object> 
parameters) {
-    if (componentId.equals(QueryListComponent.COMPONENT_ID)) {
-      final QueryListComponent component = 
getComponent(QueryListComponent.class);
-      component.setParameters(parameters);
-      return component;
-    }
     throw new IllegalArgumentException("Component id " + componentId + " not 
supported.");
   }
 
   @Override
   public List<ComponentResource> getGlobalResources() {
     final List<ComponentResource> globalResources = new 
ArrayList<ComponentResource>();
-    globalResources
-        .add(createStaticResource(
-            "web/org.openbravo.client.querylist/js/ob-querylist-widget.js",
-            false));
-    globalResources.add(createStaticResource("org.openbravo.client.kernel/" + 
COMPONENT_TYPE + "/"
-        + QueryListComponent.COMPONENT_ID, false));
+    globalResources.add(createStaticResource(
+        "web/org.openbravo.client.querylist/js/ob-querylist-widget.js", 
false));
     return globalResources;
   }
 
diff -r f966e2f3dd29 -r 6fed35ef2c2b 
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
--- 
a/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
        Tue Dec 28 13:58:45 2010 +0100
+++ 
b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
        Tue Dec 28 14:00:17 2010 +0100
@@ -27,13 +27,21 @@
 import java.util.Map;
 
 import org.hibernate.Query;
+import org.openbravo.base.model.domaintype.PrimitiveDomainType;
 import org.openbravo.client.application.ApplicationUtils;
 import org.openbravo.client.application.Parameter;
 import org.openbravo.client.application.ParameterValue;
+import org.openbravo.client.kernel.reference.ForeignKeyUIDefinition;
+import org.openbravo.client.kernel.reference.NumberUIDefinition;
+import org.openbravo.client.kernel.reference.UIDefinition;
+import org.openbravo.client.kernel.reference.UIDefinitionController;
+import org.openbravo.client.kernel.reference.YesNoUIDefinition;
 import org.openbravo.client.myob.WidgetClass;
 import org.openbravo.client.myob.WidgetInstance;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.domain.Reference;
+import org.openbravo.service.datasource.DataSourceProperty;
 import org.openbravo.service.datasource.ReadOnlyDataSourceService;
 import org.openbravo.service.json.JsonUtils;
 
@@ -44,9 +52,6 @@
  */
 public class QueryListDataSource extends ReadOnlyDataSourceService {
 
-  private final SimpleDateFormat xmlDateFormat = JsonUtils.createDateFormat();
-  private final SimpleDateFormat xmlDateTimeFormat = 
JsonUtils.createDateTimeFormat();
-
   /**
    * Returns the count of objects based on the passed parameters.
    * 
@@ -62,6 +67,10 @@
   @Override
   protected List<Map<String, Object>> getData(Map<String, String> parameters, 
int startRow,
       int endRow) {
+    // creation of formats is done here because they are not thread safe
+    final SimpleDateFormat xmlDateFormat = JsonUtils.createDateFormat();
+    final SimpleDateFormat xmlDateTimeFormat = 
JsonUtils.createDateTimeFormat();
+
     OBContext.setAdminMode();
     try {
       WidgetInstance widgetInstance = 
OBDal.getInstance().get(WidgetInstance.class,
@@ -169,4 +178,47 @@
     }
     return parameterValues;
   }
+
+  public List<DataSourceProperty> getDataSourceProperties(Map<String, Object> 
parameters) {
+    // note datasource properties are not cached as the component is
+    // re-used within one request thread
+    final List<DataSourceProperty> dsProperties = new 
ArrayList<DataSourceProperty>();
+    OBContext.setAdminMode();
+    try {
+      WidgetClass widgetClass = (WidgetClass) parameters
+          .get(QueryListWidgetProvider.WIDGETCLASS_PARAMETER);
+
+      if (!widgetClass.getOBCQLWidgetQueryList().isEmpty()) {
+        for (OBCQL_QueryColumn column : QueryListUtils.getColumns(widgetClass
+            .getOBCQLWidgetQueryList().get(0))) {
+          Reference reference = column.getReference();
+          if (column.getReferenceSearchKey() != null) {
+            reference = column.getReferenceSearchKey();
+          }
+
+          final DataSourceProperty dsProperty = new DataSourceProperty();
+          dsProperty.setName(column.getDisplayExpression());
+          dsProperty.setId(false);
+          dsProperty.setMandatory(false);
+          dsProperty.setAuditInfo(false);
+          dsProperty.setUpdatable(false);
+          final UIDefinition uiDefinition = 
UIDefinitionController.getInstance().getUIDefinition(
+              reference);
+          dsProperty.setBoolean(uiDefinition instanceof YesNoUIDefinition);
+          dsProperty.setPrimitive(!(uiDefinition instanceof 
ForeignKeyUIDefinition));
+          dsProperty.setUIDefinition(uiDefinition);
+          if (dsProperty.isPrimitive()) {
+            dsProperty.setPrimitiveObjectType(((PrimitiveDomainType) 
uiDefinition.getDomainType())
+                .getPrimitiveType());
+            dsProperty.setNumericType(uiDefinition instanceof 
NumberUIDefinition);
+          } else {
+          }
+          dsProperties.add(dsProperty);
+        }
+      }
+      return dsProperties;
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
 }
diff -r f966e2f3dd29 -r 6fed35ef2c2b 
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListWidgetProvider.java
--- 
a/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListWidgetProvider.java
    Tue Dec 28 13:58:45 2010 +0100
+++ 
b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListWidgetProvider.java
    Tue Dec 28 14:00:17 2010 +0100
@@ -18,14 +18,23 @@
  */
 package org.openbravo.client.querylist;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.inject.Inject;
+
 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.application.ParameterValue;
+import org.openbravo.client.kernel.Component;
+import org.openbravo.client.kernel.ComponentProvider;
 import org.openbravo.client.kernel.KernelConstants;
 import org.openbravo.client.myob.WidgetInstance;
 import org.openbravo.client.myob.WidgetProvider;
+import org.openbravo.service.datasource.DataSourceComponentProvider;
+import org.openbravo.service.datasource.DataSourceConstants;
 
 /**
  * Responsible for creating the Query/List Widgets.
@@ -33,6 +42,8 @@
  * @author gorkaion
  */
 public class QueryListWidgetProvider extends WidgetProvider {
+  private static final String DATASOURCEID = 
"DD17275427E94026AD721067C3C91C18";
+  public static final String WIDGETCLASS_PARAMETER = "WIDGET_CLASS";
 
   private static final String GRID_PROPERTIES_REFERENCE = 
"B36DF126DF5F4077A37F1E5B963AA636";
   private static final Logger log = 
Logger.getLogger(QueryListWidgetProvider.class);
@@ -40,6 +51,10 @@
   private static final Long ROW_HEIGHT = 23L;
   private static final Long STATIC_HEIGHT = 80L;
 
+  @Inject
+  @ComponentProvider.Qualifier(DataSourceConstants.DS_COMPONENT_TYPE)
+  private DataSourceComponentProvider dataSourceComponentProvider;
+
   @Override
   public String generate() {
     JSONObject gridPropertiesObject = null;
@@ -58,15 +73,30 @@
     }
     String gridProperties = (gridPropertiesObject == null ? "" : ", 
gridProperties: "
         + gridPropertiesObject.toString());
-    return "isc.defineClass('"
+    final String result = "isc.defineClass('"
         + KernelConstants.ID_PREFIX
         + getWidgetClass().getId()
         + "', isc.OBQueryListWidget).addProperties({widgetId: '"
         + getWidgetClass().getId()
-        + "', fields:"
+        + "', "
+        + "gridDataSource: "
+        + getDataSourceJavaScript()
+        + ", fields:"
         + QueryListUtils
             .getWidgetClassFields(getWidgetClass(), 
QueryListUtils.IncludeIn.WidgetView)
         + gridProperties + "});";
+    return result;
+  }
+
+  public String getDataSourceJavaScript() {
+    final Map<String, Object> localParameters = new HashMap<String, Object>();
+    localParameters.putAll(getParameters());
+    localParameters.put(DataSourceConstants.DS_ONLY_GENERATE_CREATESTATEMENT, 
true);
+    localParameters.put(WIDGETCLASS_PARAMETER, getWidgetClass());
+    final Component dsComponent = 
dataSourceComponentProvider.getComponent(DATASOURCEID,
+        localParameters);
+    final String dsJavaScript = dsComponent.generate();
+    return dsJavaScript;
   }
 
   public JSONObject getWidgetInstanceDefinition(WidgetInstance widgetInstance) 
{
diff -r f966e2f3dd29 -r 6fed35ef2c2b 
modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js
--- 
a/modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js
       Tue Dec 28 13:58:45 2010 +0100
+++ 
b/modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js
       Tue Dec 28 14:00:17 2010 +0100
@@ -57,6 +57,7 @@
     }), url, params = {};
     
     this.grid = isc.OBQueryListGrid.create(isc.addProperties({
+      dataSource: this.gridDataSource,
       widget: this,
       fields: this.fields
     }, this.gridProperties));
@@ -105,30 +106,10 @@
   canReorderFields: false,
   canFreezeFields: false,
   canGroupBy: false,
-  autoFetchData: false,
+  autoFetchData: true,
   canAutoFitFields: false,
   showGridSummary: true,
   
-  //autoFitFieldWidths: true,
-  //autoFitWidthApproach: 'title',
-  
-  initWidget: function(){
-    OB.Datasource.get('DD17275427E94026AD721067C3C91C18', this);
-    this.Super('initWidget', arguments);
-  },
-  
-  setDataSource: function(ds){
-    if (ds) {
-      ds.fields = this.widget.fields;
-      this.dataSource = ds;
-
-      if(this.widget && this.widget.dbInstanceId) {
-        this.filterData();
-      }
-
-    }
-  },
-  
   filterData: function(criteria, callback, requestProperties){
     var crit = criteria || {},
     reqProperties = requestProperties || {};

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to