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.uif.layout.collections;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  import org.kuali.rice.krad.uif.UifConstants;
21  import org.kuali.rice.krad.uif.container.Group;
22  import org.kuali.rice.krad.uif.field.Field;
23  import org.kuali.rice.krad.uif.field.FieldGroup;
24  import org.kuali.rice.krad.uif.layout.CollectionLayoutManager;
25  import org.kuali.rice.krad.uif.layout.LayoutManagerBase;
26  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
27  import org.kuali.rice.krad.uif.view.ExpressionEvaluator;
28  import org.kuali.rice.krad.uif.element.Pager;
29  import org.kuali.rice.krad.util.KRADUtils;
30  
31  import java.util.Map;
32  
33  /**
34   * Base class for collection layout managers.
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public abstract class CollectionLayoutManagerBase extends LayoutManagerBase implements CollectionLayoutManager {
39      private static final long serialVersionUID = 5530678364562263669L;
40  
41      private Group addLineGroup;
42      private Field selectFieldPrototype;
43      private FieldGroup subCollectionFieldGroupPrototype;
44  
45      private Pager pagerWidget;
46  
47      /**
48       * {@inheritDoc}
49       */
50      @Override
51      @BeanTagAttribute
52      public Group getAddLineGroup() {
53          return addLineGroup;
54      }
55  
56      /**
57       * {@inheritDoc}
58       */
59      @Override
60      public void setAddLineGroup(Group addLineGroup) {
61          this.addLineGroup = addLineGroup;
62      }
63  
64      /**
65       * Method to add and enter key add to the given Group. Will use given lineContext and expressionEvaluator if action
66       * string starts with '@{'.
67       *
68       * @param group
69       * @param lineContext
70       * @param expressionEvaluator
71       * @param enterKeyAction
72       */
73      protected void addEnterKeyDataAttributeToGroup(Group group, Map<String, Object> lineContext,
74              ExpressionEvaluator expressionEvaluator, String enterKeyAction) {
75          if (StringUtils.isNotBlank(enterKeyAction)) {
76              String action = enterKeyAction;
77              if (action.contains("@{")) {
78                  action = expressionEvaluator.evaluateExpressionTemplate(lineContext, enterKeyAction);
79              }
80  
81              group.addDataAttribute(UifConstants.DataAttributes.ENTER_KEY, KRADUtils.convertToHTMLAttributeSafeString(
82                      action));
83          }
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      @Override
90      @ViewLifecycleRestriction(UifConstants.ViewPhases.INITIALIZE)
91      @BeanTagAttribute
92      public Field getSelectFieldPrototype() {
93          return selectFieldPrototype;
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     public void setSelectFieldPrototype(Field selectFieldPrototype) {
101         this.selectFieldPrototype = selectFieldPrototype;
102     }
103 
104     /**
105      * {@inheritDoc}
106      */
107     @Override
108     @ViewLifecycleRestriction(UifConstants.ViewPhases.INITIALIZE)
109     @BeanTagAttribute
110     public FieldGroup getSubCollectionFieldGroupPrototype() {
111         return this.subCollectionFieldGroupPrototype;
112     }
113 
114     /**
115      * {@inheritDoc}
116      */
117     @Override
118     public void setSubCollectionFieldGroupPrototype(FieldGroup subCollectionFieldGroupPrototype) {
119         this.subCollectionFieldGroupPrototype = subCollectionFieldGroupPrototype;
120     }
121 
122     /**
123      * {@inheritDoc}
124      */
125     @Override
126     @BeanTagAttribute
127     public Pager getPagerWidget() {
128         return pagerWidget;
129     }
130 
131     /**
132      * {@inheritDoc}
133      */
134     @Override
135     public void setPagerWidget(Pager pagerWidget) {
136         this.pagerWidget = pagerWidget;
137     }
138 }