Fixed issue 18809. Attribute Set Instance selectors will work correctly when editing the grid
authorAntonio Moreno <antonio.moreno@openbravo.com>
Thu, 20 Oct 2011 16:56:44 +0200
changeset 14014 8a0c37fd9dd2
parent 13967 4e9fa8e7edbc
child 14015 f7371a718253
Fixed issue 18809. Attribute Set Instance selectors will work correctly when editing the grid
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/ForeignKeyUIDefinition.java
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/StringUIDefinition.java
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TextUIDefinition.java
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/reference/FKSelectorUIDefinition.java
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/ForeignKeyUIDefinition.java	Fri Oct 14 13:52:15 2011 +0000
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/ForeignKeyUIDefinition.java	Thu Oct 20 16:56:44 2011 +0200
@@ -46,10 +46,6 @@
 
   @Override
   public String getGridFieldProperties(Field field) {
-    Long length = field.getDisplayedLength();
-    if (length == null || length == 0) {
-      length = field.getColumn().getLength();
-    }
     final Property prop = KernelUtils.getInstance().getPropertyFromColumn(field.getColumn());
 
     // only output when really needed
@@ -57,8 +53,8 @@
     if (getDisplayFieldName(field, prop) != null) {
       displayField = ", displayField: '" + getDisplayFieldName(field, prop) + "'";
     }
-    return ", length:" + length + displayField + ",fkField: true"
-        + super.getGridFieldProperties(field) + getShowHoverGridFieldSettings(field);
+    return displayField + ",fkField: true" + super.getGridFieldProperties(field)
+        + getShowHoverGridFieldSettings(field);
   }
 
   /**
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/StringUIDefinition.java	Fri Oct 14 13:52:15 2011 +0000
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/StringUIDefinition.java	Thu Oct 20 16:56:44 2011 +0200
@@ -18,6 +18,8 @@
  */
 package org.openbravo.client.kernel.reference;
 
+import org.codehaus.jettison.json.JSONObject;
+import org.openbravo.base.exception.OBException;
 import org.openbravo.model.ad.ui.Field;
 
 /**
@@ -43,15 +45,33 @@
   }
 
   @Override
+  public String getFieldProperties(Field field) {
+    String fieldProperties = super.getFieldProperties(field);
+    if (field != null && field.getColumn() != null) {
+      final Long length = field.getColumn().getLength();
+      try {
+        if (length != null) {
+          JSONObject o = new JSONObject(
+              fieldProperties != null && fieldProperties.length() > 0 ? fieldProperties : "{}");
+          o.put("length", length);
+          return o.toString();
+        }
+      } catch (Exception e) { // ignore
+        throw new OBException(e);
+      }
+    }
+    return fieldProperties;
+  }
+
+  @Override
   public String getGridFieldProperties(Field field) {
-    Long length = field.getDisplayedLength();
-    if (length == null || length == 0) {
-      length = field.getColumn().getLength();
-    }
+    Long length = field.getColumn().getLength();
+
     // custom override
     if (field.getColumn().getDBColumnName().compareToIgnoreCase("documentno") == 0) {
       length = new Long(20);
     }
-    return getShowHoverGridFieldSettings(field) + super.getGridFieldProperties(field);
+    return getShowHoverGridFieldSettings(field) + (length != null ? ", length:" + length : "")
+        + super.getGridFieldProperties(field);
   }
 }
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TextUIDefinition.java	Fri Oct 14 13:52:15 2011 +0000
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TextUIDefinition.java	Thu Oct 20 16:56:44 2011 +0200
@@ -35,6 +35,7 @@
   @Override
   public String getGridFieldProperties(Field field) {
     final Property property = KernelUtils.getInstance().getPropertyFromColumn(field.getColumn());
+    final Long length = field.getColumn().getLength();
 
     // anything above 2000 is probably a clob
     return super.getGridFieldProperties(field) + ", canSort: false"
--- a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/reference/FKSelectorUIDefinition.java	Fri Oct 14 13:52:15 2011 +0000
+++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/reference/FKSelectorUIDefinition.java	Thu Oct 20 16:56:44 2011 +0200
@@ -99,10 +99,6 @@
 
   @Override
   protected String getDisplayFieldName(Field field, Property prop) {
-    Long length = field.getDisplayedLength();
-    if (length == null || length == 0) {
-      length = field.getColumn().getLength();
-    }
     final Selector selector = getSelector(field);
     final SelectorField displayField = selector.getDisplayfield();
     String displayFieldName = JsonConstants.IDENTIFIER;