001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.web.struts.form;
017:
018: import java.util.HashMap;
019: import java.util.List;
020: import java.util.Map;
021:
022: import javax.servlet.http.HttpServletRequest;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.RiceConstants;
026: import org.kuali.core.datadictionary.HeaderNavigation;
027: import org.kuali.core.util.ActionFormUtilMap;
028: import org.kuali.core.util.TypedArrayList;
029: import org.kuali.core.util.WebUtils;
030: import org.kuali.core.web.struts.pojo.PojoFormBase;
031: import org.kuali.core.web.ui.ExtraButton;
032: import org.kuali.core.web.ui.KeyLabelPair;
033: import org.kuali.rice.KNSServiceLocator;
034:
035: /**
036: * This class common properites for all action forms.
037: */
038: public class KualiForm extends PojoFormBase {
039: private static final long serialVersionUID = 1L;
040: private String methodToCall;
041: private String refreshCaller;
042: private String anchor;
043: private Map<String, String> tabStates;
044: private Map actionFormUtilMap;
045: private Map displayedErrors = new HashMap();
046: private int currentTabIndex = 0;
047: private int arbitrarilyHighIndex = 1000000;
048:
049: private String navigationCss;
050: private HeaderNavigation[] headerNavigationTabs;
051: protected List<ExtraButton> extraButtons = new TypedArrayList(
052: ExtraButton.class);
053:
054: private KeyLabelPair additionalDocInfo1;
055: private KeyLabelPair additionalDocInfo2;
056: private boolean fieldLevelHelpEnabled;
057:
058: /**
059: * no args constructor which must init our tab states list
060: */
061: public KualiForm() {
062: this .tabStates = new HashMap<String, String>();
063: this .actionFormUtilMap = new ActionFormUtilMap();
064: }
065:
066: /**
067: * Checks for methodToCall parameter, and if not populated in form calls utility method to parse the string from the request.
068: */
069: public void populate(HttpServletRequest request) {
070: super .populate(request);
071:
072: if (StringUtils.isEmpty(this .getMethodToCall())) {
073: // call utility method to parse the methodToCall from the request.
074: setMethodToCall(WebUtils.parseMethodToCall(request));
075: }
076: populateFieldLevelHelpEnabled(request);
077:
078: if (actionFormUtilMap instanceof ActionFormUtilMap) {
079: ((ActionFormUtilMap) actionFormUtilMap)
080: .setCacheValueFinderResults(true);
081: }
082: }
083:
084: /**
085: * Populates whether the each field will have field-level help associated with it. Depending on how the jsp/tags are implemented, the value
086: * populated by this method may be overruled by other settings
087: *
088: * @param request
089: */
090: protected void populateFieldLevelHelpEnabled(
091: HttpServletRequest request) {
092: setFieldLevelHelpEnabled(KNSServiceLocator
093: .getKualiConfigurationService()
094: .getIndicatorParameter(
095: RiceConstants.KNS_NAMESPACE,
096: RiceConstants.DetailTypes.ALL_DETAIL_TYPE,
097: RiceConstants.SystemGroupParameterNames.ENABLE_FIELD_LEVEL_HELP_IND));
098: }
099:
100: public Map getDisplayedErrors() {
101: return displayedErrors;
102: }
103:
104: /**
105: * Used by the dispatch action to determine which action method to call into.
106: *
107: * @return Returns the methodToCall.
108: */
109: public String getMethodToCall() {
110: return methodToCall;
111: }
112:
113: /**
114: * @param methodToCall The methodToCall to set.
115: */
116: public void setMethodToCall(String methodToCall) {
117: this .methodToCall = methodToCall;
118: }
119:
120: /**
121: * Can be used by actions refresh method to determine what called the the refresh method.
122: *
123: * @return Returns the refreshCaller.
124: */
125: public String getRefreshCaller() {
126: return refreshCaller;
127: }
128:
129: /**
130: * @param refreshCaller The refreshCaller to set.
131: */
132: public void setRefreshCaller(String refreshCaller) {
133: this .refreshCaller = refreshCaller;
134: }
135:
136: /**
137: * @return the tab state list
138: */
139: public Map<String, String> getTabStates() {
140: return tabStates;
141: }
142:
143: /**
144: * simple setter for the tab state Map
145: *
146: * @param tabStates
147: */
148: public void setTabStates(Map<String, String> tabStates) {
149: this .tabStates = tabStates;
150: }
151:
152: /**
153: * Special getter based on key to work with multi rows for tab state objects
154: */
155: public String getTabState(String key) {
156: String state = RiceConstants.EMPTY_STRING;
157: if (tabStates.containsKey(key)) {
158: if (tabStates.get(key) instanceof String) {
159: state = tabStates.get(key);
160: } else {
161: //This is the case where the value is an Array of String,
162: //so we'll have to get the first element
163: Object result = tabStates.get(key);
164: result.getClass();
165: state = ((String[]) result)[0];
166: }
167: }
168:
169: return state;
170: }
171:
172: public int getCurrentTabIndex() {
173: return currentTabIndex;
174: }
175:
176: public void setCurrentTabIndex(int currentTabIndex) {
177: this .currentTabIndex = currentTabIndex;
178: }
179:
180: public void incrementTabIndex() {
181: this .currentTabIndex++;
182: }
183:
184: public int getNextArbitrarilyHighIndex() {
185: return this .arbitrarilyHighIndex++;
186: }
187:
188: /**
189: * @return Returns the validOptionsMap.
190: */
191: public Map getActionFormUtilMap() {
192: return actionFormUtilMap;
193: }
194:
195: /**
196: * @param validOptionsMap The validOptionsMap to set.
197: */
198: public void setActionFormUtilMap(Map validOptionsMap) {
199: this .actionFormUtilMap = validOptionsMap;
200: }
201:
202: /**
203: * Gets the headerNavigationTabs attribute.
204: *
205: * @return Returns the headerNavigationTabs.
206: */
207: public HeaderNavigation[] getHeaderNavigationTabs() {
208: return headerNavigationTabs;
209: }
210:
211: /**
212: * Sets the headerNavigationTabs attribute value.
213: *
214: * @param headerNavigationTabs The headerNavigationTabs to set.
215: */
216: public void setHeaderNavigationTabs(
217: HeaderNavigation[] headerNavigationTabs) {
218: this .headerNavigationTabs = headerNavigationTabs;
219: }
220:
221: /**
222: * Gets the navigationCss attribute.
223: *
224: * @return Returns the navigationCss.
225: */
226: public String getNavigationCss() {
227: return navigationCss;
228: }
229:
230: /**
231: * Sets the navigationCss attribute value.
232: *
233: * @param navigationCss The navigationCss to set.
234: */
235: public void setNavigationCss(String navigationCss) {
236: this .navigationCss = navigationCss;
237: }
238:
239: /**
240: * Gets the additionalDocInfo1 attribute.
241: *
242: * @return Returns the additionalDocInfo1.
243: */
244: public KeyLabelPair getAdditionalDocInfo1() {
245: return additionalDocInfo1;
246: }
247:
248: /**
249: * Sets the additionalDocInfo1 attribute value.
250: *
251: * @param additionalDocInfo1 The additionalDocInfo1 to set.
252: */
253: public void setAdditionalDocInfo1(KeyLabelPair additionalDocInfo1) {
254: this .additionalDocInfo1 = additionalDocInfo1;
255: }
256:
257: /**
258: * Gets the additionalDocInfo2 attribute.
259: *
260: * @return Returns the additionalDocInfo2.
261: */
262: public KeyLabelPair getAdditionalDocInfo2() {
263: return additionalDocInfo2;
264: }
265:
266: /**
267: * Sets the additionalDocInfo2 attribute value.
268: *
269: * @param additionalDocInfo2 The additionalDocInfo2 to set.
270: */
271: public void setAdditionalDocInfo2(KeyLabelPair additionalDocInfo2) {
272: this .additionalDocInfo2 = additionalDocInfo2;
273: }
274:
275: public String getAnchor() {
276: return anchor;
277: }
278:
279: public void setAnchor(String anchor) {
280: this .anchor = anchor;
281: }
282:
283: public List<ExtraButton> getExtraButtons() {
284: return extraButtons;
285: }
286:
287: public void setExtraButtons(List<ExtraButton> extraButtons) {
288: if (extraButtons instanceof TypedArrayList) {
289: this .extraButtons = extraButtons;
290: } else {
291: this .extraButtons.clear();
292: this .extraButtons.addAll(extraButtons);
293: }
294: }
295:
296: public ExtraButton getExtraButton(int index) {
297: return extraButtons.get(index);
298: }
299:
300: public void setExtraButton(int index, ExtraButton extraButton) {
301: extraButtons.set(index, extraButton);
302: }
303:
304: /**
305: * Returns whether field level help is enabled for this form.
306: *
307: * @return
308: */
309: public boolean isFieldLevelHelpEnabled() {
310: return this .fieldLevelHelpEnabled;
311: }
312:
313: public void setFieldLevelHelpEnabled(boolean fieldLevelHelpEnabled) {
314: this.fieldLevelHelpEnabled = fieldLevelHelpEnabled;
315: }
316: }
|