001/** 002 * Copyright 2005-2017 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 */ 016package org.kuali.rice.krad.labs.inquiry; 017 018import java.util.ArrayList; 019import java.util.List; 020 021import org.kuali.rice.krad.inquiry.InquirableImpl; 022import org.kuali.rice.krad.uif.component.Component; 023import org.kuali.rice.krad.uif.container.Group; 024import org.kuali.rice.krad.uif.container.PageGroup; 025import org.kuali.rice.krad.uif.field.DataField; 026import org.kuali.rice.krad.uif.util.ComponentFactory; 027import org.kuali.rice.krad.uif.util.LifecycleElement; 028import org.kuali.rice.krad.uif.view.InquiryView; 029 030/** 031 * Demonstrates the ability to add new sections and modify old ones. 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 */ 035public class LabsInquiryDynamicSectionsInquirable extends InquirableImpl { 036 037 @Override 038 public void performCustomInitialization(LifecycleElement component) { 039 super.performCustomInitialization(component); 040 041 if (component instanceof InquiryView) { 042 InquiryView inquiryView = (InquiryView) component; 043 PageGroup pageGroup = inquiryView.getCurrentPage(); 044 045 Group oldSection = (Group) pageGroup.getItems().get(0); 046 oldSection.setHeaderText(oldSection.getHeaderText() + " - Customized"); 047 048 Group newSection = ComponentFactory.getGroupWithDisclosureGridLayout(); 049 newSection.setHeaderText("Dynamically Added Section"); 050 DataField newDataField = ComponentFactory.getDataField("newDataField", "Dynamically Added Field"); 051 newDataField.setForcedValue("This is a dynamically set value."); 052 053 List<Component> fields = new ArrayList<Component>(); 054 fields.add(newDataField); 055 newSection.setItems(fields); 056 057 List<Component> sections = new ArrayList<Component>(); 058 sections.addAll(pageGroup.getItems()); 059 sections.add(newSection); 060 pageGroup.setItems(sections); 061 } 062 063 } 064}