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