001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.uif.container; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.krad.datadictionary.parse.BeanTag; 020import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 021import org.kuali.rice.krad.datadictionary.parse.BeanTags; 022import org.kuali.rice.krad.uif.component.Component; 023import org.kuali.rice.krad.uif.element.Action; 024import org.kuali.rice.krad.uif.element.ToggleMenu; 025import org.kuali.rice.krad.uif.util.LifecycleElement; 026 027/** 028 * A navigation group which renders a menu with items, that is shown at the side of the page with collapse. 029 * functionality 030 * 031 * <p>Items of this menu should only be of {@link org.kuali.rice.krad.uif.element.Header}, {@link Action}, and 032 * {@link ToggleMenu} types. Actions and ToggleMenus must have icons to render correctly when using the collapse 033 * functionality, but will inherit the defaultItemIconClass if their iconClass properties are not set.</p> 034 * 035 * @author Kuali Rice Team (rice.collab@kuali.org) 036 */ 037@BeanTags({@BeanTag(name = "sidebarNavigation", parent = "Uif-SidebarNavigationGroup"), 038 @BeanTag(name = "menuNavigation", parent = "Uif-MenuNavigationGroup")}) 039public class SidebarNavigationGroup extends GroupBase { 040 private static final long serialVersionUID = -8388015161780120970L; 041 042 private boolean renderCollapse; 043 private String openedToggleIconClass; 044 private String closedToggleIconClass; 045 private String defaultItemIconClass; 046 047 private static final String ARROW_CSS = "arrow"; 048 049 /** 050 * Adds icons and classes to {@link Action} and {@link ToggleMenu} items which exist in its items 051 * for rendering purposes. 052 * 053 * {@inheritDoc} 054 */ 055 @Override 056 public void performFinalize(Object model, LifecycleElement parent) { 057 super.performFinalize(model, parent); 058 059 for (Component item : this.getItems()) { 060 if (item instanceof ToggleMenu) { 061 ((ToggleMenu) item).setRenderedInList(true); 062 ((ToggleMenu) item).setToggleCaretClass(ARROW_CSS + " " + closedToggleIconClass); 063 064 if (StringUtils.isBlank(((ToggleMenu) item).getIconClass())) { 065 ((ToggleMenu) item).setIconClass(defaultItemIconClass); 066 } 067 } else if (item instanceof Action) { 068 ((Action) item).setRenderInnerTextSpan(true); 069 070 if (StringUtils.isBlank(((Action) item).getIconClass())) { 071 ((Action) item).setIconClass(defaultItemIconClass); 072 } 073 } 074 } 075 } 076 077 /** 078 * When true, render the collapse icon (an icon that the user can click to close/open the sidebar navigation). 079 * 080 * @return true if the collapse icon should be rendered, false otherwise 081 */ 082 @BeanTagAttribute 083 public boolean isRenderCollapse() { 084 return renderCollapse; 085 } 086 087 /** 088 * @see org.kuali.rice.krad.uif.container.SidebarNavigationGroup#isRenderCollapse() 089 */ 090 public void setRenderCollapse(boolean renderCollapse) { 091 this.renderCollapse = renderCollapse; 092 } 093 094 /** 095 * Icon class to use to render a opened icon for sub menus (the {@link ToggleMenu} items) that exist 096 * in this navigation menu. 097 * 098 * @return the opened ToggleMenu icon 099 */ 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}