View Javadoc
1   /**
2    * Copyright 2005-2016 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.container;
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.datadictionary.parse.BeanTags;
22  import org.kuali.rice.krad.uif.component.Component;
23  import org.kuali.rice.krad.uif.element.Action;
24  import org.kuali.rice.krad.uif.element.ToggleMenu;
25  import org.kuali.rice.krad.uif.util.LifecycleElement;
26  
27  /**
28   * A navigation group which renders a menu with items, that is shown at the side of the page with collapse.
29   * functionality
30   *
31   * <p>Items of this menu should only be of {@link org.kuali.rice.krad.uif.element.Header}, {@link Action}, and
32   * {@link ToggleMenu} types.  Actions and ToggleMenus must have icons to render correctly when using the collapse
33   * functionality, but will inherit the defaultItemIconClass if their iconClass properties are not set.</p>
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  @BeanTags({@BeanTag(name = "sidebarNavigation", parent = "Uif-SidebarNavigationGroup"),
38          @BeanTag(name = "menuNavigation", parent = "Uif-MenuNavigationGroup")})
39  public class SidebarNavigationGroup extends GroupBase {
40      private static final long serialVersionUID = -8388015161780120970L;
41  
42      private boolean renderCollapse;
43      private String openedToggleIconClass;
44      private String closedToggleIconClass;
45      private String defaultItemIconClass;
46  
47      private static final String ARROW_CSS = "arrow";
48  
49      /**
50       * Adds icons and classes to {@link Action} and {@link ToggleMenu} items which exist in its items
51       * for rendering purposes.
52       *
53       * {@inheritDoc}
54       */
55      @Override
56      public void performFinalize(Object model, LifecycleElement parent) {
57          super.performFinalize(model, parent);
58  
59          for (Component item : this.getItems()) {
60              if (item instanceof ToggleMenu) {
61                  ((ToggleMenu) item).setRenderedInList(true);
62                  ((ToggleMenu) item).setToggleCaretClass(ARROW_CSS + " " + closedToggleIconClass);
63  
64                  if (StringUtils.isBlank(((ToggleMenu) item).getIconClass())) {
65                      ((ToggleMenu) item).setIconClass(defaultItemIconClass);
66                  }
67              } else if (item instanceof Action) {
68                  ((Action) item).setRenderInnerTextSpan(true);
69  
70                  if (StringUtils.isBlank(((Action) item).getIconClass())) {
71                      ((Action) item).setIconClass(defaultItemIconClass);
72                  }
73              }
74          }
75      }
76  
77      /**
78       * When true, render the collapse icon (an icon that the user can click to close/open the sidebar navigation).
79       *
80       * @return true if the collapse icon should be rendered, false otherwise
81       */
82      @BeanTagAttribute
83      public boolean isRenderCollapse() {
84          return renderCollapse;
85      }
86  
87      /**
88       * @see org.kuali.rice.krad.uif.container.SidebarNavigationGroup#isRenderCollapse()
89       */
90      public void setRenderCollapse(boolean renderCollapse) {
91          this.renderCollapse = renderCollapse;
92      }
93  
94      /**
95       * Icon class to use to render a opened icon for sub menus (the {@link ToggleMenu} items) that exist
96       * in this navigation menu.
97       *
98       * @return the opened ToggleMenu icon
99       */
100     @BeanTagAttribute
101     public String getOpenedToggleIconClass() {
102         return openedToggleIconClass;
103     }
104 
105     /**
106      * @see org.kuali.rice.krad.uif.container.SidebarNavigationGroup#getOpenedToggleIconClass()
107      */
108     public void setOpenedToggleIconClass(String openedToggleIconClass) {
109         this.openedToggleIconClass = openedToggleIconClass;
110     }
111 
112     /**
113      * Icon class to use to render a closed icon for sub menus (the {@link ToggleMenu} items) that exist
114      * in this navigation menu.
115      *
116      * @return the closed ToggleMenu icon
117      */
118     @BeanTagAttribute
119     public String getClosedToggleIconClass() {
120         return closedToggleIconClass;
121     }
122 
123     /**
124      * @see org.kuali.rice.krad.uif.container.SidebarNavigationGroup#getClosedToggleIconClass()
125      */
126     public void setClosedToggleIconClass(String closedToggleIconClass) {
127         this.closedToggleIconClass = closedToggleIconClass;
128     }
129 
130     /**
131      * The default css class to use for the icons of the items which exist in this navigation menu if they are not set
132      * on the items themselves (icons are required by {@link Action} and {@link ToggleMenu} items in this menu).
133      *
134      * @return the default icon class
135      */
136     @BeanTagAttribute
137     public String getDefaultItemIconClass() {
138         return defaultItemIconClass;
139     }
140 
141     /**
142      * @see org.kuali.rice.krad.uif.container.SidebarNavigationGroup#getDefaultItemIconClass()
143      */
144     public void setDefaultItemIconClass(String defaultItemIconClass) {
145         this.defaultItemIconClass = defaultItemIconClass;
146     }
147 }