Fixes issue 25371: Support list references in parameter windows
authorMartin Taal <martin.taal@openbravo.com>
Wed, 08 Jan 2014 04:00:39 +0100
changeset 21777 e7bddfad3ae2
parent 21776 f857a081fd75
child 21778 d7f5fe16e748
Fixes issue 25371: Support list references in parameter windows
Read the valuemap from the database and show it in the process window for a list reference
.project
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-param-window-parameter.ftl
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewParameterHandler.java
--- a/.project	Wed Jan 08 03:59:47 2014 +0100
+++ b/.project	Wed Jan 08 04:00:39 2014 +0100
@@ -23,4 +23,11 @@
 		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
 		<nature>org.openarchitectureware.base.oawNature</nature>
 	</natures>
+	<linkedResources>
+		<link>
+			<name>modules/org.openbravo.client.analytics/mondrian-3.6.1-src</name>
+			<type>2</type>
+			<location>/home/mtaal/mydownloads/reporting/mondrian/mondrian-3.6.1-sources/main</location>
+		</link>
+	</linkedResources>
 </projectDescription>
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-param-window-parameter.ftl	Wed Jan 08 03:59:47 2014 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-param-window-parameter.ftl	Wed Jan 08 04:00:39 2014 +0100
@@ -29,6 +29,13 @@
   <#if param.type != "OBSectionItem">
     paramId: '${param.id}',
     width: '${param.width?js_string}',
+    <#if param.valueMapPresent>
+    valueMap: {
+    <#list param.valueMap as valueMapValue>
+      '${valueMapValue.key?js_string}': '${valueMapValue.value?js_string}'<#if valueMapValue_has_next>,</#if>
+    </#list>
+    },
+    </#if>
     <#if param.redrawOnChange>
       redrawOnChange: true,
     </#if>
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewParameterHandler.java	Wed Jan 08 03:59:47 2014 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewParameterHandler.java	Wed Jan 08 04:00:39 2014 +0100
@@ -19,6 +19,8 @@
 package org.openbravo.client.application.window;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -29,6 +31,10 @@
 import org.openbravo.client.application.Process;
 import org.openbravo.client.kernel.reference.UIDefinition;
 import org.openbravo.client.kernel.reference.UIDefinitionController;
+import org.openbravo.dal.core.DalUtil;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.model.ad.domain.ListTrl;
+import org.openbravo.model.ad.domain.Reference;
 import org.openbravo.model.ad.ui.FieldGroup;
 import org.openbravo.model.ad.ui.Tab;
 import org.openbravo.model.ad.ui.Window;
@@ -112,6 +118,12 @@
       if (readOnlyLogicMap.containsKey(param)) {
         parameter.setReadOnlyIf(readOnlyLogicMap.get(param));
       }
+      // 17 is the list reference
+      if (param.getReferenceSearchKey() != null
+          && param.getReferenceSearchKey().getParentReference() != null
+          && DalUtil.getId(param.getReferenceSearchKey().getParentReference()).equals("17")) {
+        parameter.addListReferenceValues(param.getReferenceSearchKey());
+      }
 
       params.add(parameter);
     }
@@ -124,6 +136,7 @@
     String showIf = "";
     String readOnlyIf = "";
     boolean redrawOnChange = false;
+    List<ValueMapValue> valueMap = new ArrayList<ValueMapValue>();
 
     public OBViewParameter() {
 
@@ -134,6 +147,53 @@
       parameter = param;
     }
 
+    public boolean isValueMapPresent() {
+      return !valueMap.isEmpty();
+    }
+
+    public List<ValueMapValue> getValueMap() {
+      Collections.sort(valueMap, new Comparator<ValueMapValue>() {
+        @Override
+        public int compare(ValueMapValue v1, ValueMapValue v2) {
+          final long seqno1 = v1.seqno;
+          final long seqno2 = v2.seqno;
+
+          // compare the names if no seqno set.
+          if (seqno1 == -1 || seqno2 == -1) {
+            return v1.getValue().compareTo(v2.getValue());
+          }
+
+          return (int) (seqno1 - seqno2);
+        }
+      });
+      return valueMap;
+    }
+
+    public void addListReferenceValues(Reference reference) {
+      for (org.openbravo.model.ad.domain.List list : reference.getADListList()) {
+        if (list.isActive()) {
+          addListValueReference(list);
+        }
+      }
+    }
+
+    public void addListValueReference(org.openbravo.model.ad.domain.List listValue) {
+      String name = listValue.getName();
+      final String languageId = OBContext.getOBContext().getLanguage().getId();
+      for (ListTrl listTrl : listValue.getADListTrlList()) {
+        if (!listTrl.isActive()) {
+          continue;
+        }
+        if (DalUtil.getId(listTrl.getLanguage()).equals(languageId)) {
+          name = listTrl.getName();
+          break;
+        }
+      }
+      final ValueMapValue vmv = new ValueMapValue(listValue.getSearchKey(), name,
+          listValue.getSequenceNumber());
+      valueMap.add(vmv);
+    }
+
     public String getId() {
       return parameter.getId();
     }
@@ -233,6 +293,30 @@
       }
       return parameter.getLength();
     }
+
+    public class ValueMapValue {
+      final String key;
+      final String value;
+      final long seqno;
+
+      ValueMapValue(String key, String value, Long seqno) {
+        this.key = key;
+        this.value = value;
+        this.seqno = (seqno != null ? seqno : -1);
+      }
+
+      public String getKey() {
+        return key;
+      }
+
+      public String getValue() {
+        return value;
+      }
+
+      public long getSeqno() {
+        return seqno;
+      }
+    }
   }
 
   public class OBViewParamGroup extends OBViewParameter {