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