⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uiutility.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * 
 * Copyright (c) 2004 SourceTap - www.sourcetap.com
 *
 *  The contents of this file are subject to the SourceTap Public License 
 * ("License"); You may not use this file except in compliance with the 
 * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 */

package com.sourcetap.sfa.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;

import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericPK;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityComparisonOperator;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityConditionList;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.model.DynamicViewEntity;
import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.model.ModelKeyMap;

import com.sourcetap.sfa.event.GenericEventProcessor;
import com.sourcetap.sfa.util.EntityHelper;
import com.sourcetap.sfa.util.QueryInfo;


/**
 * DOCUMENT ME!
 *
 */
public class UIUtility {
	public static final String module = UIUtility.class.getName();

    /**
     * DOCUMENT ME!
     *
     * @param entityDisplayDef 
     * @param genericValueVector 
     * @param currentAttibuteName 
     *
     * @return 
     */
    public static String decodeEntityDisplayDef(String entityDisplayDef,
        Vector genericValueVector, String currentAttibuteName) {
        if (entityDisplayDef == null) {
            Debug.logError("entityDisplayDef is null", module);

            return "ERROR";
        }

        if (genericValueVector.size() == 0) {
            Debug.logError("genericValueVector is empty.", module);

            return "ERROR";
        }

        if (currentAttibuteName == null) {
            Debug.logError("currentAttibuteName is null", module);

            return "ERROR";
        }

        Debug.logVerbose("[decodeEntityDisplayDef] entityDisplayDef: " +
                entityDisplayDef, module);

        Debug.logVerbose("[decodeEntityDisplayDef] genericValueVector: " +
                genericValueVector.toString(), module);

        Debug.logVerbose("[decodeEntityDisplayDef] currentAttibuteName: " +
                currentAttibuteName, module);

        // Dissect the display definition.
        // Example:
        // *  attribEntityDisplayDef = 'sicCodeId;" - ";SicCode.sicCodeDescription'
        // *  Resulting Display Value = '2074 - Cottonseed Oil Mills'
        String displayItem = "";
        StringTokenizer tokSemicolon = new StringTokenizer(entityDisplayDef, ";");
        GenericValue genericValue = null;
        String attributeName = "";

        while (tokSemicolon.hasMoreTokens()) {
            String valueDef = tokSemicolon.nextToken();

            Debug.logVerbose("valueDef = " + valueDef, module);

            if (valueDef.indexOf("\"") != -1) {
                // This is a literal string. Get the part between the 2 quotes and append it
                // directly onto the display value.
                int startPos = valueDef.indexOf("\"");
                int endPos = valueDef.lastIndexOf("\"");

                if ((startPos < 0) || (startPos >= (valueDef.length() - 1))) {
                    startPos = 0; // Missing first quote
                }

                if (endPos < (valueDef.length() - 1)) {
                    endPos = valueDef.length() - 1; // Missing last quote
                }

                Debug.logVerbose("startPos = " + String.valueOf(startPos), module);

                Debug.logVerbose("endPos = " + String.valueOf(endPos), module);

                displayItem += valueDef.substring(startPos + 1, endPos);
            } else {
                if (valueDef.indexOf(".") != -1) {

                    Debug.logVerbose("Found a period.", module);

                    StringTokenizer tokPeriod = new StringTokenizer(valueDef,
                            ".");
                    String entityName = tokPeriod.nextToken();
                    attributeName = tokPeriod.nextToken();

                    Debug.logVerbose("entityName = " + entityName, module);

                    Debug.logVerbose("attributeName = " + attributeName, module);

                    Iterator genericValueVectorI = genericValueVector.iterator();

                    while (genericValueVectorI.hasNext()) {
                        GenericValue testGV = (GenericValue) genericValueVectorI.next();

                        if (testGV.getEntityName().equals(entityName)) {

                            Debug.logVerbose("Found generic value with entity name " +
                                    entityName, module);

                            genericValue = testGV;
                        }
                    }
                } else {
                    Debug.logVerbose("Did not find a period.", module);

                    genericValue = (GenericValue) genericValueVector.get(0);
                    attributeName = valueDef;
                }

                // This is not a literal.  Treat it as an attribute name.
                if (attributeName.equals("#currentField")) {
                    attributeName = (currentAttibuteName == null) ? ""
                                                                  : currentAttibuteName;
                }

                try {
                    displayItem += ((genericValue.get(attributeName) != null)
                    ? String.valueOf(genericValue.get(attributeName)) : "");
                } catch (Exception e) {
                    //					throw new GenericEntityException("");
                    Debug.logError(e.getMessage(),module);
                    Debug.logError("Entity display definition \"" +
                        entityDisplayDef + "\" not valid", module);

                    //                         for genericValue " + genericValue.toString() +
                    //						".  Error message: " + e.toString());
                    return "ERROR";
                }
            }
        }

        return displayItem;
    }

