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.rice.krad.uif.widget;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.uif.CssConstants;
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.layout.LayoutManager;
25  import org.kuali.rice.krad.uif.view.View;
26  
27  /**
28   * Decorates a group with scroll functionality
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  @BeanTag(name = "scrollpane-bean", parent = "Uif-Scrollpane")
33  public class Scrollpane  extends WidgetBase {
34      private static final long serialVersionUID = 3853028195825084261L;
35  
36      private String height;
37  
38      @Override
39      public void performFinalize(View view, Object model, Component parent) {
40          super.performFinalize(view, model, parent);
41  
42          buildCSSforScrollPane(parent);
43      }
44  
45      private void buildCSSforScrollPane(Component parent) {
46          LayoutManager layoutManager = ((Group) parent).getLayoutManager();
47          if (StringUtils.isNotBlank(getHeight())) {
48              if (!StringUtils.contains(layoutManager.getStyle(), CssConstants.HEIGHT)) {
49                  layoutManager.appendToStyle(CssConstants.HEIGHT + getHeight() +";");
50              }
51  
52              if (!StringUtils.contains(layoutManager.getStyle(), CssConstants.OVERFLOW)) {
53                  layoutManager.appendToStyle(CssConstants.OVERFLOW + "auto;");
54              }
55          }
56      }
57  
58      /**
59       * Height the content should take up in the group
60       *
61       * <p>
62       * If the content size exceeds the height then a scroll bar will be shown.
63       * </p>
64       * <p>
65       * e.g. '30%' or '55px'
66       * </p>
67       *
68       * @return Content height of the group
69       */
70      @BeanTagAttribute(name="height")
71      public String getHeight() {
72          return height;
73      }
74  
75      /**
76       * Setter for the group height
77       *
78       * @param height
79       */
80      public void setHeight(String height) {
81          this.height = height;
82      }
83  
84      /**
85       * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
86       */
87      @Override
88      protected <T> void copyProperties(T component) {
89          super.copyProperties(component);
90          Scrollpane scrollpaneCopy = (Scrollpane) component;
91          scrollpaneCopy.setHeight(this.getHeight());
92      }
93  
94  }