1
2
3
4
5
6
7
8
9
10
11
12
13
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
30
31
32
33
34 public class KSMenuItemData {
35 private String label;
36 private String styleName;
37 private ClickHandler clickHandler;
38 private List<KSMenuItemData> subItems = new ArrayList<KSMenuItemData>();
39 private KSMenuItemData parent = null;
40 private boolean selected = false;
41 private Image shownIcon = null;
42
43 private HandlerManager manager = new HandlerManager(this);
44
45 public KSMenuItemData(String label) {
46 super();
47 this.label = label;
48 }
49
50 public KSMenuItemData(String label, ClickHandler clickHandler) {
51 super();
52 this.label = label;
53 this.clickHandler = clickHandler;
54 }
55
56 public KSMenuItemData(String label, Image icon, ClickHandler clickHandler) {
57 super();
58 this.label = label;
59 this.shownIcon = icon;
60 this.clickHandler = clickHandler;
61 }
62
63
64
65
66
67
68 public String getLabel() {
69 return label;
70 }
71
72
73
74
75
76 public void setLabel(String label) {
77 this.label = label;
78 manager.fireEvent(new MenuChangeEvent());
79 }
80
81
82
83
84
85 public ClickHandler getClickHandler() {
86 return clickHandler;
87 }
88
89
90
91
92
93 public void setClickHandler(ClickHandler clickHandler) {
94 this.clickHandler = clickHandler;
95 }
96
97
98
99
100
101
102 public void addSubItem(KSMenuItemData item) {
103 subItems.add(item);
104 item.setParent(this);
105 }
106
107
108
109
110
111
112 public List<KSMenuItemData> getSubItems() {
113 return Collections.unmodifiableList(subItems);
114 }
115
116
117
118
119
120
121 public void setParent(KSMenuItemData parent) {
122 this.parent = parent;
123 }
124
125
126
127
128
129
130 public KSMenuItemData getParent() {
131 return parent;
132 }
133
134 public boolean isSelected() {
135 return selected;
136 }
137
138 public void setSelected(boolean selected) {
139 this.selected = selected;
140 if(selected == true){
141 manager.fireEvent(new MenuSelectEvent());
142 }
143 }
144
145 public void setSelected(boolean selected, boolean fireClick) {
146 this.selected = selected;
147 if(selected == true){
148 MenuSelectEvent e = new MenuSelectEvent();
149 e.setFireClickEvent(fireClick);
150 manager.fireEvent(e);
151 }
152 }
153
154 public void unhandledSetSelected(boolean selected){
155 this.selected = selected;
156 }
157
158 public Image getShownIcon() {
159 return shownIcon;
160 }
161
162 public void setShownIcon(Image shownIcon) {
163 this.shownIcon = shownIcon;
164 manager.fireEvent(new MenuChangeEvent());
165 }
166
167 @SuppressWarnings("unchecked")
168 public HandlerRegistration addMenuEventHandler(Type type, MenuEventHandler meh){
169 return manager.addHandler(type, meh);
170 }
171
172 public void addSpecialStyle(String style){
173 styleName = style;
174 }
175
176 public String getSpecialStyle(){
177 return styleName;
178 }
179
180 }