KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > wizard > WizardPageSupport


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.wizard;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.Collections JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19
20 import com.tonbeller.wcf.controller.RequestContext;
21
22 /**
23  * Support class for building WizardPage implementations.
24  *
25  * @author av
26  */

27 public class WizardPageSupport {
28   WizardPage source;
29   ArrayList JavaDoc listeners = new ArrayList JavaDoc();
30
31   public WizardPageSupport(WizardPage source) {
32     this.source = source;
33   }
34
35   public void fireNext(RequestContext context) throws Exception JavaDoc {
36     for (Iterator JavaDoc it = iterator(); it.hasNext();)
37       ((PageListener) it.next()).onNext(context);
38   }
39
40   public void fireBack(RequestContext context) throws Exception JavaDoc {
41     for (Iterator JavaDoc it = iterator(); it.hasNext();)
42       ((PageListener) it.next()).onBack(context);
43   }
44
45   public void fireFinish(RequestContext context) throws Exception JavaDoc {
46     for (Iterator JavaDoc it = iterator(); it.hasNext();)
47       ((PageListener) it.next()).onFinish(context);
48   }
49
50   public void fireCancel(RequestContext context) throws Exception JavaDoc {
51     for (Iterator JavaDoc it = iterator(); it.hasNext();)
52       ((PageListener) it.next()).onCancel(context);
53   }
54
55   private Iterator JavaDoc iterator() {
56     if (listeners.size() == 0)
57       return Collections.EMPTY_LIST.iterator();
58     List JavaDoc copy = (List JavaDoc) listeners.clone();
59     return copy.iterator();
60   }
61
62   public void addPageListener(PageListener l) {
63     listeners.add(l);
64   }
65
66   public void removePageListener(PageListener l) {
67     listeners.remove(l);
68   }
69
70   public void fireWizardButton(RequestContext context, String JavaDoc methodName) throws Exception JavaDoc {
71     if ("onNext".equals(methodName))
72       fireNext(context);
73     else if ("onBack".equals(methodName))
74       fireBack(context);
75     else if ("onCancel".equals(methodName))
76       fireCancel(context);
77     else if ("onFinish".equals(methodName))
78       fireFinish(context);
79   }
80
81 }
Popular Tags