001: /*
002: *
003: * Copyright (c) 2004 SourceTap - www.sourcetap.com
004: *
005: * The contents of this file are subject to the SourceTap Public License
006: * ("License"); You may not use this file except in compliance with the
007: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010: * the specific language governing rights and limitations under the License.
011: *
012: * The above copyright notice and this permission notice shall be included
013: * in all copies or substantial portions of the Software.
014: *
015: */
016:
017: package com.sourcetap.sfa.address;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.LinkedList;
022: import java.util.List;
023: import java.util.Map;
024: import java.util.Vector;
025:
026: import org.ofbiz.base.util.Debug;
027: import org.ofbiz.entity.GenericDelegator;
028: import org.ofbiz.entity.GenericEntityException;
029:
030: import com.sourcetap.sfa.ui.UIDisplayObject;
031: import com.sourcetap.sfa.ui.UIDropDown;
032: import com.sourcetap.sfa.ui.UIFieldInfo;
033: import com.sourcetap.sfa.ui.UIUtility;
034: import com.sourcetap.sfa.util.UserInfo;
035:
036: /**
037: * DOCUMENT ME!
038: *
039: */
040: public class StateDropDown extends UIDropDown {
041: public static final String module = StateDropDown.class.getName();
042:
043: public StateDropDown() {
044: }
045:
046: /**
047: * Return a list of values for a drop down using a UI Display Object defined in the data base.
048: * This method overrides the parent class. Note: This
049: * method is only used when the screen is first drawn. If the drop down list is updated dynamically, the
050: * getDropDownValuesDynamic method is used.
051: *
052: * @see #getDropDownValuesDynamic(GenericDelegator, Map, UserInfo)
053: *
054: * @author John Nutting
055: *
056: * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
057: * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
058: * @param orderDef List of fields defining the sort order of the drop down values
059: * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
060: * @param fieldInfo Reference to field info object containing attributes of the current field
061: * @param userInfo Reference to user info object containing information about the currently logged-in user
062: *
063: * @return List of generic values to be displayed in the drop down. This will be null if an error occurs.
064: */
065: public List getDropDownValues(GenericDelegator delegator,
066: UIDisplayObject uiDisplayObject, ArrayList orderDef,
067: Vector entityDetailsVector, UIFieldInfo fieldInfo,
068: UserInfo userInfo) {
069: String country = UIUtility.getAttributeValue(
070: entityDetailsVector, "Address", "country");
071:
072: HashMap map = new HashMap();
073: map.put("country", country);
074:
075: return getDropDownValuesDynamic(delegator, map, userInfo);
076: }
077:
078: /**
079: * Return a list of values based on filter criteria. This is used by the dynamic filtered drop downs
080: * which are modified via DHTML. This method overrides the standard method.<BR><BR>Note: This method
081: * is only used when the drop down is updated dynamically.
082: * When the screen is first displayed, the getDropDownValues method is used.
083: *
084: * @see #getDropDownValues(GenericDelegator, UIDisplayObject, ArrayList, Vector, UIFieldInfo, UserInfo)
085: *
086: * @author John Nutting
087: *
088: * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
089: * @param filterValues Map containing field/value pairs to be used for filtering the drop down list
090: * @param userInfo Reference to user info object containing information about the currently logged-in user
091: *
092: * @return List of generic values to be displayed in the drop down. This will be null if an error occurs.
093: */
094: public List getDropDownValuesDynamic(GenericDelegator delegator,
095: Map filterValues, UserInfo userInfo) {
096: ArrayList orderBy = new ArrayList();
097: orderBy.add("codeValue");
098:
099: HashMap findMap = new HashMap();
100:
101: String country = (String) filterValues.get("country");
102:
103: if ((country != null)) {
104: // Country is selected. Return list of states for the selected country.
105: findMap.put("codeTypeId", "STATE");
106: findMap.put("parentCodeTypeId", "COUNTRY");
107: findMap.put("parentCodeId", country);
108:
109: try {
110: return delegator.findByAnd("Code", findMap, orderBy);
111: } catch (GenericEntityException e) {
112: Debug.logError(
113: "Error retrieving the dropdown values: ",
114: module);
115: Debug.logError(e.getLocalizedMessage(), module);
116:
117: return new LinkedList();
118: }
119: } else {
120: // No country is selected. Return an empty list of states.
121: return new LinkedList();
122: }
123: }
124: }
|