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.customization;
018:
019: import java.util.HashMap;
020: import java.util.List;
021:
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import org.ofbiz.base.util.Debug;
026: import org.ofbiz.entity.GenericDelegator;
027: import org.ofbiz.entity.GenericEntityException;
028: import org.ofbiz.entity.GenericValue;
029: import org.ofbiz.entity.model.ModelEntity;
030:
031: import com.sourcetap.sfa.event.DataMatrix;
032: import com.sourcetap.sfa.event.GenericEventProcessor;
033: import com.sourcetap.sfa.event.GenericWebEventProcessor;
034: import com.sourcetap.sfa.ui.UICache;
035: import com.sourcetap.sfa.ui.UIWebScreenSection;
036: import com.sourcetap.sfa.util.UserInfo;
037:
038: /**
039: * DOCUMENT ME!
040: *
041: */
042: public class UIDisplayObjectAttribWebEventProcessor extends
043: GenericWebEventProcessor {
044: public static final String module = UIDisplayObjectAttribWebEventProcessor.class
045: .getName();
046:
047: /**
048: * DOCUMENT ME!
049: *
050: * @param userInfo
051: * @param uiWebScreenSection
052: * @param request
053: * @param response
054: * @param delegator
055: * @param eventProcessor
056: * @param dataMatrix
057: * @param uiCache
058: *
059: * @return
060: */
061: protected int postUpdate(UserInfo userInfo,
062: UIWebScreenSection uiWebScreenSection,
063: HttpServletRequest request, HttpServletResponse response,
064: GenericDelegator delegator,
065: GenericEventProcessor eventProcessor,
066: DataMatrix dataMatrix, UICache uiCache) {
067:
068: // Clear UI cache.
069: uiCache.clear();
070:
071: return STATUS_CONTINUE;
072: }
073:
074: /**
075: * DOCUMENT ME!
076: *
077: * @param userInfo
078: * @param uiWebScreenSection
079: * @param request
080: * @param response
081: * @param delegator
082: * @param eventProcessor
083: * @param dataMatrix
084: * @param uiCache
085: *
086: * @return
087: */
088: protected int postInsert(UserInfo userInfo,
089: UIWebScreenSection uiWebScreenSection,
090: HttpServletRequest request, HttpServletResponse response,
091: GenericDelegator delegator,
092: GenericEventProcessor eventProcessor,
093: DataMatrix dataMatrix, UICache uiCache) {
094:
095: // Clear UI cache.
096: uiCache.clear();
097:
098: return STATUS_CONTINUE;
099: }
100:
101: /**
102: * DOCUMENT ME!
103: *
104: * @param userInfo
105: * @param uiWebScreenSection
106: * @param request
107: * @param response
108: * @param delegator
109: * @param eventProcessor
110: * @param primaryME
111: * @param fields
112: * @param uiCache
113: *
114: * @return
115: */
116: protected int postDelete(UserInfo userInfo,
117: UIWebScreenSection uiWebScreenSection,
118: HttpServletRequest request, HttpServletResponse response,
119: GenericDelegator delegator,
120: GenericEventProcessor eventProcessor,
121: ModelEntity primaryME, HashMap fields, UICache uiCache) {
122:
123: // Clear UI cache.
124: uiCache.clear();
125:
126: return STATUS_CONTINUE;
127: }
128:
129: /**
130: * DOCUMENT ME!
131: *
132: * @param userInfo
133: * @param uiWebScreenSection
134: * @param request
135: * @param response
136: * @param delegator
137: * @param eventProcessor
138: * @param dataMatrix
139: * @param entityNameList
140: *
141: * @return
142: */
143: protected int postCreate(UserInfo userInfo,
144: UIWebScreenSection uiWebScreenSection,
145: HttpServletRequest request, HttpServletResponse response,
146: GenericDelegator delegator,
147: GenericEventProcessor eventProcessor,
148: DataMatrix dataMatrix, List entityNameList) {
149:
150: // Get the empty generic value.
151: GenericValue displayObjectAttribGV = dataMatrix
152: .getCurrentBuffer().getGenericValue(0, 0);
153:
154: // Set default values on the new record so they will be displayed for the user to see before saving.
155: // This is done here instead of the regular event processor because the values have to be read from the
156: // request object parameters.
157: // Display Object ID
158: String displayObjectId = (request
159: .getParameter("displayObjectId") == null) ? ""
160: : request.getParameter("displayObjectId");
161:
162: displayObjectAttribGV.set("displayObjectId", displayObjectId);
163:
164: // Display Type ID
165: HashMap uiDisplayObjectFindMap = new HashMap();
166: uiDisplayObjectFindMap.put("displayObjectId", displayObjectId);
167:
168: try {
169: GenericValue uiDisplayObjectGV = delegator
170: .findByPrimaryKey("UiDisplayObject",
171: uiDisplayObjectFindMap);
172: String displayTypeId = uiDisplayObjectGV
173: .getString("displayTypeId");
174:
175: displayObjectAttribGV.set("displayTypeId", displayTypeId);
176: } catch (GenericEntityException e) {
177: Debug
178: .logError(
179: "[UIDisplayObjectAttribEventProcessor.postCreate] Error while looking for display object: "
180: + e.getLocalizedMessage(), module);
181: }
182:
183: return STATUS_CONTINUE;
184: }
185:
186: /**
187: * This function gets the application path to be used to reconstruct the URI when a
188: * UI History record is logged. Example: "/accounts"
189: * @author John Nutting
190: * @param url The URL used to open the screen section
191: * @return String containing the application path
192: */
193: protected String getUiHistoryAppPath(String url) {
194: return "/uiDisplayObjectAttribHeader";
195: }
196:
197: /**
198: * This function gets the description to store in the UI history table. This description
199: * will show up in the UI History drop list.
200: * @author John Nutting
201: * @param dataMatrix DataMatrix object containing the data from the screen
202: * @param delegator Generic delegator through which the data base is accessed
203: * @param action The action being performed on the screen
204: * @param uiWebScreenSection The UIWebScreenSection being used to construct the screen section
205: * @return String containing the UI History description
206: */
207: protected String getUiHistoryDescription(DataMatrix dataMatrix,
208: GenericDelegator delegator, String action,
209: UIWebScreenSection uiWebScreenSection) {
210: GenericValue primaryGV = dataMatrix.getCurrentBuffer()
211: .getGenericValue(0, 0);
212:
213: return "Display Obj Attrib: "
214: + primaryGV.getString("displayObjectId") + "/"
215: + primaryGV.getString("displayTypeId") + "/"
216: + primaryGV.getString("displayAttribId");
217: }
218: }
|