📄 uiutility.java
字号:
public static boolean getIsCopiedPrimaryKey(String action,
UIFieldInfo fieldInfo) {
if (action.equals(UIScreenSection.ACTION_SHOW_COPY) &&
fieldInfo.getUiAttribute().getIsPk()) {
return true;
} else {
return false;
}
}
/**
* DOCUMENT ME!
*
* @param attributeValueSource
* @param entityDetailsVector
* @param currentAttibuteName
*
* @return
*
* @throws GenericEntityException
*/
public static String decodeAttributeValue(String attributeValueSource,
Vector entityDetailsVector, String currentAttibuteName)
throws GenericEntityException {
String screenEntityName = "";
String screenAttributeName = "";
GenericValue screenEntityDetails = null;
Debug.logVerbose(
"-->[UIUtility.decodeFieldValue] attributeValueSource: " +
attributeValueSource, module);
if (attributeValueSource.indexOf("\"") == -1) {
// There are no quote marks in the attribute name, so it is really an attribute name. Get the value of this
// attribute from the screen entity.
Debug.logVerbose(
"-->[UIUtility.decodeFieldValue] No quotes found in '" +
attributeValueSource + "'", module);
// If there is a "." in the attribute name, split off the entity name.
StringTokenizer tokPeriod = new StringTokenizer(attributeValueSource,
".");
if (tokPeriod.countTokens() == 1) {
// There is no "." in the attribute string. Assume we need to use the primary screen entity.
Debug.logVerbose(
"-->[UIUtility.decodeFieldValue] No period found in '" +
attributeValueSource + "'. Using the primary entity", module);
screenEntityName = ((GenericValue) (entityDetailsVector.get(0))).getEntityName();
screenAttributeName = attributeValueSource;
} else {
// Need to get the entity specified before the "." in the attribute name string.
Debug.logVerbose(
"-->[UIUtility.decodeFieldValue] Period found in '" +
attributeValueSource +
"'. Parsing the primary entity out of the find def.", module);
screenEntityName = tokPeriod.nextToken();
screenAttributeName = tokPeriod.nextToken();
}
tokPeriod = null;
if (screenAttributeName.equals("#currentField")) {
screenAttributeName = (currentAttibuteName == null) ? ""
: currentAttibuteName;
Debug.logVerbose(
"-->[UIUtility.decodeFieldValue] Replacing '#currentField' with '" +
screenAttributeName + "'", module);
}
Debug.logVerbose(
"-->[UIUtility.decodeFieldValue] Find Def Entity = " +
screenEntityName, module);
Debug.logVerbose(
"-->[UIUtility.decodeFieldValue] Find Def Attrib = " +
screenAttributeName, module);
// Get the specified screen entity from the vector.
Iterator entityDetailsIterator = entityDetailsVector.iterator();
while (entityDetailsIterator.hasNext()) {
GenericValue testEntity = (GenericValue) entityDetailsIterator.next();
if (testEntity.getEntityName().equals(screenEntityName)) {
screenEntityDetails = testEntity;
}
}
try {
String dummy = String.valueOf(screenEntityDetails.get(
screenAttributeName));
} catch (IllegalArgumentException e) {
throw new GenericEntityException(
"[UIUtility.decodeFieldValue]: Problem with attribute value definition \"" +
attributeValueSource + "\": " + e.getLocalizedMessage());
// Debug.logWarning("[UIUtility.decodeFieldValue]: Problem with entity find definition \"" + entityFindDef + "\":");
// Debug.logWarning(e.getMessage());
// entityFindMap = null;
// return entityFindMap;
}
return screenEntityDetails.getString(screenAttributeName);
} else {
Debug.logVerbose(
"-->[UIUtility.decodeEntityFindDef] Quotes found in '" +
attributeValueSource + "'. Using literal value.", module);
// This is a literal value because it has quote marks around it.
return attributeValueSource.substring(attributeValueSource.indexOf(
"\"") + 1, attributeValueSource.lastIndexOf("\""));
}
}
/**
* Looks up the read-only value for the field to be shown on the screen instead
* of a drop down select because the mode is read-only.
*
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @param fieldValue Value stored or to be stored in the data base. Used as the primary key to look up the value to be displayed.
* @param attributeName Name of the attribute being displayed
* @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
* @param entityDetailsVector Vector that holds one or more generic values from which the display value can be decoded
* @param delegator Reference to the OFBIZ delegator being used to connect to the data base
*
* @return Array containing the data value and display value.
*/
public static GenericValue getReadOnlyValue(String fieldValue,
String attributeName, UIDisplayObject uiDisplayObject,
Vector entityDetailsVector, GenericDelegator delegator) {
GenericValue gv = null;
if (fieldValue.trim().equals("")) {
Debug.logVerbose("[getReadOnlyValue] Field value is empty.", module);
// Field value is empty. Just display an empty string, and create a hidden field.
return gv;
} else {
Debug.logVerbose(
"[getReadOnlyValue] Field value has contents. About to create the findByAnd field map.", module);
// Decode the primary key entity find definition into a hash map that can be used
// to create the primary key necessary for the findByPrimaryKey function.
HashMap entityFindMap = UIUtility.decodeEntityFindDef(uiDisplayObject.getAttribEntityPkFindDef(),
entityDetailsVector, attributeName);
if (entityFindMap == null) {
Debug.logWarning("[getReadOnlyValue] Skipping field \"" +
attributeName + "\" because of faulty find definition: " +
uiDisplayObject.getAttribEntityPkFindDef(), module);
return gv;
}
Debug.logVerbose(
"[getReadOnlyValue] Finished calling decodeEntityFindDef to decode find def '" +
uiDisplayObject.getAttribEntityPkFindDef() + "'.", module);
Debug.logVerbose("[getReadOnlyValue] entityFindMap -> " +
entityFindMap.toString(), module);
// Find the entity by its primary key.
ModelEntity entityEntity = delegator.getModelEntity(uiDisplayObject.getAttribEntity());
GenericPK entityPk = new GenericPK(entityEntity, entityFindMap);
try {
gv = delegator.findByPrimaryKeyCache(entityPk);
} catch (GenericEntityException e) {
Debug.logError(
"[getReadOnlyValue] Error searching for read-only value for drop down: " +
e.getLocalizedMessage(), module);
}
if (gv == null) {
gv = new GenericValue(entityPk);
Debug.logWarning("[getReadOnlyValue] Skipping field \"" +
attributeName +
"\" because no entity was found for value \"" + fieldValue +
"\" using find definition \"" +
uiDisplayObject.getAttribEntityPkFindDef() + "\"", module);
}
return gv;
}
}
/**
* Add criteria to
*
* @param entityFindDef
* @param entityDetailsVector
* @param currentAttibuteName
*
* @return
*/
public static boolean addSelectSearch(QueryInfo queryInfo, String displayObjectId, String entityName, String attributeName, String aliasName, EntityComparisonOperator searchOperator, Object searchValue)
{
try
{
GenericDelegator delegator = queryInfo.getDelegator();
UIDisplayObject displayObject = new UIDisplayObject( displayObjectId, delegator );
displayObject.loadAttributes();
// Split the entity find definition into pieces. Example:
// * attribEntityFindDef:
// * sectionId:sectionId;partyId:"-1"
// * Resulting find map pairs:
// * sectionId:43
// * partyId:-1
// * Resulting find logic:
// * sectionId = 43 AND partyId = -1
String findAttributeValue = "";
List joinList = new ArrayList();
String joinEntity = "";
HashMap conditionMap = new HashMap();
String entityFindDef = displayObject.getAttribEntityPkFindDef();
StringTokenizer tokSemicolon = new StringTokenizer(entityFindDef, ";");
while (tokSemicolon.hasMoreTokens()) {
String pair = tokSemicolon.nextToken();
StringTokenizer tokColon = new StringTokenizer(pair, ":");
if (tokColon.countTokens() != 2) {
Debug.logWarning(
"-->[UIUtility.decodeEntityFindDef] No colon found in '" +
pair + "'" + "for entityFindDef" + entityFindDef, module);
return false;
} else {
String findAttributeName = tokColon.nextToken();
if ( findAttributeName.equals("#currentField"))
findAttributeName = attributeName;
// String screenAttributeString = tokColon.nextToken();
String attributeValueSource = tokColon.nextToken();
if ( attributeValueSource.equals("#currentField"))
attributeValueSource = attributeName;
if ( attributeValueSource.indexOf("\"") > -1 )
{
attributeValueSource = attributeValueSource.substring(attributeValueSource.indexOf(
"\"") + 1, attributeValueSource.lastIndexOf("\""));
conditionMap.put(findAttributeName, attributeValueSource);
}
else
{
StringTokenizer tokPeriod = new StringTokenizer(attributeValueSource,
".");
String relatedEntity = "";
if (tokPeriod.countTokens() == 1) {
// There is no "." in the attribute string. Assume we need to use the primary screen entity.
relatedEntity = entityName;
} else {
// Need to get the entity specified before the "." in the attribute name string.
relatedEntity = tokPeriod.nextToken();
attributeValueSource = tokPeriod.nextToken();
}
if ( (joinEntity.length() > 0) && ( !joinEntity.equals(relatedEntity) ) )
{
Debug.logError("Invalid Join Condition, attempting to join lookup table to two different entities", module);
return false;
}
joinEntity = relatedEntity;
joinList.add(new ModelKeyMap(attributeValueSource, findAttributeName));
}
}
}
if( joinList.size() < 1)
{
Debug.logWarning("EntityFindDef has no join with primary tables", module);
return false;
}
queryInfo.addJoin( joinEntity, joinEntity, displayObject.getAttribEntity(), aliasName, Boolean.valueOf(false), joinList );
Iterator conditionIter = conditionMap.entrySet().iterator();
while ( conditionIter.hasNext())
{
Map.Entry set = (Map.Entry) conditionIter.next();
String fieldName = (String) set.getKey();
String fieldValue = (String) set.getValue();
queryInfo.addCondition( aliasName, "c" + aliasName + fieldName, fieldName, EntityOperator.EQUALS, fieldValue );
}
String listDisplayField = displayObject.getAttribEntityDisplayDef();
if ( listDisplayField.indexOf(";") > 0)
listDisplayField = listDisplayField.substring(listDisplayField.lastIndexOf(";") + 1);
queryInfo.addCondition( aliasName, "c" + aliasName + listDisplayField, listDisplayField, searchOperator, searchValue);
return true;
} catch (GenericEntityException e)
{
Debug.logError("Unable to generate search on lookup table" + e.getMessage(), module);
e.printStackTrace();
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -