001: /*
002: * Copyright 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.kfs.lookup.keyvalues;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import org.kuali.core.lookup.keyvalues.KeyValuesBase;
022: import org.kuali.core.web.ui.KeyLabelPair;
023: import org.kuali.kfs.context.SpringContext;
024: import org.kuali.kfs.service.ParameterService;
025:
026: /**
027: * This class gets all the values of a parameter and then builds a list of key label pairs out of them, using each parameter value
028: * as both key and label
029: */
030: public class ParameterValuesFinder extends KeyValuesBase {
031: private Class componentClass;
032: private String parameterName;
033: private boolean insertBlankRow = true;
034:
035: public ParameterValuesFinder() {
036: }
037:
038: public ParameterValuesFinder(Class componentClass,
039: String parameterName) {
040: this .componentClass = componentClass;
041: this .parameterName = parameterName;
042: }
043:
044: public List getKeyValues() {
045: List keyLabels = new ArrayList();
046: List<String> parameterValues = SpringContext.getBean(
047: ParameterService.class).getParameterValues(
048: this .componentClass, this .parameterName);
049: if (insertBlankRow) {
050: keyLabels.add(new KeyLabelPair("", ""));
051: }
052: if (parameterValues != null) {
053: for (String parameterValue : parameterValues) {
054: keyLabels.add(new KeyLabelPair(parameterValue,
055: parameterValue));
056: }
057: }
058: return keyLabels;
059: }
060:
061: /**
062: * Gets the insertBlankRow attribute.
063: *
064: * @return Returns the insertBlankRow.
065: */
066: public boolean shouldInsertBlankRow() {
067: return insertBlankRow;
068: }
069:
070: /**
071: * Sets the insertBlankRow attribute value.
072: *
073: * @param insertBlankRow The insertBlankRow to set.
074: */
075: public void setInsertBlankRow(boolean insertBlankRow) {
076: this .insertBlankRow = insertBlankRow;
077: }
078:
079: /**
080: * Gets the componentClass attribute.
081: *
082: * @return Returns the componentClass.
083: */
084: public Class getComponentClass() {
085: return componentClass;
086: }
087:
088: /**
089: * Gets the parameterName attribute.
090: *
091: * @return Returns the parameterName.
092: */
093: public String getParameterName() {
094: return parameterName;
095: }
096:
097: /**
098: * Sets the componentClass attribute value.
099: *
100: * @param componentClass The componentClass to set.
101: */
102: public void setComponentClass(Class componentClass) {
103: this .componentClass = componentClass;
104: }
105:
106: /**
107: * Sets the parameterName attribute value.
108: *
109: * @param parameterName The parameterName to set.
110: */
111: public void setParameterName(String parameterName) {
112: this.parameterName = parameterName;
113: }
114:
115: }
|