View Javadoc
1   /**
2    * Copyright 2012 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * Created by Daniel on 7/6/12
16   */
17  package org.kuali.student.enrollment.class2.courseoffering.keyvalue;
18  
19  import org.kuali.rice.core.api.util.ConcreteKeyValue;
20  import org.kuali.rice.core.api.util.KeyValue;
21  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
22  import org.kuali.rice.krad.uif.view.ViewModel;
23  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
24  import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
25  
26  import java.io.Serializable;
27  import java.util.ArrayList;
28  import java.util.Collections;
29  import java.util.List;
30  
31  /**
32   * This class makes key values based on allowed credit options from the course offering
33   *
34   * @author Kuali Student Team
35   */
36  public class MultipleCreditOptionsKeyValues extends UifKeyValuesFinderBase implements Serializable {
37  
38      private static final long serialVersionUID = 1L;
39  
40      @Override
41      public List<KeyValue> getKeyValues(ViewModel model) {
42          MaintenanceDocumentForm form1 = (MaintenanceDocumentForm)model;
43          CourseOfferingEditWrapper form = (CourseOfferingEditWrapper)form1.getDocument().getDocumentDataObject();
44  
45          List<KeyValue> keyValues = new ArrayList<KeyValue>();
46  
47          List<Float> creditOptionsF = new ArrayList();
48          for(String creditOption : form.getCreditOption().getAllowedCredits()){
49              creditOptionsF.add(Float.valueOf(creditOption));
50          }
51          Collections.sort(creditOptionsF);
52          for(Float creditOption : creditOptionsF){
53              keyValues.add(new ConcreteKeyValue(String.valueOf(creditOption), String.valueOf(creditOption)));
54          }
55  
56          return keyValues;
57      }
58  
59  }