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

📄 uidropdown.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.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;

import com.sourcetap.sfa.util.UserInfo;


/**
 * This class is used by the UI builder to display a drop down list on the screen.
 *
 * @author  <a href='mailto:steve_fowler@sourcetap.com'>Steve Fowler</a>
 * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
 */
public class UIDropDown {
	public static final String module = UIDropDown.class.getName();


    /**
     * Constructor
     */
    public UIDropDown() {
    }

    /**
     * Return a list of values for a drop down using a UI Display Object defined in the data base.
     * This method should be overridden in a custom class for custom drop down population.  Note: This
     * method is only used when the screen is first drawn.  If the drop down list is updated dynamically, the
     * getDropDownValuesDynamic method is used.
     *
     * @see #getDropDownValuesDynamic(GenericDelegator, Map, UserInfo)
     *
     * @author  <a href='mailto:steve_fowler@telluridetechnologies.com'>Steve Fowler</a>
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     *
     * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
     * @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 orderDef List of fields defining the sort order of the drop down values
     * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
     * @param fieldInfo Reference to field info object containing attributes of the current field
     * @param userInfo Reference to user info object containing information about the currently logged-in user
     *
     * @return List of generic values to be displayed in the drop down.  This will be null if an error occurs.
     */
    public List getDropDownValues(GenericDelegator delegator,
        UIDisplayObject uiDisplayObject, ArrayList orderDef,
        Vector entityDetailsVector, UIFieldInfo fieldInfo, UserInfo userInfo) {
        // Use the find method display attribute of the display object.
        if (uiDisplayObject.getAttribEntityFindMethod().equals("ALL")) {
            // Find all entities.
            try {
                return delegator.findAllCache(uiDisplayObject.getAttribEntity(),
                    orderDef);
            } catch (GenericEntityException e) {
                Debug.logError("Error searching for drop down values: " +
                    e.getLocalizedMessage(), module);

                return null;
            }
        } else if (uiDisplayObject.getAttribEntityFindMethod().equals("ATTRIBUTE_MATCH")) {
            // Need to find only selected entities.
            if (uiDisplayObject.getAttribEntityFindDef().trim().equals("")) {
                // The find definition not specified. Can't do the find. Return empty List.
                Debug.logWarning(
                    "Attribute ENTITY_FIND_DEF not specified in display object.", module);

                return null;
            }

            // Decode the entity find definition into a hash map that can be passed
            // to the findByAnd function.
            Debug.logVerbose(
                    "About to call decodeEntityFindDef to decode find def '" +
                    uiDisplayObject.getAttribEntityFindDef() + "'.", module);

            HashMap entityFindMap = UIUtility.decodeEntityFindDef(uiDisplayObject.getAttribEntityFindDef(),
                    entityDetailsVector,
                    fieldInfo.getUiAttribute().getAttributeName());

            if (entityFindMap == null) {

                Debug.logError("Invalid ENTITY_FIND_DEF definition: '" +
                    uiDisplayObject.getAttribEntityFindDef() + "'", module);

                return null;
            }

            Debug.logVerbose(
                    "Finished calling decodeEntityFindDef to decode find def '" +
                    uiDisplayObject.getAttribEntityFindDef() + "'.", module);
            Debug.logVerbose("entityFindMap           -> " +
                    entityFindMap.toString(), module);
            

            try {
                return delegator.findByAndCache(uiDisplayObject.getAttribEntity(),
                    entityFindMap, orderDef);
            } catch (GenericEntityException e) {
                Debug.logError(
                    "Error searching for drop down values by And: " +
                    e.getLocalizedMessage(), module);

                return null;
            }
        } else if (uiDisplayObject.getAttribEntityFindMethod().equals("CUSTOM_CLASS")) {
            // There is a custom class built to find only selected entities to the drop down.
            // The descendent object should take care of this.
            Debug.logWarning("Method should be overriddent in class " +
                uiDisplayObject.getAttribEntityFindDef() + "!", module);

            return null;
        } else {
            // Invalid find method.
            // Just create a hidden field AND show the value as text in the table cell.
            Debug.logWarning(
                "[UIDropDown.displayField]: Invalid find method: '" +
                uiDisplayObject.getAttribEntityFindMethod() + "'", module);

            return null;
        }
    }

    /**
     * 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 GenericValue getReadOnlyValue(String fieldValue,
        String attributeName, UIDisplayObject uiDisplayObject,
        Vector entityDetailsVector, GenericDelegator delegator) {

        return UIUtility.getReadOnlyValue(fieldValue, attributeName,
            uiDisplayObject, entityDetailsVector, delegator);
    }

    /**
     * Return an array of data value/display value pairs to be passed to the getDisplayHtml
     * method.  In this root version of this method, the list of generic values returned by
     * the getDropDownValues is simlply converted to an array using the decodeValueArray
     * method.  However, this method may be overridden in the descendent if special processing
     * is needed, as may be the case when two different types of entities are to be combined
     * into the same drop list.
     *
     * @see #getDropDownValues(GenericDelegator, UIDisplayObject, ArrayList, Vector, UIFieldInfo, UserInfo)
     * @see #decodeValueArray(String, String, String, List)
     *
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     *
     * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
     * @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 orderDef List of fields defining the sort order of the drop down values
     * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
     * @param fieldInfo Reference to field info object containing attributes of the current field
     * @param userInfo Reference to user info object containing information about the currently logged-in user
     *
     * @return List of generic values to be displayed in the drop down.  This will be null if an error occurs.
     */
    public String[][] getValuePairArray(GenericDelegator delegator,
        UIDisplayObject uiDisplayObject, ArrayList orderDef,
        Vector entityDetailsVector, UIFieldInfo fieldInfo, UserInfo userInfo) {
        return decodeValueArray(uiDisplayObject.getAttribEntityValueDef(),
            uiDisplayObject.getAttribEntityDisplayDef(),
            fieldInfo.getUiAttribute().getAttributeName(),
            getDropDownValues(delegator, uiDisplayObject, orderDef,
                entityDetailsVector, fieldInfo, userInfo));
    }

    /**
     * Return a data value/display value pair to be passed to the getSelectHtmlReadOnly
     * method.  In this root version of this method, the generic value returned by
     * the getReadOnlyValue method is simlply converted to an array using the decodeValue
     * method.  However, this method may be overridden in the descendent if special processing
     * is needed, as may be the case when two different types of entities are to be combined
     * into the same drop list.
     *
     * @see #getReadOnlyValue(String, String, UIDisplayObject, Vector, GenericDelegator)
     * @see #decodeValue(String, String, String, Object)
     * @see #getSelectHtmlReadOnly(String, String, String, UIDisplayObject, String[], GenericDelegator)
     *
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     *

⌨️ 快捷键说明

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