/*
*
* 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.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.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import com.sourcetap.sfa.security.SecurityLinkInfo;
import com.sourcetap.sfa.security.SecurityWrapper;
import com.sourcetap.sfa.util.UserInfo;
/**
* DOCUMENT ME!
*
*/
public class UIContactDropDown extends UIDropDown {
public static final String module = UIContactDropDown.class.getName();
public UIContactDropDown() {
}
/**
* Return a list of values for a drop down using a UI Display Object defined in the data base.
* This method overrides the parent class. 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 John Nutting
*
* @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) {
String accountId = UIUtility.getAttributeValue(entityDetailsVector,
"Contact", "accountId");
HashMap map = new HashMap();
map.put("accountId", accountId);
return getDropDownValuesDynamic(delegator, map, userInfo);
}
/**
* Return a list of values based on filter criteria. This is used by the dynamic filtered drop downs
* which are modified via DHTML. This method overrides the standard method.<BR><BR>Note: This method
* is only used when the drop down is updated dynamically.
* When the screen is first displayed, the getDropDownValues method is used.
*
* @see #getDropDownValues(GenericDelegator, UIDisplayObject, ArrayList, Vector, UIFieldInfo, UserInfo)
*
* @author John Nutting
*
* @param delegator Reference to the OFBIZ delegator being used to connect to the data base
* @param filterValues Map containing field/value pairs to be used for filtering the drop down list
* @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 getDropDownValuesDynamic(GenericDelegator delegator,
Map filterValues, UserInfo userInfo) {
ArrayList orderBy = new ArrayList();
orderBy.add("lastName");
orderBy.add("firstName");
EntityCondition condition = null;
String accountId = (String) filterValues.get("accountId");
if ((accountId != null)) {
condition = new EntityExpr( "accountId", EntityOperator.EQUALS, accountId);
}
try {
return SecurityWrapper.findByCondition("Contact", condition,
orderBy, userInfo,
new SecurityLinkInfo("Account", "accountId", true), delegator);
} catch (GenericEntityException e) {
Debug.logError(
"[UIContactDropDown.getDropDownValues] Error retrieving the dropdown values: ", module);
Debug.logError(e.getLocalizedMessage(), module);
return new LinkedList();
}
}
}