Author: adrianc
Date: Tue Dec 4 11:40:38 2007 New Revision: 601056 URL: http://svn.apache.org/viewvc?rev=601056&view=rev Log: Improved entity reference screen - now has better field definitions. Based on discussion in https://issues.apache.org/jira/browse/OFBIZ-1425. Modified: ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml ofbiz/trunk/framework/example/entitydef/entitymodel.xml ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java Modified: ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml?rev=601056&r1=601055&r2=601056&view=diff ============================================================================== --- ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml (original) +++ ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml Tue Dec 4 11:40:38 2007 @@ -47,4 +47,72 @@ <value xml:lang="en">Not Allowed</value> <value xml:lang="it">Non Permesso</value> </property> + + <!-- Entity field descriptions. The Webtools component will use these properties + for online documentation. Field description properties have two forms: + FieldDescription.[fieldname] - will be used for all fields of that name + FieldDescription.[entityname].[fieldname] - will be used for the specified + entity field + --> + <property key="FieldDescription.exampleId"> + <value xml:lang="en">Example ID</value> + <value xml:lang="it">Codice Esempio</value> + <value xml:lang="ro">Cod Exemplu</value> + </property> + <property key="FieldDescription.exampleTypeId"> + <value xml:lang="en">Example Type ID</value> + </property> + <property key="FieldDescription.exampleItemSeqId"> + <value xml:lang="en">Example Item sequence ID</value> + </property> + <property key="FieldDescription.amount"> + <value xml:lang="en">Amount</value> + <value xml:lang="it">Importo</value> + <value xml:lang="ro">Import</value> + </property> + <property key="FieldDescription.exampleName"> + <value xml:lang="en">Example Name</value> + <value xml:lang="it">Nome Esempio</value> + <value xml:lang="ro">Nume Exemplu</value> + </property> + <property key="FieldDescription.longDescription"> + <value xml:lang="en">Long Description</value> + <value xml:lang="it">Descrizione Lunga</value> + <value xml:lang="ro">Descriere Lunga</value> + </property> + <property key="FieldDescription.comments"> + <value xml:lang="en">Comments</value> + <value xml:lang="it">Commenti</value> + <value xml:lang="ro">Comentarii</value> + </property> + <property key="FieldDescription.exampleSize"> + <value xml:lang="en">Example Size</value> + <value xml:lang="it">Esempio Taglia</value> + <value xml:lang="ro">Marime-size Exemplu</value> + </property> + <property key="FieldDescription.exampleDate"> + <value xml:lang="en">Example Date</value> + <value xml:lang="it">Esempio Data</value> + <value xml:lang="ro">Data Exemplu</value> + </property> + <property key="FieldDescription.anotherDate"> + <value xml:lang="en">Another Date</value> + <value xml:lang="it">Altra Data</value> + </property> + <property key="FieldDescription.anotherText"> + <value xml:lang="en">Another Text</value> + <value xml:lang="it">Altro Testo</value> + </property> + <property key="FieldDescription.Example.exampleId"> + <value xml:lang="en">A unique Example ID. If you don't assign an + ID, one will be generated automatically</value> + </property> + <property key="FieldDescription.ExampleItem.exampleItemSeqId"> + <value xml:lang="en">A unique Example Item sequence ID. If you don't assign an + ID, one will be generated automatically</value> + </property> + <property key="FieldDescription.ExampleType.exampleTypeId"> + <value xml:lang="en">A unique Example Type ID. If you don't assign an + ID, one will be generated automatically</value> + </property> </resource> Modified: ofbiz/trunk/framework/example/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/entitydef/entitymodel.xml?rev=601056&r1=601055&r2=601056&view=diff ============================================================================== --- ofbiz/trunk/framework/example/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/framework/example/entitydef/entitymodel.xml Tue Dec 4 11:40:38 2007 @@ -40,7 +40,10 @@ <!-- org.ofbiz.example.example --> <!-- ========================================================= --> - <entity entity-name="Example" package-name="org.ofbiz.example.example" title="Example Entity"> + <entity entity-name="Example" + package-name="org.ofbiz.example.example" + default-resource-name="ExampleEntityLabels" + title="Example Entity"> <field name="exampleId" type="id-ne"><!-- primary sequenced ID --></field> <field name="exampleTypeId" type="id-ne"></field> <field name="statusId" type="id-ne"></field> @@ -60,7 +63,7 @@ <key-map field-name="statusId"/> </relation> </entity> - <entity entity-name="ExampleItem" package-name="org.ofbiz.example.example" title="Example Item Entity"> + <entity entity-name="ExampleItem" package-name="org.ofbiz.example.example" title="Example Item Entity" default-resource-name="ExampleEntityLabels"> <field name="exampleId" type="id-ne"></field> <field name="exampleItemSeqId" type="id-ne"><!-- secondary sequenced ID --></field> <field name="description" type="description"></field> @@ -72,7 +75,7 @@ <key-map field-name="amountUomId" rel-field-name="uomId"/> </relation> </entity> - <entity entity-name="ExampleStatus" package-name="org.ofbiz.example.example" title="Example Status Entity"> + <entity entity-name="ExampleStatus" package-name="org.ofbiz.example.example" title="Example Status Entity" default-resource-name="ExampleEntityLabels"> <field name="exampleId" type="id-ne"></field> <field name="statusDate" type="date-time"></field> <field name="statusEndDate" type="date-time"></field> @@ -123,7 +126,7 @@ <entity entity-name="ExampleFeature" package-name="org.ofbiz.example.feature" - title="Example Feature Entity"> + title="Example Feature Entity" default-resource-name="ExampleEntityLabels"> <field name="exampleFeatureId" type="id-ne"><!-- primary sequenced ID --></field> <field name="featureSourceEnumId" type="id-ne"></field> <field name="description" type="description"></field> @@ -134,7 +137,7 @@ </entity> <entity entity-name="ExampleFeatureAppl" package-name="org.ofbiz.example.feature" - title="Example Feature Application Entity"> + title="Example Feature Application Entity" default-resource-name="ExampleEntityLabels"> <field name="exampleId" type="id-ne"></field> <field name="exampleFeatureId" type="id-ne"></field> <field name="fromDate" type="date-time"></field> Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java?rev=601056&r1=601055&r2=601056&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java (original) +++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java Tue Dec 4 11:40:38 2007 @@ -28,6 +28,7 @@ import java.util.TreeSet; import java.util.Locale; import java.util.Map; +import java.util.ResourceBundle; import java.io.File; import java.io.InputStream; import java.io.StringReader; @@ -50,6 +51,7 @@ import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilProperties.XmlResourceBundle; import org.ofbiz.base.util.UtilURL; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilDateTime; @@ -67,6 +69,7 @@ import org.ofbiz.entity.model.ModelIndex; import org.ofbiz.entity.model.ModelRelation; import org.ofbiz.entity.model.ModelKeyMap; +import org.ofbiz.entity.model.ModelUtil; import org.ofbiz.entity.model.ModelViewEntity; import org.ofbiz.security.Security; import org.ofbiz.service.DispatchContext; @@ -605,18 +608,19 @@ * */ public static Map getEntityRefData(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); - Map resultMap = ServiceUtil.returnSuccess(); + Locale locale = (Locale) context.get("locale"); + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + Map<String, Object> resultMap = ServiceUtil.returnSuccess(); ModelReader reader = delegator.getModelReader(); - Map packages = new HashMap(); - TreeSet packageNames = new TreeSet(); - TreeSet tableNames = new TreeSet(); + Map<String, Object> packages = new HashMap<String, Object>(); + TreeSet<String> packageNames = new TreeSet<String>(); + TreeSet<String> tableNames = new TreeSet<String>(); //put the entityNames TreeSets in a HashMap by packageName try { Collection ec = reader.getEntityNames(); resultMap.put("numberOfEntities", ec.size()); - TreeSet entityNames = new TreeSet(ec); Iterator ecIter = ec.iterator(); while (ecIter.hasNext()) { String eName = (String) ecIter.next(); @@ -625,9 +629,9 @@ if (UtilValidate.isNotEmpty(ent.getPlainTableName())) { tableNames.add(ent.getPlainTableName()); } - TreeSet entities = (TreeSet) packages.get(ent.getPackageName()); + TreeSet<String> entities = (TreeSet) packages.get(ent.getPackageName()); if (entities == null) { - entities = new TreeSet(); + entities = new TreeSet<String>(); packages.put(ent.getPackageName(), entities); packageNames.add(ent.getPackageName()); } @@ -638,35 +642,59 @@ } String search = (String) context.get("search"); - List packagesList = new ArrayList(); + List<Map<String, Object>> packagesList = new ArrayList<Map<String, Object>>(); Iterator piter = packageNames.iterator(); try { while (piter.hasNext()) { - Map packageMap = new HashMap(); + Map<String, Object> packageMap = new HashMap<String, Object>(); String pName = (String) piter.next(); TreeSet entities = (TreeSet) packages.get(pName); - List entitiesList = new ArrayList(); - Iterator i = entities.iterator(); - while (i.hasNext()) { - Map entityMap = new HashMap(); - String entityName = (String) i.next(); + List<Map<String, Object>> entitiesList = new ArrayList<Map<String, Object>>(); + Iterator e = entities.iterator(); + while (e.hasNext()) { + Map<String, Object> entityMap = new HashMap<String, Object>(); + String entityName = (String) e.next(); String helperName = delegator.getEntityHelperName(entityName); String groupName = delegator.getEntityGroupName(entityName); if (search == null || entityName.toLowerCase().indexOf(search.toLowerCase()) != -1) { ModelEntity entity = reader.getModelEntity(entityName); + ResourceBundle bundle = null; + if (UtilValidate.isNotEmpty(entity.getDefaultResourceName())) { + try { + bundle = XmlResourceBundle.getBundle(entity.getDefaultResourceName(), locale, loader); + } catch (Exception exception) { + Debug.logInfo(exception.getMessage(), module); + } + } // fields list - List javaNameList = new ArrayList(); - TreeSet ufields = new TreeSet(); - for (int y = 0; y < entity.getFieldsSize(); y++) { - Map javaNameMap = new HashMap(); - ModelField field = entity.getField(y); + List<Map<String, Object>> javaNameList = new ArrayList<Map<String, Object>>(); + for (Iterator f = entity.getFieldsIterator(); f.hasNext();) { + Map<String, Object> javaNameMap = new HashMap<String, Object>(); + ModelField field = (ModelField) f.next(); ModelFieldType type = delegator.getEntityFieldType(entity, field.getType()); - String javaName = null; javaNameMap.put("isPk", field.getIsPk()); javaNameMap.put("name", field.getName()); javaNameMap.put("colName", field.getColName()); - javaNameMap.put("description", field.getDescription()); + String fieldDescription = null; + if (bundle != null) { + try { + fieldDescription = bundle.getString("FieldDescription." + entity.getEntityName() + "." + field.getName()); + } catch (Exception exception) {} + } + if (UtilValidate.isEmpty(fieldDescription)) { + fieldDescription = field.getDescription(); + } + if (UtilValidate.isEmpty(fieldDescription) && bundle != null) { + try { + fieldDescription = bundle.getString("FieldDescription." + field.getName()); + } catch (Exception exception) {} + } + if (UtilValidate.isEmpty(fieldDescription)) { + fieldDescription = ModelUtil.javaNameToDbName(field.getName()).toLowerCase(); + fieldDescription = ModelUtil.upperFirstChar(fieldDescription.replace('_', ' ')); + } + javaNameMap.put("description", fieldDescription); javaNameMap.put("type", (field.getType()) != null ? field.getType() : null); javaNameMap.put("javaType", (field.getType() != null && type != null) ? type.getJavaType() : "Undefined"); javaNameMap.put("sqlType", (type != null && type.getSqlType() != null) ? type.getSqlType() : "Undefined"); @@ -674,13 +702,13 @@ } // relations list - List relationsList = new ArrayList(); + List<Map<String, Object>> relationsList = new ArrayList<Map<String, Object>>(); for (int r = 0; r < entity.getRelationsSize(); r++) { - Map relationMap = new HashMap(); + Map<String, Object> relationMap = new HashMap<String, Object>(); ModelRelation relation = entity.getRelation(r); - List keysList = new ArrayList(); + List<Map<String, Object>> keysList = new ArrayList<Map<String, Object>>(); for (int km = 0; km < relation.getKeyMapsSize(); km++) { - Map keysMap = new HashMap(); + Map<String, Object> keysMap = new HashMap<String, Object>(); ModelKeyMap keyMap = relation.getKeyMap(km); String fieldName = null; String relFieldName = null; @@ -707,16 +735,16 @@ } // index list - List indexList = new ArrayList(); + List<Map<String, Object>> indexList = new ArrayList<Map<String, Object>>(); for (int r = 0; r < entity.getIndexesSize(); r++) { - List fieldNameList = new ArrayList(); + List<String> fieldNameList = new ArrayList<String>(); ModelIndex index = entity.getIndex(r); for (Iterator fieldIterator = index.getIndexFieldsIterator(); fieldIterator.hasNext();) { fieldNameList.add((String) fieldIterator.next()); } - Map indexMap = new HashMap(); + Map<String, Object> indexMap = new HashMap<String, Object>(); indexMap.put("name", index.getName()); indexMap.put("description", index.getDescription()); indexMap.put("fieldNameList", fieldNameList); |
Free forum by Nabble | Edit this page |