KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > communication > forum > component > UIWatchForm


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.communication.forum.component;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9 import org.exoplatform.faces.core.component.UISelectBox;
10 import org.exoplatform.faces.core.component.UISimpleForm;
11 import org.exoplatform.faces.core.component.UIStringInput;
12 import org.exoplatform.faces.core.component.model.*;
13 import org.exoplatform.faces.core.event.ExoActionEvent;
14 import org.exoplatform.faces.core.event.ExoActionListener ;
15 import org.exoplatform.services.communication.forum.ForumService;
16 import org.exoplatform.services.communication.forum.Watcher ;
17 /**
18  * Sat, Jan 03, 2004 @ 11:16
19  * @author: Tuan Nguyen
20  * @email: tuan08@users.sourceforge.net
21  * @version: $Id: UICategoryForm.java,v 1.7 2004/10/17 13:46:25 tuan08 Exp $
22  */

23 public class UIWatchForm extends UISimpleForm {
24   private static List JavaDoc protocols ;
25
26   static {
27     protocols = new ArrayList JavaDoc(10) ;
28     protocols.add(new SelectItem("smtp(email)", "smtp")) ;
29     protocols.add(new SelectItem("sms(Not Support Yet)", "sms")) ;
30   }
31   
32   private ForumService service_ ;
33   private Cell userName ;
34   private UISelectBox protocol_ ;
35   private UIStringInput address_ ;
36   private Watcher watcher_ ;
37   
38   public UIWatchForm(ForumService service) throws Exception JavaDoc {
39     super("watchForm", "post", null) ;
40     setId("UIWatchForm") ;
41     setClazz("UIWatchForm") ;
42     service_ = service ;
43     address_ = new UIStringInput("address", "") ;
44     protocol_ = new UISelectBox("protocol", "smtp", protocols) ;
45     userName = new Cell("") ;
46     add(new HeaderRow().
47         add(new Cell("#{UIWatchForm.header}").
48             addColspan("2")));
49     add(new Row().
50         add(new LabelCell("#{UIWatchForm.label.username}")).
51         add(userName));
52     add(new Row().
53         add(new LabelCell("#{UIWatchForm.label.protocol}")).
54         add(new ComponentCell(this, protocol_)));
55     add(new Row().
56         add(new LabelCell("#{UIWatchForm.label.address}")).
57         add(new ComponentCell(this, address_)));
58     add(new Row().
59         add(new ListComponentCell().
60             add(new FormButton("#{UIWatchForm.button.save}", SAVE_ACTION)).
61             add(new FormButton("#{UIWatchForm.button.cancel}", CANCEL_ACTION)).
62             addColspan("2").addAlign("center"))) ;
63     addActionListener(CancelActionListener.class, CANCEL_ACTION) ;
64     addActionListener(SaveActionListener.class, SAVE_ACTION) ;
65   }
66   
67   public void setWatcher(Watcher watcher) throws Exception JavaDoc {
68     watcher_ = watcher ;
69     userName.setValue(watcher.getUserName()) ;
70     address_.setValue(watcher.getAddress()) ;
71   }
72   
73   static public class CancelActionListener extends ExoActionListener {
74         public void execute(ExoActionEvent event) throws Exception JavaDoc {
75             UIWatchForm uiForm = (UIWatchForm) event.getComponent() ;
76       uiForm.setRenderedSibling(UITopics.class) ;
77         }
78   }
79   
80   static public class SaveActionListener extends ExoActionListener {
81         public void execute(ExoActionEvent event) throws Exception JavaDoc {
82             UIWatchForm uiForm = (UIWatchForm) event.getComponent() ;
83       uiForm.watcher_.setMessageProtocol(uiForm.protocol_.getValue()) ;
84       uiForm.watcher_.setAddress(uiForm.address_.getValue()) ;
85       uiForm.service_.saveWatcher(uiForm.watcher_) ;
86       uiForm.setRenderedSibling(UITopics.class) ;
87         }
88   }
89 }
Popular Tags