Set widget height based on the RowsNumber parameter.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Tue, 14 Dec 2010 14:11:26 +0100
changeset 9125 63908817afee
parent 9124 543120570dec
child 9126 ad4fb64a6f27
Set widget height based on the RowsNumber parameter.
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 14 14:10:28 2010 +0100
+++ b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListWidgetProvider.java	Tue Dec 14 14:11:26 2010 +0100
@@ -22,6 +22,7 @@
 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.KernelConstants;
 import org.openbravo.client.myob.WidgetInstance;
 import org.openbravo.client.myob.WidgetProvider;
@@ -35,6 +36,9 @@
 
   private static String GRID_PROPERTIES_REFERENCE = "B36DF126DF5F4077A37F1E5B963AA636";
   private static final Logger log = Logger.getLogger(QueryListWidgetProvider.class);
+  private static final String HEIGHT = "height";
+  private static final Long ROW_HEIGHT = 23L;
+  private static final Long STATIC_HEIGHT = 80L;
 
   @Override
   public String generate() {
@@ -65,24 +69,23 @@
         + gridProperties + "});";
   }
 
-  @Override
-  public JSONObject getWidgetClassDefinition() {
-    try {
-      final JSONObject jsonObject = super.getWidgetClassDefinition();
-      final JSONObject parameters = new JSONObject();
-      jsonObject.put(WidgetProvider.PARAMETERS, parameters);
-      return jsonObject;
-    } catch (Exception e) {
-      throw new OBException(e);
-    }
-  }
-
   public JSONObject getWidgetInstanceDefinition(WidgetInstance widgetInstance) {
     try {
-      final JSONObject jsonObject = new JSONObject();
-      addDefaultWidgetProperties(jsonObject, widgetInstance);
+      final JSONObject jsonObject = super.getWidgetInstanceDefinition(widgetInstance);
       jsonObject.put("widgetInstanceId", widgetInstance.getId());
-      final JSONObject parameters = jsonObject.getJSONObject(WidgetProvider.PARAMETERS);
+
+      Long height = widgetInstance.getWidgetClass().getHeight();
+
+      for (ParameterValue value : widgetInstance
+          .getOBUIAPPParameterValueEMObkmoWidgetInstanceIDList()) {
+        if ("RowsNumber".equals(value.getParameter().getDBColumnName())) {
+          height = value.getValueNumber().longValue() * ROW_HEIGHT;
+          height += STATIC_HEIGHT;
+        }
+      }
+
+      jsonObject.put(HEIGHT, height);
+
       return jsonObject;
     } catch (Exception e) {
       throw new OBException(e);