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