01: package org.araneaframework.example.main.release.demos;
02:
03: import java.lang.reflect.Field;
04: import java.util.Arrays;
05: import java.util.Iterator;
06: import java.util.Map;
07: import org.apache.commons.beanutils.BeanPropertyValueEqualsPredicate;
08: import org.apache.commons.collections.CollectionUtils;
09: import org.araneaframework.Widget;
10: import org.araneaframework.example.main.TemplateBaseWidget;
11: import org.araneaframework.example.main.web.menu.MenuWidget;
12: import org.araneaframework.uilib.core.MenuContext;
13: import org.araneaframework.uilib.core.MenuItem;
14: import org.araneaframework.uilib.tab.TabContainerWidget;
15:
16: /**
17: * Demonstrates usage of tabs—{@link TabContainerWidget}.
18: *
19: * @author Taimo Peelo (taimo@araneaframework.org)
20: */
21: public class DemoNewTabWidget extends TemplateBaseWidget {
22: protected void init() throws Exception {
23: setViewSelector("release/demos/tab");
24:
25: TabContainerWidget containerWidget = new TabContainerWidget();
26: addWidget("tabContainer", containerWidget);
27:
28: addTabs(containerWidget);
29: }
30:
31: // whole method is a hack to determine menu content and show it in different tabs
32: private void addTabs(TabContainerWidget containerWidget)
33: throws IllegalAccessException, InstantiationException {
34: Map araneaDemos = ((MenuWidget) getEnvironment().getEntry(
35: MenuContext.class)).getAraneaMenu().getSubMenu();
36: for (Iterator i = araneaDemos.entrySet().iterator(); i
37: .hasNext();) {
38: Map.Entry entry = (Map.Entry) i.next();
39: MenuItem menuItem = ((MenuItem) entry.getValue());
40:
41: Field classfield = (Field) CollectionUtils.find(Arrays
42: .asList(menuItem.getClass().getDeclaredFields()),
43: new BeanPropertyValueEqualsPredicate("name",
44: "flowClass"));
45:
46: if (classfield == null)
47: continue;
48:
49: classfield.setAccessible(true);
50: Class clazz = (Class) classfield.get(menuItem);
51:
52: containerWidget.addTab((String) entry.getKey(), menuItem
53: .getLabel(), (Widget) clazz.newInstance());
54: // show tab for current widget too, if it was found from menu: but disable it
55: if (this .getClass().equals(clazz))
56: containerWidget.disableTab((String) entry.getKey());
57: }
58: }
59: }
|