View Javadoc
1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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.student.enrollment.class1.krms.util;
17  
18  import org.kuali.rice.krad.uif.UifParameters;
19  import org.kuali.rice.krad.uif.component.Component;
20  import org.kuali.rice.krad.uif.container.CollectionGroup;
21  import org.kuali.rice.krad.uif.container.Group;
22  import org.kuali.rice.krad.uif.element.Action;
23  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleUtils;
24  import org.kuali.rice.krad.uif.util.ComponentUtils;
25  import org.kuali.rice.krms.dto.AgendaEditor;
26  import org.kuali.rice.krms.util.AgendaBuilder;
27  import org.kuali.rice.krms.util.AgendaSection;
28  
29  import java.util.List;
30  
31  /**
32   * @author Kuali Student Team
33   */
34  public class FinalExamAgendaBuilder extends AgendaBuilder {
35  
36      /**
37       * This method dynamically build the components on the screen to render an agenda.
38       *
39       * @param agenda
40       * @return
41       */
42      public Component buildAgenda(AgendaEditor agenda, int index, AgendaSection agendaSection) {
43  
44          FinalExamAgendaSection feAgendaSection;
45          if (agendaSection instanceof FinalExamAgendaSection) {
46              feAgendaSection = (FinalExamAgendaSection) agendaSection;
47  
48              String agendaSuffix = "_agenda" + Integer.toString(index);
49              Group group = ComponentUtils.copy(feAgendaSection.getAgendaPrototypeMap().get(agenda.getAgendaTypeInfo().getType()), agendaSuffix);
50              group.setHeaderText(agenda.getAgendaTypeInfo().getDescription());
51  
52              String bindingPrefix = "agendas[" + index + "]";
53              List<CollectionGroup> components = ViewLifecycleUtils.getElementsOfTypeDeep(group, CollectionGroup.class);
54              for (CollectionGroup fieldCollectionGroup : components) {
55                  ComponentUtils.prefixBindingPath(fieldCollectionGroup, bindingPrefix);
56                  fieldCollectionGroup.setSubCollectionSuffix(agendaSuffix);
57              }
58  
59              List<Action> actionLinks = ViewLifecycleUtils.getElementsOfTypeDeep(group, Action.class);
60              for (Action actionLink : actionLinks) {
61                  actionLink.getActionParameters().put(UifParameters.SELECTED_LINE_INDEX, "" + index);
62              }
63  
64              return group;
65          }
66          throw new RuntimeException("Error retrieving Maintenance document form from UifFormBase");
67      }
68  
69  }