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.condition.EntityCondition;
031: import org.ofbiz.entity.condition.EntityConditionList;
032: import org.ofbiz.entity.condition.EntityExpr;
033: import org.ofbiz.entity.condition.EntityOperator;
034: import org.ofbiz.entity.model.DynamicViewEntity;
035: import org.ofbiz.entity.model.ModelKeyMap;
036:
037: import com.sourcetap.sfa.util.EntityHelper;
038: import com.sourcetap.sfa.util.UserInfo;
039:
040: /**
041: * DOCUMENT ME!
042: *
043: */
044: public class UIAttributeDropDown extends UIDropDown {
045: public static final String module = UIAttributeDropDown.class
046: .getName();
047:
048: public UIAttributeDropDown() {
049: }
050:
051: /**
052: * Return a list of values for a drop down using a UI Display Object defined in the data base.
053: * This method overrides the parent class. Note: This
054: * method is only used when the screen is first drawn. If the drop down list is updated dynamically, the
055: * getDropDownValuesDynamic method is used.
056: *
057: * @see #getDropDownValuesDynamic(GenericDelegator, Map, UserInfo)
058: *
059: * @author John Nutting
060: *
061: * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
062: * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
063: * @param orderDef List of fields defining the sort order of the drop down values
064: * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
065: * @param fieldInfo Reference to field info object containing attributes of the current field
066: * @param userInfo Reference to user info object containing information about the currently logged-in user
067: *
068: * @return List of generic values to be displayed in the drop down. This will be null if an error occurs.
069: */
070: public List getDropDownValues(GenericDelegator delegator,
071: UIDisplayObject uiDisplayObject, ArrayList orderDef,
072: Vector entityDetailsVector, UIFieldInfo fieldInfo,
073: UserInfo userInfo) {
074: String sectionId = UIUtility
075: .getAttributeValue(entityDetailsVector,
076: "UiScreenSectionInfo", "sectionId");
077:
078: HashMap map = new HashMap();
079: map.put("sectionId", sectionId);
080:
081: return getDropDownValuesDynamic(delegator, map, userInfo);
082: }
083:
084: /**
085: * Return a list of values based on filter criteria. This is used by the dynamic filtered drop downs
086: * which are modified via DHTML. This method overrides the standard method.<BR><BR>Note: This method
087: * is only used when the drop down is updated dynamically.
088: * When the screen is first displayed, the getDropDownValues method is used.
089: *
090: * @see #getDropDownValues(GenericDelegator, UIDisplayObject, ArrayList, Vector, UIFieldInfo, UserInfo)
091: *
092: * @author John Nutting
093: *
094: * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
095: * @param filterValues Map containing field/value pairs to be used for filtering the drop down list
096: * @param userInfo Reference to user info object containing information about the currently logged-in user
097: *
098: * @return List of generic values to be displayed in the drop down. This will be null if an error occurs.
099: */
100: public List getDropDownValuesDynamic(GenericDelegator delegator,
101: Map filterValues, UserInfo userInfo) {
102: ArrayList orderBy = new ArrayList();
103: orderBy.add("attributeName");
104:
105: ArrayList findClauses = new ArrayList();
106:
107: String sectionId = (String) filterValues.get("sectionId");
108:
109: if ((sectionId != null)) {
110:
111: // Find the last query used by this party ID for this screen section.
112: // select X from ui_attribute a, ui_screen_section_entity sse where a.entity_id = sse.entity_id and sse.section_id = <sectionId> order by attribute_name
113: DynamicViewEntity dve = EntityHelper
114: .createDynamicViewEntity(delegator, "UiAttribute");
115: dve.addMemberEntity("UiScreenSectionEntity",
116: "UiScreenSectionEntity");
117: dve.addViewLink("UiAttribute", "UiScreenSectionEntity",
118: Boolean.FALSE, UtilMisc.toList(new ModelKeyMap(
119: "entityId", "entityId")));
120: dve.addAlias("UiScreenSectionEntity", "sectionId", null,
121: null, null, null, null);
122:
123: EntityCondition condition = new EntityConditionList(
124: UtilMisc.toList(new EntityExpr("sectionId",
125: EntityOperator.EQUALS, sectionId)),
126: EntityOperator.AND);
127:
128: try {
129: return EntityHelper.findByCondition(delegator, dve,
130: condition, orderBy);
131: } catch (GenericEntityException e) {
132: Debug
133: .logError(
134: "[UIAttributeDropDown.getDropDownValues] Error retrieving the dropdown values: ",
135: module);
136: Debug.logError(e.getLocalizedMessage(), module);
137:
138: return new LinkedList();
139: }
140: } else {
141: try {
142: return delegator.findAll("UiAttribute", orderBy);
143: } catch (GenericEntityException e) {
144: Debug
145: .logError(
146: "[UIAttributeDropDown.getDropDownValues] Error retrieving the dropdown values: ",
147: module);
148: Debug.logError(e.getLocalizedMessage(), module);
149:
150: return new LinkedList();
151: }
152: }
153: }
154: }
|