KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.exoplatform.faces.core.component.UIForm;
8 import org.exoplatform.faces.core.event.ExoActionEvent;
9 import org.exoplatform.faces.core.event.ExoActionListener;
10 import org.exoplatform.faces.core.validator.EmptyFieldValidator ;
11 import org.exoplatform.services.communication.forum.Category;
12 import org.exoplatform.services.communication.forum.Forum;
13 import org.exoplatform.services.communication.forum.ForumService;
14 /**
15  * Sat, Jan 03, 2004 @ 11:16
16  * @author: Tuan Nguyen
17  * @email: tuan08@users.sourceforge.net
18  * @version: $Id: UIForumForm.java,v 1.7 2004/10/17 13:46:25 tuan08 Exp $
19  */

20 public class UIForumForm extends UIForm {
21   private static String JavaDoc FORUM_NAME = "forumName" , FORUM_DESC = "forumDesc" ,
22                         VIEW_FORUM_ROLE = "viewRole", CREATE_TOPIC_ROLE = "createTopic",
23                         REPLY_TOPIC_ROLE = "replyTopic", MODERATORS = "moderators" ,
24                         FORUM_ORDER = "order" ;
25   
26   private ForumService service_ ;
27   private Forum forum_ ;
28   private String JavaDoc categoryId_ ;
29   
30   public UIForumForm(ForumService service) throws Exception JavaDoc {
31     super("forumForm") ;
32     setId("UIForumForm") ;
33     service_ = service ;
34     
35     addContainer("#{UIForumForm.header.title}").
36       add(new StringField(FORUM_NAME, "#{UIForumForm.label.name}", "")).
37       add(new TextAreaField(FORUM_DESC, "#{UIForumForm.label.description}", "")).
38       add(new StringField(VIEW_FORUM_ROLE, "#{UIForumForm.label.view-forum-role}", "")).
39       add(new StringField(CREATE_TOPIC_ROLE, "#{UIForumForm.label.create-topic-role}", "")).
40       add(new StringField(REPLY_TOPIC_ROLE, "#{UIForumForm.label.reply-topic-role}", "")).
41       add(new StringField(MODERATORS, "#{UIForumForm.label.moderators}", "")).
42       add(new IntegerField(FORUM_ORDER, "#{UIForumForm.label.forum-order}", 0));
43     addButton(new Button("#{UIForumForm.button.save}", SAVE_ACTION)) ;
44     addButton(new Button("#{UIForumForm.button.cancel}", CANCEL_ACTION)) ;
45     addFieldValidator(EmptyFieldValidator.class) ;
46     addActionListener(CancelActionListener.class, CANCEL_ACTION) ;
47     addActionListener(SaveActionListener.class, SAVE_ACTION) ;
48   }
49   
50   public void setForum(String JavaDoc categoryId, Forum forum) {
51     forum_ = forum ;
52     categoryId_ = categoryId ;
53     if (forum == null) {
54       resetFields() ;
55     } else {
56       setStringFieldValue(FORUM_NAME, forum.getForumName()) ;
57       setStringFieldValue(FORUM_DESC, forum.getDescription()) ;
58       setStringFieldValue(VIEW_FORUM_ROLE, forum.getViewForumRole()) ;
59       setStringFieldValue(CREATE_TOPIC_ROLE, forum.getCreateTopicRole()) ;
60       setStringFieldValue(REPLY_TOPIC_ROLE, forum.getReplyTopicRole()) ;
61       setStringFieldValue(MODERATORS, forum.getModerators()) ;
62       setIntegerFieldValue(FORUM_ORDER, forum.getForumOrder()) ;
63     }
64   }
65   
66   public boolean canDecodeInvalidState() { return categoryId_ != null; }
67   
68   static public class CancelActionListener extends ExoActionListener {
69         public void execute(ExoActionEvent event) throws Exception JavaDoc {
70             UIForumForm uiForm = (UIForumForm) event.getComponent() ;
71             uiForm.setRenderedSibling(UIAdminViewCategories.class) ;
72         }
73   }
74   
75   static public class SaveActionListener extends ExoActionListener {
76         public void execute(ExoActionEvent event) throws Exception JavaDoc {
77             UIForumForm uiForm = (UIForumForm) event.getComponent() ;
78             Forum forum = uiForm.forum_ ;
79       boolean isNew = false ;
80       if(forum == null) {
81         forum = uiForm.service_.createForumInstance() ;
82         isNew = true ;
83       }
84       forum.setForumName(uiForm.getStringFieldValue(FORUM_NAME)) ;
85       forum.setDescription(uiForm.getStringFieldValue(FORUM_DESC)) ;
86       forum.setViewForumRole(uiForm.getStringFieldValue(VIEW_FORUM_ROLE)) ;
87       forum.setCreateTopicRole(uiForm.getStringFieldValue(CREATE_TOPIC_ROLE)) ;
88       forum.setReplyTopicRole(uiForm.getStringFieldValue(REPLY_TOPIC_ROLE)) ;
89       forum.setModerators(uiForm.getStringFieldValue(MODERATORS)) ;
90       forum.setForumOrder(uiForm.getIntegerFieldValue(FORUM_ORDER)) ;
91       if(isNew) {
92         Category category = uiForm.service_.getCategory(uiForm.categoryId_) ;
93         uiForm.service_.addForum(category , forum) ;
94       } else {
95         uiForm.service_.updateForum(forum) ;
96       }
97       UIAdminViewCategories uiCategories =
98         (UIAdminViewCategories) uiForm.getSibling(UIAdminViewCategories.class) ;
99       uiCategories.update() ;
100             uiForm.setRenderedSibling(UIAdminViewCategories.class) ;
101         }
102   }
103 }
Popular Tags