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