KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > popup > TestBean


1 /*
2  * Copyright (c) 1971-2003 TONBELLER AG, Bensheim.
3  * All rights reserved.
4  */

5 package com.tonbeller.wcf.popup;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.List JavaDoc;
10
11 import javax.servlet.http.HttpSessionBindingEvent JavaDoc;
12 import javax.servlet.http.HttpSessionBindingListener JavaDoc;
13
14 import com.tonbeller.wcf.controller.Dispatcher;
15 import com.tonbeller.wcf.controller.DispatcherSupport;
16 import com.tonbeller.wcf.controller.RequestContext;
17 import com.tonbeller.wcf.controller.WcfController;
18
19 public class TestBean implements HttpSessionBindingListener JavaDoc {
20
21   Dispatcher disp = new DispatcherSupport();
22   String JavaDoc lastItem;
23
24   /**
25    * Items w/o groups
26    */

27   public PopUp getPopUp0() {
28     PopUp p = new PopUp();
29     p.setLabel("popup 0");
30     List JavaDoc items = new ArrayList JavaDoc();
31     addItems(items);
32     for (Iterator JavaDoc it = items.iterator(); it.hasNext();) {
33       Item item = (Item) it.next();
34       p.addItem(item);
35     }
36     return p;
37   }
38
39   /**
40    * 2 Items in anonymous group
41    */

42   public PopUp getPopUp1a() {
43     PopUp p = new PopUp();
44     p.setLabel("popup 1a");
45     // anonymous group
46
GroupItem g = new GroupItemSupport();
47     addItems(g.getChildren());
48     p.addItem(g);
49     return p;
50   }
51
52   /**
53    * 2 Items in named group
54    */

55   public PopUp getPopUp1b() {
56     PopUp p = new PopUp();
57     p.setLabel("popup 1b");
58     // anonymous group
59
GroupItem g = new GroupItemSupport("Group 1");
60     addItems(g.getChildren());
61     p.addItem(g);
62     return p;
63   }
64
65   public PopUp getPopUp2() {
66     PopUp p = new PopUp();
67     p.setLabel("popup 2");
68
69     GroupItem g = new GroupItemSupport("Group 1");
70     addItems(g.getChildren());
71     p.addItem(g);
72
73     g = new GroupItemSupport("Group 2", "/wcf/table/page-last.png");
74     addItems(g.getChildren());
75     p.addItem(g);
76
77     g = new GroupItemSupport("Group 3 is empty", "/wcf/table/page-first.png");
78     p.addItem(g);
79
80     g = new GroupItemSupport("Group 4", "/wcf/table/page-first.png");
81     addItems(g.getChildren());
82     p.addItem(g);
83     GroupItem sub = new GroupItemSupport("Group 4.1");
84     addItems(sub.getChildren());
85     g.getChildren().add(sub);
86     addItems(g.getChildren());
87     sub = new GroupItemSupport("Group 4.2", "/wcf/table/page-first.png");
88     addItems(sub.getChildren());
89     g.getChildren().add(sub);
90     addItems(g.getChildren());
91
92     return p;
93   }
94
95   private void addItems(List JavaDoc list) {
96     MenuItemSupport m;
97     m = new WcfMenuItem(disp, "Item 1") {
98       public void request(RequestContext context) throws Exception JavaDoc {
99         lastItem = "Item 1";
100       }
101     };
102     list.add(m);
103     m = new WcfMenuItem(disp, "Item 2", "/wcf/tree/accept.png") {
104       public void request(RequestContext context) throws Exception JavaDoc {
105         lastItem = "Item 2";
106       }
107     };
108     list.add(m);
109   }
110
111   public String JavaDoc getLastItem() {
112     disp.clear();
113     return lastItem;
114   }
115
116   public void setLastItem(String JavaDoc lastItem) {
117     this.lastItem = lastItem;
118   }
119
120   public void valueBound(HttpSessionBindingEvent JavaDoc e) {
121     WcfController.instance(e.getSession()).addRequestListener(disp);
122   }
123
124   public void valueUnbound(HttpSessionBindingEvent JavaDoc e) {
125   }
126
127 }
128
Popular Tags