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.ui;
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: import org.ofbiz.entity.condition.EntityCondition;
030: import org.ofbiz.entity.condition.EntityExpr;
031: import org.ofbiz.entity.condition.EntityOperator;
032:
033: import com.sourcetap.sfa.security.SecurityLinkInfo;
034: import com.sourcetap.sfa.security.SecurityWrapper;
035: import com.sourcetap.sfa.util.UserInfo;
036:
037: /**
038: * DOCUMENT ME!
039: *
040: */
041: public class UIContactDropDown extends UIDropDown {
042: public static final String module = UIContactDropDown.class
043: .getName();
044:
045: public UIContactDropDown() {
046: }
047:
048: /**
049: * Return a list of values for a drop down using a UI Display Object defined in the data base.
050: * This method overrides the parent class. Note: This
051: * method is only used when the screen is first drawn. If the drop down list is updated dynamically, the
052: * getDropDownValuesDynamic method is used.
053: *
054: * @see #getDropDownValuesDynamic(GenericDelegator, Map, UserInfo)
055: *
056: * @author John Nutting
057: *
058: * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
059: * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
060: * @param orderDef List of fields defining the sort order of the drop down values
061: * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
062: * @param fieldInfo Reference to field info object containing attributes of the current field
063: * @param userInfo Reference to user info object containing information about the currently logged-in user
064: *
065: * @return List of generic values to be displayed in the drop down. This will be null if an error occurs.
066: */
067: public List getDropDownValues(GenericDelegator delegator,
068: UIDisplayObject uiDisplayObject, ArrayList orderDef,
069: Vector entityDetailsVector, UIFieldInfo fieldInfo,
070: UserInfo userInfo) {
071: String accountId = UIUtility.getAttributeValue(
072: entityDetailsVector, "Contact", "accountId");
073:
074: HashMap map = new HashMap();
075: map.put("accountId", accountId);
076:
077: return getDropDownValuesDynamic(delegator, map, userInfo);
078: }
079:
080: /**
081: * Return a list of values based on filter criteria. This is used by the dynamic filtered drop downs
082: * which are modified via DHTML. This method overrides the standard method.<BR><BR>Note: This method
083: * is only used when the drop down is updated dynamically.
084: * When the screen is first displayed, the getDropDownValues method is used.
085: *
086: * @see #getDropDownValues(GenericDelegator, UIDisplayObject, ArrayList, Vector, UIFieldInfo, UserInfo)
087: *
088: * @author John Nutting
089: *
090: * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
091: * @param filterValues Map containing field/value pairs to be used for filtering the drop down list
092: * @param userInfo Reference to user info object containing information about the currently logged-in user
093: *
094: * @return List of generic values to be displayed in the drop down. This will be null if an error occurs.
095: */
096: public List getDropDownValuesDynamic(GenericDelegator delegator,
097: Map filterValues, UserInfo userInfo) {
098: ArrayList orderBy = new ArrayList();
099: orderBy.add("lastName");
100: orderBy.add("firstName");
101:
102: EntityCondition condition = null;
103:
104: String accountId = (String) filterValues.get("accountId");
105:
106: if ((accountId != null)) {
107: condition = new EntityExpr("accountId",
108: EntityOperator.EQUALS, accountId);
109: }
110:
111: try {
112: return SecurityWrapper.findByCondition("Contact",
113: condition, orderBy, userInfo, new SecurityLinkInfo(
114: "Account", "accountId", true), delegator);
115: } catch (GenericEntityException e) {
116: Debug
117: .logError(
118: "[UIContactDropDown.getDropDownValues] Error retrieving the dropdown values: ",
119: module);
120: Debug.logError(e.getLocalizedMessage(), module);
121:
122: return new LinkedList();
123: }
124: }
125: }
|