001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.example.main.web.menu;
016:
017: import org.apache.commons.lang.exception.ExceptionUtils;
018: import org.araneaframework.OutputData;
019: import org.araneaframework.Widget;
020: import org.araneaframework.core.ProxyEventListener;
021: import org.araneaframework.example.common.framework.TemplateMenuWidget;
022: import org.araneaframework.example.main.SecurityContext;
023: import org.araneaframework.example.main.release.ReleaseWidget;
024: import org.araneaframework.example.main.release.demos.DemoActionPollWidget;
025: import org.araneaframework.example.main.release.demos.DemoAutoCompletionWidget;
026: import org.araneaframework.example.main.release.demos.DemoContextMenuWidget;
027: import org.araneaframework.example.main.release.demos.DemoNewTabWidget;
028: import org.araneaframework.example.main.release.demos.FriendlyUpdateDemoWidget;
029: import org.araneaframework.example.main.release.demos.ModalDialogDemoWidget;
030: import org.araneaframework.example.main.release.demos.SimpleTreeWidget;
031: import org.araneaframework.example.main.release.features.EasyAJAXUpdateRegionsWidget;
032: import org.araneaframework.example.main.release.features.SeamlessFormValidationDemoWidget;
033: import org.araneaframework.example.main.release.features.SimpleInMemoryEditableList;
034: import org.araneaframework.example.main.release.features.SimpleListWidget;
035: import org.araneaframework.example.main.web.FooterWidget;
036: import org.araneaframework.example.main.web.company.CompanyListWidget;
037: import org.araneaframework.example.main.web.contract.ContractAddEditWidget;
038: import org.araneaframework.example.main.web.contract.ContractListWidget;
039: import org.araneaframework.example.main.web.demo.DemoAutomaticFormElement;
040: import org.araneaframework.example.main.web.demo.DemoCheckboxList;
041: import org.araneaframework.example.main.web.demo.DemoComplexForm;
042: import org.araneaframework.example.main.web.demo.DemoDisplayForm;
043: import org.araneaframework.example.main.web.demo.DemoDisplayableEditableList;
044: import org.araneaframework.example.main.web.demo.DemoEmbeddedDisplayableEditableList;
045: import org.araneaframework.example.main.web.demo.DemoFileUpload;
046: import org.araneaframework.example.main.web.demo.DemoFlowEventConfirmationWidget;
047: import org.araneaframework.example.main.web.demo.DemoFormList;
048: import org.araneaframework.example.main.web.demo.DemoInMemoryEditableList;
049: import org.araneaframework.example.main.web.demo.DemoMultiSelect;
050: import org.araneaframework.example.main.web.demo.DemoOnChangeListenersWidget;
051: import org.araneaframework.example.main.web.demo.DemoRadioSelect;
052: import org.araneaframework.example.main.web.demo.DemoRichTextForm;
053: import org.araneaframework.example.main.web.demo.FilteredInputDemoWidget;
054: import org.araneaframework.example.main.web.list.MultiListWidget;
055: import org.araneaframework.example.main.web.list.SimpleSubBeanListWidget;
056: import org.araneaframework.example.main.web.misc.AjaxRequestErrorWidget;
057: import org.araneaframework.example.main.web.misc.EventErrorWidget;
058: import org.araneaframework.example.main.web.misc.InitErrorWidget;
059: import org.araneaframework.example.main.web.misc.RedirectingWidget;
060: import org.araneaframework.example.main.web.misc.RenderErrorWidget;
061: import org.araneaframework.example.main.web.person.PersonEditableListWidget;
062: import org.araneaframework.example.main.web.person.PersonListWidget;
063: import org.araneaframework.example.main.web.popups.DemoAdvancedPopupUsageWidget;
064: import org.araneaframework.example.main.web.sample.FormComplexConstraintDemoWidget;
065: import org.araneaframework.example.main.web.sample.SampleActionFormWidget;
066: import org.araneaframework.example.main.web.sample.SamplePopupWidget;
067: import org.araneaframework.example.main.web.sample.SimpleFormWidget;
068: import org.araneaframework.example.main.web.testing.ModalDialogTestWidget;
069: import org.araneaframework.example.main.web.tree.ComplexTreeWidget;
070: import org.araneaframework.example.main.web.tree.UnsynchronizedTreeWidget;
071: import org.araneaframework.http.util.ServletUtil;
072: import org.araneaframework.uilib.core.MenuItem;
073: import org.araneaframework.uilib.support.FlowCreator;
074:
075: /**
076: * @author Taimo Peelo (taimo@araneaframework.org)
077: */
078: public class MenuWidget extends TemplateMenuWidget {
079: private static final long serialVersionUID = 1L;
080: private MenuItem araneaMenu;
081:
082: public MenuWidget(Widget topWidget) throws Exception {
083: super (topWidget);
084: }
085:
086: protected void init() throws Exception {
087: super .init();
088:
089: addWidget("footer", new FooterWidget());
090: addEventListener("logout", new ProxyEventListener(this ));
091: addEventListener("mainPage", new ProxyEventListener(this ));
092: }
093:
094: public void handleEventLogout() throws Exception {
095: ((SecurityContext) getEnvironment().requireEntry(
096: SecurityContext.class)).logout();
097: }
098:
099: public void handleEventMainPage() throws Exception {
100: reset(null);
101: menu.clearSelection();
102: }
103:
104: public MenuItem getAraneaMenu() {
105: return araneaMenu;
106: }
107:
108: protected MenuItem buildMenu() throws Exception {
109: MenuItem result = new MenuItem();
110: araneaMenu = result.addMenuItem(null, new MenuItem(
111: "Aranea_1_1", ReleaseWidget.class));
112: // Aranea 1.1 features/demos
113: araneaMenu.addMenuItem(new MenuItem("Context_Menus",
114: DemoContextMenuWidget.class));
115: araneaMenu.addMenuItem(new MenuItem("Easy_AJAX_Update_Regions",
116: EasyAJAXUpdateRegionsWidget.class));
117: araneaMenu.addMenuItem(new MenuItem("Cooperative_Form",
118: FriendlyUpdateDemoWidget.class));
119: araneaMenu.addMenuItem(new MenuItem("AutoComplete",
120: DemoAutoCompletionWidget.class));
121: araneaMenu.addMenuItem(new MenuItem("List",
122: SimpleListWidget.class));
123: araneaMenu.addMenuItem(new MenuItem("SimpleEditableList",
124: SimpleInMemoryEditableList.class));
125: araneaMenu.addMenuItem(new MenuItem("Modal_Dialog",
126: ModalDialogDemoWidget.class));
127: araneaMenu.addMenuItem(new MenuItem("Seamless_Validation",
128: SeamlessFormValidationDemoWidget.class));
129: araneaMenu.addMenuItem(new MenuItem("Tabs_Demo",
130: DemoNewTabWidget.class));
131: araneaMenu.addMenuItem(new MenuItem("TreeComponent",
132: SimpleTreeWidget.class));
133: araneaMenu.addMenuItem(new MenuItem("Serverside_Polling",
134: DemoActionPollWidget.class));
135:
136: // "Management"
137: result.addMenuItem(null, new MenuItem("Management"));
138: {
139: result.addMenuItem("Management", new MenuItem("Persons"));
140: // example use of simple FlowCreator
141: result.addMenuItem("Management.Persons", new MenuItem(
142: "View_Add", new FlowCreator() {
143: private static final long serialVersionUID = 1L;
144:
145: public Widget createFlow() {
146: return new PersonListWidget(true);
147: }
148: }));
149: result.addMenuItem("Management.Persons", new MenuItem(
150: "Editable_List_Memory",
151: PersonEditableListWidget.Memory.class));
152: result.addMenuItem("Management.Persons", new MenuItem(
153: "Editable_List_Backend",
154: PersonEditableListWidget.Backend.class));
155:
156: result.addMenuItem("Management", new MenuItem("Companies"));
157: result.addMenuItem("Management.Companies", new MenuItem(
158: "View_Edit", CompanyListWidget.class));
159:
160: result.addMenuItem("Management", new MenuItem("Contracts"));
161: result.addMenuItem("Management.Contracts", new MenuItem(
162: "View_Edit", ContractListWidget.class));
163: result.addMenuItem("Management.Contracts", new MenuItem(
164: "Add", ContractAddEditWidget.class));
165: }
166:
167: // Another way of adding menuitems is available
168: MenuItem sampleMenu = result.addMenuItem(new MenuItem("Demos"));
169: {
170: sampleMenu.addMenuItem(new MenuItem("Simple"));
171: sampleMenu.addMenuItem("Simple", new MenuItem(
172: "Simple_Form", SimpleFormWidget.class));
173: sampleMenu.addMenuItem("Simple", new MenuItem(
174: "Search_Form",
175: FormComplexConstraintDemoWidget.class));
176: sampleMenu.addMenuItem("Simple", new MenuItem(
177: "Popup_Example", SamplePopupWidget.class));
178: sampleMenu.addMenuItem("Simple", new MenuItem(
179: "MultiSelect", DemoMultiSelect.class));
180: sampleMenu.addMenuItem("Simple", new MenuItem(
181: "RadioSelect", DemoRadioSelect.class));
182: sampleMenu.addMenuItem("Simple", new MenuItem(
183: "demo_automaticForm_title",
184: DemoAutomaticFormElement.class));
185:
186: MenuItem advDemos = sampleMenu.addMenuItem(new MenuItem(
187: "Advanced"));
188: sampleMenu.addMenuItem("Advanced", new MenuItem(
189: "File_Upload", DemoFileUpload.class));
190: sampleMenu.addMenuItem("Advanced", new MenuItem(
191: "Complex_Form", DemoComplexForm.class));
192: sampleMenu.addMenuItem("Advanced", new MenuItem(
193: "Rich_Text_Editor", DemoRichTextForm.class));
194: sampleMenu.addMenuItem("Advanced", new MenuItem(
195: "Advanced_Popup",
196: DemoAdvancedPopupUsageWidget.class));
197: sampleMenu.addMenuItem("Advanced", new MenuItem(
198: "Flow_Navigation_Confirmation",
199: DemoFlowEventConfirmationWidget.class));
200:
201: advDemos.addMenuItem(new MenuItem("demo_filteredinput",
202: FilteredInputDemoWidget.class));
203: advDemos.addMenuItem(new MenuItem("OnChangeListeners",
204: DemoOnChangeListenersWidget.class));
205: advDemos.addMenuItem(new MenuItem("Form_with_Actions",
206: SampleActionFormWidget.class));
207: advDemos.addMenuItem(new MenuItem("ModalDialogTesting",
208: ModalDialogTestWidget.class));
209:
210: MenuItem formListMenu = sampleMenu
211: .addMenuItem(new MenuItem("Form_Lists"));
212: formListMenu.addMenuItem(new MenuItem("Display_Form",
213: DemoDisplayForm.class));
214: formListMenu.addMenuItem(new MenuItem("Editable_List",
215: DemoFormList.class));
216: formListMenu.addMenuItem(new MenuItem(
217: "In_memory_editable_list",
218: DemoInMemoryEditableList.class));
219: formListMenu.addMenuItem(new MenuItem(
220: "Editable_checkbox_list", DemoCheckboxList.class));
221: formListMenu.addMenuItem(new MenuItem(
222: "Displayable_editable_list",
223: DemoDisplayableEditableList.class));
224: formListMenu.addMenuItem(new MenuItem("Embedded_Form_List",
225: DemoEmbeddedDisplayableEditableList.class));
226:
227: sampleMenu.addMenuItem(new MenuItem("Lists"));
228: sampleMenu.addMenuItem("Lists", new MenuItem(
229: "Contacts_SubBeanList",
230: SimpleSubBeanListWidget.class));
231: sampleMenu.addMenuItem("Lists", new MenuItem("Multi_List",
232: MultiListWidget.class));
233:
234: MenuItem treeMenu = sampleMenu.addMenuItem(new MenuItem(
235: "Trees"));
236: treeMenu.addMenuItem(new MenuItem("Simple_Tree",
237: SimpleTreeWidget.class));
238: treeMenu.addMenuItem(new MenuItem("Complex_Tree",
239: ComplexTreeWidget.class));
240: treeMenu.addMenuItem(new MenuItem(
241: "Tree_with_Unsynchronized_Actions",
242: UnsynchronizedTreeWidget.class));
243: }
244:
245: MenuItem errorMenu = result.addMenuItem(new MenuItem("Misc"));
246: {
247: errorMenu.addMenuItem(new MenuItem("Error_on_init",
248: InitErrorWidget.class));
249: errorMenu.addMenuItem(new MenuItem("Error_on_event",
250: EventErrorWidget.class));
251: errorMenu.addMenuItem(new MenuItem("Error_on_render",
252: RenderErrorWidget.class));
253: errorMenu.addMenuItem(new MenuItem("Error_on_ajax_request",
254: AjaxRequestErrorWidget.class));
255: errorMenu.addMenuItem(new MenuItem("Redirecting",
256: RedirectingWidget.class));
257: }
258:
259: return result;
260: }
261:
262: protected void renderExceptionHandler(OutputData output, Exception e)
263: throws Exception {
264: if (ExceptionUtils.getRootCause(e) != null) {
265: putViewDataOnce("rootStackTrace", ExceptionUtils
266: .getFullStackTrace(ExceptionUtils.getRootCause(e)));
267: }
268: putViewDataOnce("fullStackTrace", ExceptionUtils
269: .getFullStackTrace(e));
270:
271: ServletUtil.include("/WEB-INF/jsp/menuError.jsp", this, output);
272: }
273: }
|