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 | |
|
121 | 0 | } |
122 | |
|
123 | |
public void showExport(boolean show) { |
124 | 0 | header.showJasper(show); |
125 | 0 | } |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public void addCommonButton(String parentMenu, KSButton button) { |
131 | 0 | if (parentMenu != null) { |
132 | 0 | List<View> views = menuViewMap.get(parentMenu); |
133 | 0 | if (views != null) { |
134 | 0 | for (int i = 0; i < views.size(); i++) { |
135 | 0 | addButtonForView(views.get(i).getViewEnum(), button); |
136 | |
} |
137 | |
} |
138 | |
} |
139 | 0 | } |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
public void addCommonButton(String parentMenu, KSButton button, List<Enum<?>> excludedViews) { |
145 | 0 | if (parentMenu != null) { |
146 | 0 | List<View> views = menuViewMap.get(parentMenu); |
147 | 0 | if (views != null) { |
148 | 0 | for (int i = 0; i < views.size(); i++) { |
149 | 0 | if (!excludedViews.contains(views.get(i).getViewEnum())) { |
150 | 0 | addButtonForView(views.get(i).getViewEnum(), button); |
151 | |
} |
152 | |
} |
153 | |
} |
154 | |
} |
155 | 0 | } |
156 | |
|
157 | |
public void showNextViewOnMenu() { |
158 | 0 | int i = menuOrder.indexOf(this.getCurrentView()); |
159 | 0 | if (i != -1 && i + 1 < menuOrder.size()) { |
160 | 0 | this.showView(menuOrder.get(i + 1).getViewEnum()); |
161 | |
} |
162 | 0 | } |
163 | |
|
164 | |
public void addButtonForView(Enum<?> viewType, KSButton button) { |
165 | 0 | List<KSButton> buttons = viewButtonsMap.get(viewType); |
166 | 0 | if (buttons == null) { |
167 | 0 | buttons = new ArrayList<KSButton>(); |
168 | 0 | button.addStyleName("ks-button-spacing"); |
169 | 0 | buttons.add(button); |
170 | 0 | viewButtonsMap.put(viewType, buttons); |
171 | |
} else { |
172 | 0 | buttons.add(button); |
173 | |
} |
174 | 0 | } |
175 | |
|
176 | |
@Override |
177 | |
protected void hideView(View view) { |
178 | 0 | contentPanel.clear(); |
179 | 0 | buttonPanel.clear(); |
180 | 0 | } |
181 | |
|
182 | |
@Override |
183 | |
protected void renderView(View view) { |
184 | 0 | contentPanel.add(view.asWidget()); |
185 | 0 | List<KSButton> buttons = viewButtonsMap.get(view.getViewEnum()); |
186 | 0 | if (buttons != null) { |
187 | 0 | for (KSButton button : buttons) { |
188 | 0 | buttonPanel.add(button); |
189 | |
} |
190 | |
} |
191 | 0 | KSMenuItemData item = viewMenuItemMap.get(view.getViewEnum()); |
192 | 0 | if (item != null) { |
193 | 0 | item.setSelected(true, false); |
194 | |
} |
195 | 0 | } |
196 | |
|
197 | |
|
198 | |
|
199 | |
public void addMenu(String title) { |
200 | 0 | if (title != null && !title.equals("")) { |
201 | 0 | KSMenuItemData item = new KSMenuItemData(title); |
202 | 0 | topLevelMenuItems.add(item); |
203 | 0 | List<View> list = new ArrayList<View>(); |
204 | 0 | menuViewMap.put(title, list); |
205 | 0 | if (refreshMenuOnAdd) { |
206 | 0 | menu.refresh(); |
207 | |
} |
208 | |
} |
209 | 0 | } |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
public void addStartMenuItem(String parentMenu, final View view) { |
220 | 0 | addMenuItem(parentMenu, view); |
221 | 0 | this.setDefaultView(view.getViewEnum()); |
222 | 0 | refreshMenuOnAdd = false; |
223 | 0 | menu.refresh(); |
224 | 0 | } |
225 | |
|
226 | |
public void revealMenuItems() { |
227 | 0 | menu.refresh(); |
228 | 0 | refreshMenuOnAdd = true; |
229 | 0 | } |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
@Override |
238 | |
public void addMenuItem(String parentMenu, final View view) { |
239 | 0 | super.addView(view); |
240 | 0 | KSMenuItemData parentItem = null; |
241 | 0 | for (int i = 0; i < topLevelMenuItems.size(); i++) { |
242 | 0 | if (topLevelMenuItems.get(i).getLabel().equals(parentMenu)) { |
243 | 0 | parentItem = topLevelMenuItems.get(i); |
244 | 0 | break; |
245 | |
} |
246 | |
} |
247 | |
|
248 | 0 | KSMenuItemData item = new KSMenuItemData(view.getName()); |
249 | 0 | viewMenuItemMap.put(view.getViewEnum(), item); |
250 | 0 | item.setClickHandler(new ClickHandler() { |
251 | |
|
252 | |
@Override |
253 | |
public void onClick(ClickEvent event) { |
254 | 0 | DeferredCommand.addCommand(new Command() { |
255 | |
@Override |
256 | |
public void execute() { |
257 | 0 | MenuSectionController.this.showView(view.getViewEnum(), showViewCallback); |
258 | 0 | } |
259 | |
}); |
260 | 0 | } |
261 | |
|
262 | |
}); |
263 | |
|
264 | 0 | if (parentItem != null) { |
265 | 0 | menuOrder.add(view); |
266 | 0 | parentItem.addSubItem(item); |
267 | 0 | menuViewMap.get(parentMenu).add(view); |
268 | |
} else { |
269 | 0 | menuOrder.add(view); |
270 | 0 | topLevelMenuItems.add(item); |
271 | 0 | menuViewMap.get("").add(view); |
272 | |
} |
273 | |
|
274 | 0 | if (refreshMenuOnAdd) { |
275 | 0 | menu.refresh(); |
276 | |
} |
277 | 0 | } |
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
@Override |
289 | |
public void addSpecialMenuItem(final View view, String description) { |
290 | |
|
291 | 0 | super.addView(view); |
292 | 0 | menuViewMap.get("").add(view); |
293 | 0 | menuOrder.add(view); |
294 | 0 | KSMenuItemData item = new KSMenuItemData(view.getName()); |
295 | 0 | item.addSpecialStyle("ks-menu-layout-special-menu-item-panel"); |
296 | 0 | viewMenuItemMap.put(view.getViewEnum(), item); |
297 | 0 | item.setClickHandler(new ClickHandler() { |
298 | |
|
299 | |
@Override |
300 | |
public void onClick(ClickEvent event) { |
301 | 0 | DeferredCommand.addCommand(new Command() { |
302 | |
@Override |
303 | |
public void execute() { |
304 | 0 | MenuSectionController.this.showView(view.getViewEnum(), showViewCallback); |
305 | 0 | } |
306 | |
}); |
307 | 0 | } |
308 | |
|
309 | |
}); |
310 | 0 | topLevelMenuItems.add(item); |
311 | 0 | if (refreshMenuOnAdd) { |
312 | 0 | menu.refresh(); |
313 | |
} |
314 | 0 | } |
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
@Override |
322 | |
public void updateModel() { |
323 | 0 | for (View v : menuOrder) { |
324 | 0 | v.updateModel(); |
325 | |
} |
326 | |
|
327 | 0 | } |
328 | |
|
329 | |
@Override |
330 | |
public ArrayList<ExportElement> getExportElementsFromView() { |
331 | 0 | return super.getExportElementsFromView(); |
332 | |
|
333 | |
} |
334 | |
} |