01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.util;
17:
18: import java.util.Map;
19:
20: /**
21: * Inquiry screens and maintenance documents may render a collection of BOs on a screen. These
22: * BOs may implement {@link org.kuali.core.bo.Inactivateable}, which means that the BO has an active
23: * flag of true or false. Some screens may give the user the ability to not render (i.e. hide) inactive
24: * collection elements. This class has several utilities to control that behavior.
25: *
26: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
27: */
28: public class InactiveRecordsHidingUtils {
29: /**
30: * Returns whether a collection has been set to show inactive records. Note that if a collection has not been set to show inactive inactive records, then
31: * this method will return false.
32: *
33: * @param inactiveRecordDisplay a Map used to keep state between invocations of this method and {@link #setShowInactiveRecords(Map, String, boolean)}
34: * @param collectionName the name of the collection
35: * @return
36: */
37: public static boolean getShowInactiveRecords(
38: Map<String, Boolean> inactiveRecordDisplay,
39: String collectionName) {
40: // by default, show the actives
41: boolean showInactive = true;
42:
43: if (collectionName == null) {
44: throw new IllegalArgumentException(
45: "collection name cannot be null");
46: }
47: // remove periods from the collection name due to parsing limitation in Apache beanutils
48: collectionName = collectionName.replace('.', '_');
49:
50: if (inactiveRecordDisplay.containsKey(collectionName)) {
51: Object inactiveSetting = inactiveRecordDisplay
52: .get(collectionName);
53:
54: // warren: i copied this code from somewhere else, and have no idea why they're testing to see whether it's a
55: // Boolean, but I'm guessing that it has to do w/ the PojoFormBase not setting things correctly
56: if (inactiveSetting instanceof Boolean) {
57: showInactive = ((Boolean) inactiveSetting)
58: .booleanValue();
59: } else {
60: showInactive = Boolean
61: .parseBoolean(((String[]) inactiveSetting)[0]);
62: }
63: }
64:
65: return showInactive;
66: }
67:
68: /**
69: * Sets whether a method should show inactive records
70: *
71: * @param inactiveRecordDisplay a Map used to keep state between invocations of this method and {@link #getShowInactiveRecords(Map, String)}
72: * @param collectionName the name of the collection
73: * @param showInactive whether to show inactive records
74: */
75: public static void setShowInactiveRecords(
76: Map<String, Boolean> inactiveRecordDisplay,
77: String collectionName, boolean showInactive) {
78: if (collectionName == null) {
79: throw new IllegalArgumentException(
80: "collection name cannot be null");
81: }
82:
83: // remove periods from the collection name due to parsing limitation in Apache beanutils
84: collectionName = collectionName.replace('.', '_');
85:
86: inactiveRecordDisplay.put(collectionName, new Boolean(
87: showInactive));
88: }
89:
90: public static String formatCollectionName(String collectionName) {
91: return collectionName.replace('.', '_');
92: }
93: }
|