View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sys.businessobject.options;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.kuali.kfs.sys.context.SpringContext;
25  import org.kuali.rice.core.api.util.ConcreteKeyValue;
26  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
27  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
28  
29  /**
30   * 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
31   * as both key and label
32   */
33  public class ParameterValuesFinder extends KeyValuesBase {
34      private Class componentClass;
35      private String parameterName;
36      private boolean insertBlankRow = true;
37  
38      public ParameterValuesFinder() {
39      }
40  
41      public ParameterValuesFinder(Class componentClass, String parameterName) {
42          this.componentClass = componentClass;
43          this.parameterName = parameterName;
44      }
45  
46      public List getKeyValues() {
47          List keyLabels = new ArrayList();
48          List<String> parameterValues = new ArrayList<String>( SpringContext.getBean(ParameterService.class).getParameterValuesAsString(this.componentClass, this.parameterName) );
49          if (insertBlankRow) {
50              keyLabels.add(new ConcreteKeyValue("", ""));
51          }
52          if (parameterValues != null) {
53              for (String parameterValue : parameterValues) {
54                  keyLabels.add(new ConcreteKeyValue(parameterValue, parameterValue));
55              }
56          }
57          return keyLabels;
58      }
59  
60      /**
61       * Gets the insertBlankRow attribute.
62       * 
63       * @return Returns the insertBlankRow.
64       */
65      public boolean shouldInsertBlankRow() {
66          return insertBlankRow;
67      }
68  
69      /**
70       * Sets the insertBlankRow attribute value.
71       * 
72       * @param insertBlankRow The insertBlankRow to set.
73       */
74      public void setInsertBlankRow(boolean insertBlankRow) {
75          this.insertBlankRow = insertBlankRow;
76      }
77  
78      /**
79       * Gets the componentClass attribute.
80       * 
81       * @return Returns the componentClass.
82       */
83      public Class getComponentClass() {
84          return componentClass;
85      }
86  
87      /**
88       * Gets the parameterName attribute.
89       * 
90       * @return Returns the parameterName.
91       */
92      public String getParameterName() {
93          return parameterName;
94      }
95  
96      /**
97       * Sets the componentClass attribute value.
98       * 
99       * @param componentClass The componentClass to set.
100      */
101     public void setComponentClass(Class componentClass) {
102         this.componentClass = componentClass;
103     }
104 
105     /**
106      * Sets the parameterName attribute value.
107      * 
108      * @param parameterName The parameterName to set.
109      */
110     public void setParameterName(String parameterName) {
111         this.parameterName = parameterName;
112     }
113 
114 
115 }