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.element;
17  
18  import java.util.List;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
22  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
23  import org.kuali.rice.krad.datadictionary.parse.BeanTags;
24  import org.kuali.rice.krad.uif.component.Component;
25  import org.kuali.rice.krad.uif.component.ListAware;
26  import org.kuali.rice.krad.uif.container.Group;
27  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
28  import org.kuali.rice.krad.uif.util.LifecycleElement;
29  
30  /**
31   * Renders a toggle menu (aka sub menu, dropdown menu) of items.
32   *
33   * <p>The toggle menu component can be used to build context menus or full application menus. Essentially the
34   * component is configured by first setting the text that will appear as a link (optionally with a caret). When the
35   * user clicks the link, the items ({@link #getMenuItems()} will be presented.</p>
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  @BeanTags({@BeanTag(name = "dropdownMenu", parent = "Uif-DropdownToggleMenu"),
40          @BeanTag(name = "sidebarMenu", parent = "Uif-SidebarToggleMenu")})
41  public class ToggleMenu extends ContentElementBase implements ListAware {
42      private static final long serialVersionUID = -1759659012620124641L;
43  
44      private String toggleText;
45      private Message toggleMessage;
46  
47      private String toggleCaretClass;
48      private String iconClass;
49      private boolean renderToggleButton;
50      private boolean renderedInList;
51  
52      private List<Component> menuItems;
53      private Group menuGroup;
54  
55      public ToggleMenu() {
56          super();
57      }
58  
59      /**
60       * {@inheritDoc}
61       */
62      @Override
63      public void performInitialization(Object model) {
64          super.performInitialization(model);
65  
66          if ((this.menuItems != null) && !this.menuItems.isEmpty()) {
67              this.menuGroup.setItems(menuItems);
68          }
69      }
70  
71      /**
72       * {@inheritDoc}
73       */
74      @Override
75      public void performApplyModel(Object model, LifecycleElement parent) {
76          super.performApplyModel(model, parent);
77  
78          if (StringUtils.isNotBlank(toggleText) && StringUtils.isBlank(toggleMessage.getMessageText())) {
79              toggleMessage.setMessageText(toggleText);
80          }
81      }
82  
83      /**
84       * Text to display as the toggle menu toggle link
85       * 
86       * <p>
87       * This text will appear as a link for the user to click on, which then will bring up the toggle
88       * menu menu. This property is a shortcut for {@link #getToggleMessage()}
89       * {@link Message#setMessageText(String) .setMessageText}. This text is not required, in which
90       * case only the caret will render
91       * </p>
92       * 
93       * @return text to display for the toggle menu toggle link
94       */
95      @BeanTagAttribute
96      public String getToggleText() {
97          return toggleText;
98      }
99  
100     /**
101      * @see ToggleMenu#getToggleText()
102      */
103     public void setToggleText(String toggleText) {
104         this.toggleText = toggleText;
105     }
106 
107     /**
108      * {@code Message} component that is associated with the toggle menu toggle text, can be used to adjust styling
109      * and so forth
110      *
111      * @return Message instance for toggle text
112      */
113     @BeanTagAttribute
114     public Message getToggleMessage() {
115         return toggleMessage;
116     }
117 
118     /**
119      * @see ToggleMenu#getToggleMessage()
120      */
121     public void setToggleMessage(Message toggleMessage) {
122         this.toggleMessage = toggleMessage;
123     }
124 
125     /**
126      * Css class to use when rendering a caret icon which will appear to the right of the toggleText
127      *
128      * @return the caret icon class
129      */
130     @BeanTagAttribute
131     public String getToggleCaretClass() {
132         return toggleCaretClass;
133     }
134 
135     /**
136      * @see org.kuali.rice.krad.uif.element.ToggleMenu#getToggleCaretClass()
137      */
138     public void setToggleCaretClass(String toggleCaretClass) {
139         this.toggleCaretClass = toggleCaretClass;
140     }
141 
142     /**
143      * Css class for an icon that will appear to the left of the toggleText
144      *
145      * @return the css class for an icon
146      */
147     @BeanTagAttribute
148     public String getIconClass() {
149         return iconClass;
150     }
151 
152     /**
153      * @see org.kuali.rice.krad.uif.element.ToggleMenu#getIconClass()
154      */
155     public void setIconClass(String iconClass) {
156         this.iconClass = iconClass;
157     }
158 
159     /**
160      * Indicates whether a caret button should be rendered to the right of the toggle text (if present)
161      *
162      * @return boolean true if caret button should be rendered, false if not
163      */
164     @BeanTagAttribute
165     public boolean isRenderToggleButton() {
166         return renderToggleButton;
167     }
168 
169     /**
170      * @see ToggleMenu#isRenderToggleButton()
171      */
172     public void setRenderToggleButton(boolean renderToggleButton) {
173         this.renderToggleButton = renderToggleButton;
174     }
175 
176     /**
177      * @see org.kuali.rice.krad.uif.component.ListAware#setRenderedInList(boolean)
178      */
179     @BeanTagAttribute
180     public boolean isRenderedInList() {
181         return renderedInList;
182     }
183 
184     /**
185      * @see ToggleMenu#isRenderedInList()
186      */
187     public void setRenderedInList(boolean renderedInList) {
188         this.renderedInList = renderedInList;
189     }
190 
191     /**
192      * List of components that should be rendered for the toggle menu.
193      *
194      * <p>Items for the menu are configured through this list. The order of the items within the list is
195      * the order they will appear in the toggle menu</p>
196      *
197      * @return List of menu items for the toggle menu
198      */
199     @ViewLifecycleRestriction
200     @BeanTagAttribute
201     public List<Component> getMenuItems() {
202         return menuItems;
203     }
204 
205     /**
206      * @see ToggleMenu#getMenuItems()
207      */
208     public void setMenuItems(List<Component> menuItems) {
209         this.menuItems = menuItems;
210     }
211 
212     /**
213      * Group instance that is rendered when the toggle menu is toggled.
214      *
215      * <p>Note in most cases this group will be a simple list group. The component allows for the list group
216      * to be initialized in a base bean, then child beans can simply define the item using
217      * {@link ToggleMenu#getMenuItems()}</p>
218      *
219      * @return Group instance
220      */
221     @BeanTagAttribute
222     public Group getMenuGroup() {
223         return menuGroup;
224     }
225 
226     /**
227      * @see ToggleMenu#getMenuGroup()
228      */
229     public void setMenuGroup(Group menuGroup) {
230         this.menuGroup = menuGroup;
231     }
232 }