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