View Javadoc
1   /**
2    * Copyright 2005-2015 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.rice.krad.labs.inquiry;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.rice.krad.inquiry.InquirableImpl;
22  import org.kuali.rice.krad.uif.component.Component;
23  import org.kuali.rice.krad.uif.container.Group;
24  import org.kuali.rice.krad.uif.container.PageGroup;
25  import org.kuali.rice.krad.uif.field.DataField;
26  import org.kuali.rice.krad.uif.util.ComponentFactory;
27  import org.kuali.rice.krad.uif.util.LifecycleElement;
28  import org.kuali.rice.krad.uif.view.InquiryView;
29  
30  /**
31   * Demonstrates the ability to add new sections and modify old ones.
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class LabsInquiryDynamicSectionsInquirable extends InquirableImpl {
36  
37      @Override
38      public void performCustomInitialization(LifecycleElement component) {
39          super.performCustomInitialization(component);
40  
41          if (component instanceof InquiryView) {
42              InquiryView inquiryView = (InquiryView) component;
43              PageGroup pageGroup = inquiryView.getCurrentPage();
44  
45              Group oldSection = (Group) pageGroup.getItems().get(0);
46              oldSection.setHeaderText(oldSection.getHeaderText() + " - Customized");
47  
48              Group newSection = ComponentFactory.getGroupWithDisclosureGridLayout();
49              newSection.setHeaderText("Dynamically Added Section");
50              DataField newDataField = ComponentFactory.getDataField("newDataField", "Dynamically Added Field");
51              newDataField.setForcedValue("This is a dynamically set value.");
52  
53              List<Component> fields = new ArrayList<Component>();
54              fields.add(newDataField);
55              newSection.setItems(fields);
56  
57              List<Component> sections = new ArrayList<Component>();
58              sections.addAll(pageGroup.getItems());
59              sections.add(newSection);
60              pageGroup.setItems(sections);
61          }
62  
63      }
64  }