Coverage Report - org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData
 
Classes in this File Line Coverage Branch Coverage Complexity
KSMenuItemData
0%
0/52
0%
0/4
1.1
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.common.ui.client.widgets.menus;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collections;
 20  
 import java.util.List;
 21  
 
 22  
 import com.google.gwt.event.dom.client.ClickHandler;
 23  
 import com.google.gwt.event.shared.HandlerManager;
 24  
 import com.google.gwt.event.shared.HandlerRegistration;
 25  
 import com.google.gwt.event.shared.GwtEvent.Type;
 26  
 import com.google.gwt.user.client.ui.Image;
 27  
 
 28  
 /**
 29  
  * The data object used to populate interactive ui menus.
 30  
  * 
 31  
  * @author Kuali Student Team
 32  
  *
 33  
  */
 34  
 public class KSMenuItemData {
 35  
         private String label;
 36  
         private String styleName;
 37  
         private ClickHandler clickHandler;
 38  0
         private List<KSMenuItemData> subItems = new ArrayList<KSMenuItemData>();
 39  0
         private KSMenuItemData parent = null;
 40  0
         private boolean selected = false;
 41  0
         private Image shownIcon = null;
 42  
         
 43  0
         private HandlerManager manager = new HandlerManager(this);
 44  
 
 45  
         public KSMenuItemData(String label) {
 46  0
                 super();
 47  0
                 this.label = label;
 48  0
         }
 49  
                 
 50  
         public KSMenuItemData(String label, ClickHandler clickHandler) {
 51  0
                 super();
 52  0
                 this.label = label;
 53  0
                 this.clickHandler = clickHandler;
 54  0
         }
 55  
         
 56  
         public KSMenuItemData(String label, Image icon, ClickHandler clickHandler) {
 57  0
                 super();
 58  0
                 this.label = label;
 59  0
                 this.shownIcon = icon;
 60  0
                 this.clickHandler = clickHandler;
 61  0
         }
 62  
 
 63  
         /**
 64  
          * Get the text used for this menu item
 65  
          * 
 66  
          * @return the "label" for this menu item
 67  
          */
 68  
         public String getLabel() {
 69  0
                 return label;
 70  
         }
 71  
         /**
 72  
          * Set the label to be used in the menu for this menu item
 73  
          * 
 74  
          * @param label the "label" of this menu item
 75  
          */
 76  
         public void setLabel(String label) {
 77  0
                 this.label = label;
 78  0
                 manager.fireEvent(new MenuChangeEvent());
 79  0
         }
 80  
         /**
 81  
          * Get the ClickHandler for this menu item.
 82  
          * 
 83  
          * @return ClickHandler which controls what this menu item does when selected
 84  
          */
 85  
         public ClickHandler getClickHandler() {
 86  0
                 return clickHandler;
 87  
         }
 88  
         /**
 89  
          * Set the click handler for this menu item (what the menu item does when selected).
 90  
          * 
 91  
          * @param clickHandler a ClickHandler for this menu item.
 92  
          */
 93  
         public void setClickHandler(ClickHandler clickHandler) {
 94  0
                 this.clickHandler = clickHandler;
 95  0
         }
 96  
         
 97  
         /**
 98  
          * Adds a KSMenuItemData to the list of children for this menu "category".
 99  
          * 
 100  
          * @param item a KSMenuItemData that is a child of this KSMenuItemData
 101  
          */
 102  
         public void addSubItem(KSMenuItemData item) {
 103  0
                 subItems.add(item);
 104  0
                 item.setParent(this);
 105  0
         }
 106  
         
 107  
         /**
 108  
          * Gets the list of sub items (children) in this KSMenuItemData
 109  
          * 
 110  
          * @return the list of sub items in this KSMenuItemData
 111  
          */
 112  
         public List<KSMenuItemData> getSubItems() {
 113  0
                 return Collections.unmodifiableList(subItems);
 114  
         }
 115  
 
 116  
     /**
 117  
      * Set the parent of this KSMenuItemData
 118  
      * 
 119  
      * @param parent the KSMenuItemData which is the parent KSMenuItemData (category)
 120  
      */
 121  
     public void setParent(KSMenuItemData parent) {
 122  0
         this.parent = parent;
 123  0
     }
 124  
 
 125  
     /**
 126  
      * Gets the parent of this KSMenuItemData
 127  
      * 
 128  
      * @return the paren of this KSMenuItemData
 129  
      */
 130  
     public KSMenuItemData getParent() {
 131  0
         return parent;
 132  
     }
 133  
 
 134  
     public boolean isSelected() {
 135  0
         return selected;
 136  
     }
 137  
 
 138  
     public void setSelected(boolean selected) {
 139  0
         this.selected = selected;
 140  0
         if(selected == true){
 141  0
             manager.fireEvent(new MenuSelectEvent());
 142  
         }
 143  0
     }
 144  
     
 145  
     public void setSelected(boolean selected, boolean fireClick) {
 146  0
         this.selected = selected;
 147  0
         if(selected == true){
 148  0
                 MenuSelectEvent e = new MenuSelectEvent();
 149  0
                 e.setFireClickEvent(fireClick);
 150  0
             manager.fireEvent(e);
 151  
         }
 152  0
     }
 153  
     
 154  
     public void unhandledSetSelected(boolean selected){
 155  0
         this.selected = selected;
 156  0
     }
 157  
 
 158  
     public Image getShownIcon() {
 159  0
         return shownIcon;
 160  
     }
 161  
 
 162  
     public void setShownIcon(Image shownIcon) {
 163  0
         this.shownIcon = shownIcon;
 164  0
         manager.fireEvent(new MenuChangeEvent());
 165  0
     }
 166  
     
 167  
     @SuppressWarnings("unchecked")
 168  
     public HandlerRegistration addMenuEventHandler(Type type, MenuEventHandler meh){
 169  0
         return manager.addHandler(type, meh);
 170  
     }
 171  
     
 172  
     public void addSpecialStyle(String style){
 173  0
             styleName = style;
 174  0
     }
 175  
     
 176  
     public String getSpecialStyle(){
 177  0
             return styleName;
 178  
     }
 179  
     
 180  
 }