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