1 13 package com.tonbeller.wcf.wizard; 14 15 import java.util.ArrayList ; 16 import java.util.Collections ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 20 import com.tonbeller.wcf.controller.RequestContext; 21 22 27 public class WizardPageSupport { 28 WizardPage source; 29 ArrayList listeners = new ArrayList (); 30 31 public WizardPageSupport(WizardPage source) { 32 this.source = source; 33 } 34 35 public void fireNext(RequestContext context) throws Exception { 36 for (Iterator it = iterator(); it.hasNext();) 37 ((PageListener) it.next()).onNext(context); 38 } 39 40 public void fireBack(RequestContext context) throws Exception { 41 for (Iterator it = iterator(); it.hasNext();) 42 ((PageListener) it.next()).onBack(context); 43 } 44 45 public void fireFinish(RequestContext context) throws Exception { 46 for (Iterator it = iterator(); it.hasNext();) 47 ((PageListener) it.next()).onFinish(context); 48 } 49 50 public void fireCancel(RequestContext context) throws Exception { 51 for (Iterator it = iterator(); it.hasNext();) 52 ((PageListener) it.next()).onCancel(context); 53 } 54 55 private Iterator iterator() { 56 if (listeners.size() == 0) 57 return Collections.EMPTY_LIST.iterator(); 58 List copy = (List ) 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 methodName) throws Exception { 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 |