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.base.util.UtilMisc;
028: import org.ofbiz.entity.GenericDelegator;
029: import org.ofbiz.entity.GenericEntityException;
030: import org.ofbiz.entity.GenericValue;
031:
032: import com.sourcetap.sfa.util.Preference;
033: import com.sourcetap.sfa.util.UserInfo;
034:
035: /**
036: * DOCUMENT ME!
037: *
038: */
039: public class UIDealStageDropDown extends UIDropDown {
040:
041: public static final String module = UIDealStageDropDown.class
042: .getName();
043:
044: public UIDealStageDropDown() {
045: }
046:
047: /**
048: * Return a list of values for a drop down using a UI Display Object defined in the data base.
049: * This method overrides the parent class.
050: *
051: * @author John Nutting
052: *
053: * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
054: * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
055: * @param orderDef List of fields defining the sort order of the drop down values
056: * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
057: * @param fieldInfo Reference to field info object containing attributes of the current field
058: * @param userInfo Reference to user info object containing information about the currently logged-in user
059: *
060: * @return List of generic values to be displayed in the drop down. This will be null if an error occurs.
061: */
062: public List getDropDownValues(GenericDelegator delegator,
063: UIDisplayObject uiDisplayObject, ArrayList orderDef,
064: Vector entityDetailsVector, UIFieldInfo fieldInfo,
065: UserInfo userInfo) {
066: return getDropDownValuesDynamic(delegator, new HashMap(),
067: userInfo);
068: }
069:
070: /**
071: * Return a list of values based on filter criteria. This is used by the dynamic filtered drop downs
072: * which are modified via DHTML. This method must be overridden in a desdendent class.<BR><BR>Note: This method
073: * is only used when the drop down is updated dynamically.
074: * When the screen is first displayed, the getDropDownValues method is used.
075: *
076: * @see #getDropDownValues(GenericDelegator, UIDisplayObject, ArrayList, Vector, UIFieldInfo, UserInfo)
077: *
078: * @author <a href='mailto:steve_fowler@sourcetap.com'>Steve Fowler</a>
079: * @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
080: *
081: * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
082: * @param filterValues Map containing field/value pairs to be used for filtering the drop down list
083: * @param userInfo Reference to user info object containing information about the currently logged-in user
084: *
085: * @return List of generic values to be displayed in the drop down. This will be null if an error occurs.
086: */
087: public List getDropDownValuesDynamic(GenericDelegator delegator,
088: Map filterValues, UserInfo userInfo) {
089:
090: Preference preference = new Preference(delegator);
091: String salesProcess = preference.getPreference(userInfo
092: .getAccountId(), "SALES_PROCESS", "standard");
093: try {
094:
095: String dealStageTypeId = "1";
096: List dealStageTypeList = delegator.findByAnd(
097: "DealStageType", UtilMisc.toMap("accountId",
098: userInfo.getAccountId(),
099: "dealStageTypeName", salesProcess), null);
100: if (dealStageTypeList != null
101: && !dealStageTypeList.isEmpty()) {
102: GenericValue dealStageTypeGV = (GenericValue) dealStageTypeList
103: .get(0);
104: dealStageTypeId = dealStageTypeGV
105: .getString("dealStageTypeId");
106: }
107:
108: return delegator.findByAnd("DealStage", UtilMisc.toMap(
109: "stageTypeId", dealStageTypeId), UtilMisc
110: .toList("stageOrder"));
111: } catch (GenericEntityException e) {
112: Debug
113: .logError(
114: "[UIDealStageDropDown.getDropDownValues] Error retrieving the dropdown values: ",
115: module);
116: Debug.logError(e.getLocalizedMessage(), module);
117:
118: return new LinkedList();
119: }
120: }
121:
122: public static String getDefaultSaleProcessId(
123: GenericDelegator delegator, UserInfo userInfo) {
124: Preference preference = new Preference(delegator);
125: String salesProcess = preference.getPreference(userInfo
126: .getAccountId(), "SALES_PROCESS", "standard");
127: String dealStageTypeId = "1";
128:
129: try {
130:
131: List dealStageTypeList = delegator.findByAnd(
132: "DealStageType", UtilMisc.toMap("accountId",
133: userInfo.getAccountId(),
134: "dealStageTypeName", salesProcess), null);
135: if (dealStageTypeList != null
136: && !dealStageTypeList.isEmpty()) {
137: GenericValue dealStageTypeGV = (GenericValue) dealStageTypeList
138: .get(0);
139: dealStageTypeId = dealStageTypeGV
140: .getString("dealStageTypeId");
141: }
142:
143: } catch (GenericEntityException e) {
144: Debug
145: .logError(
146: "[UIDealStageDropDown.getDropDownValues] Error retrieving the dropdown values: ",
147: module);
148: Debug.logError(e.getLocalizedMessage(), module);
149: }
150:
151: return dealStageTypeId;
152: }
153:
154: public static List getDefaultSalesProcessStages(
155: GenericDelegator delegator, UserInfo userInfo) {
156: Preference preference = new Preference(delegator);
157: String salesProcess = preference.getPreference(userInfo
158: .getAccountId(), "SALES_PROCESS", "standard");
159: try {
160:
161: String dealStageTypeId = "1";
162: List dealStageTypeList = delegator.findByAnd(
163: "DealStageType", UtilMisc.toMap("accountId",
164: userInfo.getAccountId(),
165: "dealStageTypeName", salesProcess), null);
166: if (dealStageTypeList != null
167: && !dealStageTypeList.isEmpty()) {
168: GenericValue dealStageTypeGV = (GenericValue) dealStageTypeList
169: .get(0);
170: dealStageTypeId = dealStageTypeGV
171: .getString("dealStageTypeId");
172: }
173:
174: return delegator.findByAnd("DealStage", UtilMisc.toMap(
175: "stageTypeId", dealStageTypeId), UtilMisc
176: .toList("stageOrder"));
177: } catch (GenericEntityException e) {
178: Debug
179: .logError(
180: "[UIDealStageDropDown.getDropDownValues] Error retrieving the dropdown values: ",
181: module);
182: Debug.logError(e.getLocalizedMessage(), module);
183:
184: return new LinkedList();
185: }
186: }
187: }
|