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