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 | 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 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public String getLabel() { |
69 | 0 | return label; |
70 | |
} |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public void setLabel(String label) { |
77 | 0 | this.label = label; |
78 | 0 | manager.fireEvent(new MenuChangeEvent()); |
79 | 0 | } |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public ClickHandler getClickHandler() { |
86 | 0 | return clickHandler; |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public void setClickHandler(ClickHandler clickHandler) { |
94 | 0 | this.clickHandler = clickHandler; |
95 | 0 | } |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public void addSubItem(KSMenuItemData item) { |
103 | 0 | subItems.add(item); |
104 | 0 | item.setParent(this); |
105 | 0 | } |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public List<KSMenuItemData> getSubItems() { |
113 | 0 | return Collections.unmodifiableList(subItems); |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public void setParent(KSMenuItemData parent) { |
122 | 0 | this.parent = parent; |
123 | 0 | } |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
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 | |
} |