1 | |
package org.kuali.student.common.ui.client.configurable.mvc.layouts; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.HashMap; |
5 | |
import java.util.List; |
6 | |
import java.util.Map; |
7 | |
|
8 | |
import org.kuali.student.common.ui.client.configurable.mvc.LayoutController; |
9 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
10 | |
import org.kuali.student.common.ui.client.mvc.View; |
11 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
12 | |
import org.kuali.student.common.ui.client.widgets.headers.KSDocumentHeader; |
13 | |
import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData; |
14 | |
import org.kuali.student.common.ui.client.widgets.menus.impl.KSBlockMenuImpl; |
15 | |
import org.kuali.student.common.ui.client.widgets.panels.collapsable.VerticalCollapsableDrawer; |
16 | |
|
17 | |
import com.google.gwt.event.dom.client.ClickEvent; |
18 | |
import com.google.gwt.event.dom.client.ClickHandler; |
19 | |
import com.google.gwt.user.client.Command; |
20 | |
import com.google.gwt.user.client.DeferredCommand; |
21 | |
import com.google.gwt.user.client.ui.FlowPanel; |
22 | |
import com.google.gwt.user.client.ui.SimplePanel; |
23 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
24 | |
import com.google.gwt.user.client.ui.Widget; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class MenuSectionController extends LayoutController implements ContentNavLayoutController { |
34 | |
|
35 | 0 | private KSBlockMenuImpl menu = new KSBlockMenuImpl(); |
36 | 0 | private List<KSMenuItemData> topLevelMenuItems = new ArrayList<KSMenuItemData>(); |
37 | 0 | protected Map<String, List<View>> menuViewMap = new HashMap<String, List<View>>(); |
38 | 0 | private Map<Enum<?>, List<KSButton>> viewButtonsMap = new HashMap<Enum<?>, List<KSButton>>(); |
39 | 0 | protected Map<Enum<?>, KSMenuItemData> viewMenuItemMap = new HashMap<Enum<?>, KSMenuItemData>(); |
40 | 0 | private List<View> menuOrder = new ArrayList<View>(); |
41 | 0 | private FlowPanel layout = new FlowPanel(); |
42 | 0 | private KSDocumentHeader header = new KSDocumentHeader(); |
43 | 0 | private FlowPanel rightPanel = new FlowPanel(); |
44 | 0 | private FlowPanel contentPanel = new FlowPanel(); |
45 | 0 | private FlowPanel buttonPanel = new FlowPanel(); |
46 | 0 | private VerticalPanel leftPanel = new VerticalPanel(); |
47 | 0 | private SimplePanel sideBar = new SimplePanel(); |
48 | 0 | private boolean refreshMenuOnAdd = true; |
49 | 0 | private VerticalCollapsableDrawer collapsablePanel = new VerticalCollapsableDrawer(); |
50 | |
|
51 | 0 | private Callback<Boolean> showViewCallback = new Callback<Boolean>() { |
52 | |
|
53 | |
@Override |
54 | |
public void exec(Boolean result) { |
55 | 0 | if (result == false) { |
56 | 0 | KSMenuItemData item = viewMenuItemMap.get(MenuSectionController.this.getCurrentView().getViewEnum()); |
57 | 0 | if (item != null) { |
58 | 0 | item.setSelected(true, false); |
59 | |
} |
60 | |
} |
61 | 0 | } |
62 | |
}; |
63 | |
|
64 | |
public MenuSectionController() { |
65 | 0 | super(); |
66 | 0 | List<View> list = new ArrayList<View>(); |
67 | 0 | menuViewMap.put("", list); |
68 | 0 | menu.setStyleName("ks-menu-layout-menu"); |
69 | 0 | rightPanel.setStyleName("ks-menu-layout-rightColumn"); |
70 | 0 | collapsablePanel.addStyleName("ks-menu-layout-leftColumn"); |
71 | 0 | layout.addStyleName("ks-menu-layout"); |
72 | 0 | menu.setTopLevelItems(topLevelMenuItems); |
73 | 0 | collapsablePanel.setContent(leftPanel); |
74 | 0 | leftPanel.add(menu); |
75 | 0 | leftPanel.add(sideBar); |
76 | 0 | rightPanel.add(header); |
77 | 0 | rightPanel.add(contentPanel); |
78 | 0 | rightPanel.add(buttonPanel); |
79 | 0 | layout.add(collapsablePanel); |
80 | 0 | layout.add(rightPanel); |
81 | 0 | header.setVisible(false); |
82 | 0 | this.showPrint(true); |
83 | 0 | this.initWidget(layout); |
84 | 0 | } |
85 | |
|
86 | |
public void removeMenuNavigation() { |
87 | 0 | collapsablePanel.removeFromParent(); |
88 | 0 | } |
89 | |
|
90 | |
public void setContentTitle(String title) { |
91 | 0 | header.setTitle(title); |
92 | 0 | header.setVisible(true); |
93 | 0 | } |
94 | |
|
95 | |
public void addContentWidget(Widget w) { |
96 | 0 | header.addWidget(w); |
97 | 0 | header.setVisible(true); |
98 | 0 | } |
99 | |
|
100 | |
public void setSideBarWidget(Widget w) { |
101 | 0 | sideBar.setWidget(w); |
102 | 0 | } |
103 | |
|
104 | |
public void setContentInfo(String info) { |
105 | 0 | header.getInfoLabel().setHTML(info); |
106 | 0 | header.getInfoLabel().removeStyleName("content-warning"); |
107 | 0 | header.getInfoLabel().addStyleName("content-info"); |
108 | 0 | } |
109 | |
|
110 | |
public void setContentWarning(String info) { |
111 | 0 | header.getInfoLabel().setHTML(info); |
112 | 0 | header.getInfoLabel().removeStyleName("content-info"); |
113 | 0 | header.getInfoLabel().addStyleName("content-warning"); |
114 | |
|
115 | 0 | } |
116 | |
|
117 | |
public void showPrint(boolean show){ |
118 | 0 | header.showPrint(show); |
119 | 0 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public void addCommonButton(String parentMenu, KSButton button) { |
125 | 0 | if (parentMenu != null) { |
126 | 0 | List<View> views = menuViewMap.get(parentMenu); |
127 | 0 | if (views != null) { |
128 | 0 | for (int i = 0; i < views.size(); i++) { |
129 | 0 | addButtonForView(views.get(i).getViewEnum(), button); |
130 | |
} |
131 | |
} |
132 | |
} |
133 | 0 | } |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
public void addCommonButton(String parentMenu, KSButton button, List<Enum<?>> excludedViews) { |
139 | 0 | if (parentMenu != null) { |
140 | 0 | List<View> views = menuViewMap.get(parentMenu); |
141 | 0 | if (views != null) { |
142 | 0 | for (int i = 0; i < views.size(); i++) { |
143 | 0 | if (!excludedViews.contains(views.get(i).getViewEnum())) { |
144 | 0 | addButtonForView(views.get(i).getViewEnum(), button); |
145 | |
} |
146 | |
} |
147 | |
} |
148 | |
} |
149 | 0 | } |
150 | |
|
151 | |
public void showNextViewOnMenu() { |
152 | 0 | int i = menuOrder.indexOf(this.getCurrentView()); |
153 | 0 | if (i != -1 && i + 1 < menuOrder.size()) { |
154 | 0 | this.showView(menuOrder.get(i + 1).getViewEnum()); |
155 | |
} |
156 | 0 | } |
157 | |
|
158 | |
public void addButtonForView(Enum<?> viewType, KSButton button) { |
159 | 0 | List<KSButton> buttons = viewButtonsMap.get(viewType); |
160 | 0 | if (buttons == null) { |
161 | 0 | buttons = new ArrayList<KSButton>(); |
162 | 0 | button.addStyleName("ks-button-spacing"); |
163 | 0 | buttons.add(button); |
164 | 0 | viewButtonsMap.put(viewType, buttons); |
165 | |
} else { |
166 | 0 | buttons.add(button); |
167 | |
} |
168 | 0 | } |
169 | |
|
170 | |
@Override |
171 | |
protected void hideView(View view) { |
172 | 0 | contentPanel.clear(); |
173 | 0 | buttonPanel.clear(); |
174 | 0 | } |
175 | |
|
176 | |
@Override |
177 | |
protected void renderView(View view) { |
178 | 0 | contentPanel.add(view.asWidget()); |
179 | 0 | List<KSButton> buttons = viewButtonsMap.get(view.getViewEnum()); |
180 | 0 | if (buttons != null) { |
181 | 0 | for (KSButton button : buttons) { |
182 | 0 | buttonPanel.add(button); |
183 | |
} |
184 | |
} |
185 | 0 | KSMenuItemData item = viewMenuItemMap.get(view.getViewEnum()); |
186 | 0 | if (item != null) { |
187 | 0 | item.setSelected(true, false); |
188 | |
} |
189 | 0 | } |
190 | |
|
191 | |
|
192 | |
|
193 | |
public void addMenu(String title) { |
194 | 0 | if (title != null && !title.equals("")) { |
195 | 0 | KSMenuItemData item = new KSMenuItemData(title); |
196 | 0 | topLevelMenuItems.add(item); |
197 | 0 | List<View> list = new ArrayList<View>(); |
198 | 0 | menuViewMap.put(title, list); |
199 | 0 | if (refreshMenuOnAdd) { |
200 | 0 | menu.refresh(); |
201 | |
} |
202 | |
} |
203 | 0 | } |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
public void addStartMenuItem(String parentMenu, final View view) { |
214 | 0 | addMenuItem(parentMenu, view); |
215 | 0 | this.setDefaultView(view.getViewEnum()); |
216 | 0 | refreshMenuOnAdd = false; |
217 | 0 | menu.refresh(); |
218 | 0 | } |
219 | |
|
220 | |
public void revealMenuItems() { |
221 | 0 | menu.refresh(); |
222 | 0 | refreshMenuOnAdd = true; |
223 | 0 | } |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
@Override |
232 | |
public void addMenuItem(String parentMenu, final View view) { |
233 | 0 | super.addView(view); |
234 | 0 | KSMenuItemData parentItem = null; |
235 | 0 | for (int i = 0; i < topLevelMenuItems.size(); i++) { |
236 | 0 | if (topLevelMenuItems.get(i).getLabel().equals(parentMenu)) { |
237 | 0 | parentItem = topLevelMenuItems.get(i); |
238 | 0 | break; |
239 | |
} |
240 | |
} |
241 | |
|
242 | 0 | KSMenuItemData item = new KSMenuItemData(view.getName()); |
243 | 0 | viewMenuItemMap.put(view.getViewEnum(), item); |
244 | 0 | item.setClickHandler(new ClickHandler() { |
245 | |
|
246 | |
@Override |
247 | |
public void onClick(ClickEvent event) { |
248 | 0 | DeferredCommand.addCommand(new Command() { |
249 | |
@Override |
250 | |
public void execute() { |
251 | 0 | MenuSectionController.this.showView(view.getViewEnum(), showViewCallback); |
252 | 0 | } |
253 | |
}); |
254 | 0 | } |
255 | |
|
256 | |
}); |
257 | |
|
258 | 0 | if (parentItem != null) { |
259 | 0 | menuOrder.add(view); |
260 | 0 | parentItem.addSubItem(item); |
261 | 0 | menuViewMap.get(parentMenu).add(view); |
262 | |
} else { |
263 | 0 | menuOrder.add(view); |
264 | 0 | topLevelMenuItems.add(item); |
265 | 0 | menuViewMap.get("").add(view); |
266 | |
} |
267 | |
|
268 | 0 | if (refreshMenuOnAdd) { |
269 | 0 | menu.refresh(); |
270 | |
} |
271 | 0 | } |
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
@Override |
283 | |
public void addSpecialMenuItem(final View view, String description) { |
284 | |
|
285 | 0 | super.addView(view); |
286 | 0 | menuViewMap.get("").add(view); |
287 | 0 | menuOrder.add(view); |
288 | 0 | KSMenuItemData item = new KSMenuItemData(view.getName()); |
289 | 0 | item.addSpecialStyle("ks-menu-layout-special-menu-item-panel"); |
290 | 0 | viewMenuItemMap.put(view.getViewEnum(), item); |
291 | 0 | item.setClickHandler(new ClickHandler() { |
292 | |
|
293 | |
@Override |
294 | |
public void onClick(ClickEvent event) { |
295 | 0 | DeferredCommand.addCommand(new Command() { |
296 | |
@Override |
297 | |
public void execute() { |
298 | 0 | MenuSectionController.this.showView(view.getViewEnum(), showViewCallback); |
299 | 0 | } |
300 | |
}); |
301 | 0 | } |
302 | |
|
303 | |
}); |
304 | 0 | topLevelMenuItems.add(item); |
305 | 0 | if (refreshMenuOnAdd) { |
306 | 0 | menu.refresh(); |
307 | |
} |
308 | 0 | } |
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
@Override |
316 | |
public void updateModel() { |
317 | 0 | for (View v : menuOrder) { |
318 | 0 | v.updateModel(); |
319 | |
} |
320 | |
|
321 | 0 | } |
322 | |
|
323 | |
|
324 | |
} |