Modified UIDefinitionController so that button references are taken into account
authorAntonio Moreno <antonio.moreno@openbravo.com>
Mon, 13 Dec 2010 10:10:01 +0100
changeset 9093 c26e8201a772
parent 9092 74be53157a46
child 9094 e4abe4aaf43c
Modified UIDefinitionController so that button references are taken into account
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/EnumUIDefinition.java
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinitionController.java
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/EnumUIDefinition.java	Mon Dec 13 10:08:11 2010 +0100
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/EnumUIDefinition.java	Mon Dec 13 10:10:01 2010 +0100
@@ -44,14 +44,9 @@
   public String getFieldProperties(Field field, boolean getValueFromSession) {
     String columnValue;
     try {
-      if (field.getColumn().getReference().getId().equals("17")) {
-        columnValue = new JSONObject(super.getFieldProperties(field, getValueFromSession))
-            .getString("value");
-        return getValueInComboReference(field, getValueFromSession, columnValue);
-      } else {
-        System.out.println("Invalid reference: " + field.getColumn().getReference());
-        return super.getFieldProperties(field, getValueFromSession);
-      }
+      columnValue = new JSONObject(super.getFieldProperties(field, getValueFromSession))
+          .getString("value");
+      return getValueInComboReference(field, getValueFromSession, columnValue);
     } catch (JSONException e) {
       throw new OBException("Error while computing combo data", e);
     }
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinitionController.java	Mon Dec 13 10:08:11 2010 +0100
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinitionController.java	Mon Dec 13 10:10:01 2010 +0100
@@ -18,8 +18,10 @@
  */
 package org.openbravo.client.kernel.reference;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
@@ -67,11 +69,17 @@
   private Map<String, UIDefinition> cachedDefinitions = null;
   private Map<String, UIDefinition> uiDefinitionsByColumnId = null;
   private Map<String, FormatDefinition> formatDefinitions = null;
+  private List<Reference> buttonReferences = null;
+  private List<String> buttonColumns = null;
+  private UIDefinition buttonDefinition = null;
 
   public UIDefinition getUIDefinition(String columnId) {
     if (cachedDefinitions == null) {
       setInitCachedDefinitions();
     }
+    if (buttonColumns.contains(columnId)) {
+      return buttonDefinition;
+    }
     final UIDefinition uiDefinition = uiDefinitionsByColumnId.get(columnId);
     if (uiDefinition == null) {
       log.warn("NO UIDefinition found for columnId " + columnId);
@@ -83,6 +91,9 @@
     if (cachedDefinitions == null) {
       setInitCachedDefinitions();
     }
+    if (buttonReferences.contains(reference)) {
+      return buttonDefinition;
+    }
     final UIDefinition uiDefinition = cachedDefinitions.get(reference.getId());
     if (uiDefinition == null) {
       log.warn("NO UIDefinition found for reference " + reference.getId());
@@ -115,6 +126,8 @@
     }
     final Map<String, UIDefinition> localCachedDefinitions = new HashMap<String, UIDefinition>();
     final Map<String, UIDefinition> localUIDefinitionsByColumn = new HashMap<String, UIDefinition>();
+    final ArrayList<Reference> localButtonReferences = new ArrayList<Reference>();
+    final ArrayList<String> localButtonColumns = new ArrayList<String>();
 
     OBContext.setAdminMode();
     try {
@@ -133,6 +146,11 @@
           }
 
           localCachedDefinitions.put(reference.getId(), uiDefinition);
+
+          Reference buttonReference = OBDal.getInstance().get(Reference.class, "28");
+          final Class<?> clz = OBClassLoader.getInstance().loadClass(
+              buttonReference.getOBCLKERUIDefinitionList().get(0).getImplementationClassname());
+          buttonDefinition = (UIDefinition) clz.newInstance();
         } catch (Exception e) {
           throw new OBException("Exception when creating UIDefinition for reference " + reference,
               e);
@@ -143,6 +161,11 @@
       for (Column column : columnQry.list()) {
         final String referenceId;
         if (column.getReferenceSearchKey() != null) {
+          if (DalUtil.getId(column.getReference()).equals("28")) {
+            // This reference is a button reference. We will add it to the button references
+            localButtonReferences.add(column.getReferenceSearchKey());
+            localButtonColumns.add(column.getId());
+          }
           referenceId = (String) DalUtil.getId(column.getReferenceSearchKey());
         } else {
           referenceId = (String) DalUtil.getId(column.getReference());
@@ -155,6 +178,8 @@
     }
     uiDefinitionsByColumnId = localUIDefinitionsByColumn;
     cachedDefinitions = localCachedDefinitions;
+    buttonReferences = localButtonReferences;
+    buttonColumns = localButtonColumns;
   }
 
   private UIDefinition getUIDefinitionImplementation(Reference reference) throws Exception {