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.core.krms;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.uif.UifConstants;
20  import org.kuali.rice.krad.uif.component.Component;
21  import org.kuali.rice.krad.uif.component.DataBinding;
22  import org.kuali.rice.krad.uif.container.CollectionGroup;
23  import org.kuali.rice.krad.uif.container.Group;
24  import org.kuali.rice.krad.uif.container.collections.LineBuilderContext;
25  import org.kuali.rice.krad.uif.element.Action;
26  import org.kuali.rice.krad.uif.element.Message;
27  import org.kuali.rice.krad.uif.field.Field;
28  import org.kuali.rice.krad.uif.field.FieldGroup;
29  import org.kuali.rice.krad.uif.layout.StackedLayoutManager;
30  import org.kuali.rice.krad.uif.layout.StackedLayoutManagerBase;
31  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleUtils;
32  import org.kuali.rice.krad.uif.util.ComponentUtils;
33  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
34  import org.kuali.rice.krad.uif.view.ViewModel;
35  import org.kuali.rice.krad.util.KRADUtils;
36  import org.kuali.rice.krad.web.form.UifFormBase;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  import java.util.Map;
41  
42  /**
43   * @author Kuali Student Team
44   */
45  public class TreeNodeStackedLayoutManager extends StackedLayoutManagerBase {
46  
47      @Override
48      public void buildLine(LineBuilderContext lineBuilderContext) {
49          super.buildLine(lineBuilderContext);
50  
51          if (lineBuilderContext.isAddLine()) {
52              String nodePath = this.getNodePath(lineBuilderContext.getCollectionGroup().getContext());
53              if (nodePath != null) {
54                  for (Group group : this.getStackedGroups()) {
55                      //Set the nodepath on the add line group so that progressive rendering can use the #np
56                      ComponentUtils.pushObjectToContext(group, UifConstants.ContextVariableNames.NODE_PATH, nodePath);
57                  }
58              }
59          }
60  
61      }
62  
63      private String getNodePath(Map<String, Object> context) {
64          if (context.containsKey(UifConstants.ContextVariableNames.NODE_PATH)) {
65              return (String) context.get(UifConstants.ContextVariableNames.NODE_PATH);
66  
67          } else if (context.containsKey(UifConstants.ContextVariableNames.PARENT)) {
68              Component parent = (Component) context.get(UifConstants.ContextVariableNames.PARENT);
69              return this.getNodePath(parent.getContext());
70          }
71          return null;
72      }
73  
74  }