    /**
     * DOCUMENT ME!
     *
     * @param entityFindDef 
     * @param entityDetailsVector 
     * @param currentAttibuteName 
     *
     * @return 
     */
    public static HashMap decodeEntityFindDef(String entityFindDef,
        Vector entityDetailsVector, String currentAttributeName) {
        // 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 = "";
        HashMap entityFindMap = new HashMap();
        StringTokenizer tokSemicolon = new StringTokenizer(entityFindDef, ";");
        String entityName = "";

        Debug.logVerbose(
                "-->[UIUtility.decodeEntityFindDef] Inside decodeEntityFindDef method.  Find def is '" +
                entityFindDef + "'.", module);

        while (tokSemicolon.hasMoreTokens()) {
            Debug.logVerbose(
                    "-->[UIUtility.decodeEntityFindDef] Found a semicolon", module);

            String pair = tokSemicolon.nextToken();
            StringTokenizer tokColon = new StringTokenizer(pair, ":");

            if (tokColon.countTokens() != 2) {
                Debug.logWarning(
                        "-->[UIUtility.decodeEntityFindDef] No colon found in '" +
                        pair + "'", module);
                

                Debug.logWarning(
                    "[UIUtility.decodeEntityFindDef]: Problem with entity find definition \"" +
                    entityFindDef + "\":", module);
                Debug.logWarning(
                    "There must be 2 items in each pair separated by colons.", module);

                return entityFindMap;
            } else {
                Debug.logVerbose(
                        "-->[UIUtility.decodeEntityFindDef] Colon found in '" +
                        pair + "'", module);

                String findAttributeName = tokColon.nextToken();
                if ( findAttributeName.equals("#currentField"))
                	findAttributeName = currentAttributeName;

                //				String screenAttributeString = tokColon.nextToken();
                String attributeValueSource = tokColon.nextToken();

                try {
                    findAttributeValue = decodeAttributeValue(attributeValueSource,
                            entityDetailsVector, currentAttributeName);
                } catch (GenericEntityException e) {
                    Debug.logError(
                        "[UIUtility.decodeFieldValue]: Problem with entity find definition \"" +
                        entityFindDef + "\": " + e.getLocalizedMessage(), module);
                    entityFindMap = null;

                    return entityFindMap;
                }

                //jmn start

                /*
                                                GenericValue screenEntityDetails = null;
                                                if(screenAttributeString.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.

                                                        // If there is a "." in the attribute name, split off the entity name.
                                                        StringTokenizer tokPeriod = new StringTokenizer(screenAttributeString, ".");
                                                        if(tokPeriod.countTokens() == 1) {
                                                                // There is no "." in the attribute string.  Assume we need to use the primary screen entity.
                                                                screenEntityName = ((GenericValue)(entityDetailsVector.get(0))).getEntityName();
                                                                screenAttributeName = screenAttributeString;
                                                        } else {
                                                                // Need to get the entity specified before the "." in the attribute name string.
                                                                screenEntityName = tokPeriod.nextToken();
                                                                screenAttributeName = tokPeriod.nextToken();
                                                        }
                                                        tokPeriod = null;
                                                        if (screenAttributeName.equals("#currentField")) {
                                                                screenAttributeName = currentAttibuteName==null ? "" : currentAttibuteName;
                                                        }

                                                        // 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) {
                                                                Debug.logWarning("[UIUtility.decodeEntityFindDef]: Problem with entity find definition \"" + entityFindDef + "\":");
                                                                Debug.logWarning(e.getMessage());
                                                                entityFindMap = null;
                                                                return entityFindMap;
                                                        }
                                                        findAttributeValue = screenEntityDetails.getString(screenAttributeName);
                                                } else {
                                                        // This is a literal value because it has quote marks around it.
                                                        findAttributeValue = screenAttributeString.substring(screenAttributeString.indexOf("\"") + 1, screenAttributeString.lastIndexOf("\""));
                                                }
                */

                //jmn end
                // Put the attribute name and the screen value to which we are comparing into the find map.
                Debug.logVerbose(
                        "-->[UIUtility.decodeEntityFindDef] Appending onto entityFindMap: " +
                        findAttributeName + "/" + findAttributeValue, module);

                entityFindMap.put(findAttributeName, findAttributeValue);
            }

            tokColon = null;
        }

        tokSemicolon = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -