001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.sys.businessobject.options; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 021 import org.kuali.kfs.sys.context.SpringContext; 022 import org.kuali.rice.kns.lookup.keyvalues.KeyValuesBase; 023 import org.kuali.rice.kns.service.ParameterService; 024 import org.kuali.rice.core.util.KeyLabelPair; 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, String parameterName) { 039 this.componentClass = componentClass; 040 this.parameterName = parameterName; 041 } 042 043 public List getKeyValues() { 044 List keyLabels = new ArrayList(); 045 List<String> parameterValues = SpringContext.getBean(ParameterService.class).getParameterValues(this.componentClass, this.parameterName); 046 if (insertBlankRow) { 047 keyLabels.add(new KeyLabelPair("", "")); 048 } 049 if (parameterValues != null) { 050 for (String parameterValue : parameterValues) { 051 keyLabels.add(new KeyLabelPair(parameterValue, parameterValue)); 052 } 053 } 054 return keyLabels; 055 } 056 057 /** 058 * Gets the insertBlankRow attribute. 059 * 060 * @return Returns the insertBlankRow. 061 */ 062 public boolean shouldInsertBlankRow() { 063 return insertBlankRow; 064 } 065 066 /** 067 * Sets the insertBlankRow attribute value. 068 * 069 * @param insertBlankRow The insertBlankRow to set. 070 */ 071 public void setInsertBlankRow(boolean insertBlankRow) { 072 this.insertBlankRow = insertBlankRow; 073 } 074 075 /** 076 * Gets the componentClass attribute. 077 * 078 * @return Returns the componentClass. 079 */ 080 public Class getComponentClass() { 081 return componentClass; 082 } 083 084 /** 085 * Gets the parameterName attribute. 086 * 087 * @return Returns the parameterName. 088 */ 089 public String getParameterName() { 090 return parameterName; 091 } 092 093 /** 094 * Sets the componentClass attribute value. 095 * 096 * @param componentClass The componentClass to set. 097 */ 098 public void setComponentClass(Class componentClass) { 099 this.componentClass = componentClass; 100 } 101 102 /** 103 * Sets the parameterName attribute value. 104 * 105 * @param parameterName The parameterName to set. 106 */ 107 public void setParameterName(String parameterName) { 108 this.parameterName = parameterName; 109 } 110 111 112 }