KickJava   Java API By Example, From Geeks To Geeks.

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


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.UIExoCommand;
8 import org.exoplatform.faces.core.component.UIPageListIterator;
9 import org.exoplatform.faces.core.component.model.PageListDataHandler;
10 import org.exoplatform.faces.core.component.model.Parameter;
11 import org.exoplatform.faces.core.event.ExoActionEvent;
12 import org.exoplatform.faces.core.event.ExoActionListener;
13 import org.exoplatform.portlets.communication.forum.ForumACL;
14 import org.exoplatform.services.communication.forum.Forum;
15 import org.exoplatform.services.communication.forum.ForumService;
16 import org.exoplatform.services.communication.forum.Post;
17 import org.exoplatform.services.communication.forum.Topic;
18 import org.exoplatform.services.grammar.wiki.WikiEngineService ;
19 import org.exoplatform.services.organization.OrganizationService ;
20 /**
21  * Sat, Jan 03, 2004 @ 11:16
22  * @author: Tuan Nguyen
23  * @email: tuan08@users.sourceforge.net
24  * @version: $Id: UIPosts.java,v 1.9 2004/10/20 18:46:31 benjmestrallet Exp $
25  */

26 public class UIPosts extends UIExoCommand {
27   private UIPageListIterator uiPageIterator_ ;
28   private Topic topic_ ;
29   private Forum forum_ ;
30   private ForumService service_ ;
31   private ForumACL acl_ ;
32   private WikiEngineService wikiEngineService_ ;
33   private OrganizationService orgService_ ;
34     
35   private static final String JavaDoc REPLY = "reply";
36   private static final String JavaDoc VIEW_FORUMS = "viewForums";
37
38   public static Parameter[] replyParams = { new Parameter(ACTION , REPLY)} ;
39   public static Parameter[] viewForumsParams = { new Parameter(ACTION , VIEW_FORUMS)} ;
40    
41   public UIPosts(WikiEngineService weService,
42                  OrganizationService orgService,
43                  ForumService service, ForumACL acl) throws Exception JavaDoc {
44     setRendererType("PostsRenderer") ;
45     setId("UIPosts") ;
46     wikiEngineService_ = weService ;
47     orgService_ = orgService ;
48     uiPageIterator_ = new UIPageListIterator(new PageListDataHandler()) ;
49     getChildren().add(uiPageIterator_);
50     service_ = service ;
51     acl_ = acl ;
52     
53     addActionListener(ViewTopicsActionListener.class, "viewTopics") ;
54     addActionListener(ViewForumsActionListener.class, VIEW_FORUMS) ;
55     addActionListener(QuotePostActionListener.class, "quotePost") ;
56     addActionListener(EditPostActionListener.class, "editPost") ;
57     addActionListener(ReplyActionListener.class, REPLY) ;
58   }
59   
60   
61   public String JavaDoc getForumName() { return forum_.getForumName(); }
62    
63   public Topic getTopic() { return topic_ ; }
64
65   public WikiEngineService getWikiEngineService() { return wikiEngineService_ ; }
66   
67   public OrganizationService getOrganizationService() { return orgService_ ; }
68   
69   public void setUIPostsData(Forum forum, Topic topic) throws Exception JavaDoc {
70     forum_ = forum ;
71     topic_ = topic ;
72     uiPageIterator_.setPageList(service_.getPosts(topic_.getId())) ;
73   }
74   
75   public void reload() throws Exception JavaDoc {
76     uiPageIterator_.setPageList(service_.getPosts(forum_.getId())) ;
77   }
78   
79   public boolean hasModeratorRole() { return acl_.hasModeratorRole(forum_) ; }
80
81   public boolean hasViewForumRole() { return acl_.hasViewForumRole(forum_) ; }
82
83   public boolean hasCreateTopicRole() { return acl_.hasCreateTopicRole(forum_) ; }
84
85   public boolean hasReplyTopicRole() { return acl_.hasReplyTopicRole(forum_) ; }
86   
87   public String JavaDoc getRemoteUser() { return acl_.getRemoteUser() ; }
88
89   public UIPageListIterator getUIPageIterator() { return uiPageIterator_ ; }
90   
91   public boolean canDecodeInvalidState() { return forum_ != null || topic_ != null; }
92   
93   static public class ViewTopicsActionListener extends ExoActionListener {
94         public void execute(ExoActionEvent event) throws Exception JavaDoc {
95             UIPosts uiPosts = (UIPosts) event.getComponent() ;
96       UIForumPortlet forumPortlet = (UIForumPortlet)uiPosts.getAncestorOfType(UIForumPortlet.class);
97       forumPortlet.addHistoryElement(uiPosts);
98       forumPortlet.setRenderedComponent(UITopics.class);
99       ((UIToolbarPanel)forumPortlet.getChildComponentOfType(UIToolbarPanel.class)).setRendered(true);
100         }
101   }
102   
103   static public class ViewForumsActionListener extends ExoActionListener {
104         public void execute(ExoActionEvent event) throws Exception JavaDoc {
105             UIPosts uiPosts = (UIPosts) event.getComponent() ;
106       UIForumPortlet forumPortlet = (UIForumPortlet)uiPosts.getAncestorOfType(UIForumPortlet.class);
107       forumPortlet.addHistoryElement(uiPosts);
108       forumPortlet.setRenderedComponent(UIViewCategories.class);
109       ((UIToolbarPanel)forumPortlet.getChildComponentOfType(UIToolbarPanel.class)).setRendered(true);
110         }
111   }
112   
113   static public class NewTopicActionListener extends ExoActionListener {
114         public void execute(ExoActionEvent event) throws Exception JavaDoc {
115             UIPosts uiPosts = (UIPosts) event.getComponent() ;
116             UITopics uiTopics = (UITopics) uiPosts.getSibling(UITopics.class) ;
117         Forum forum = uiTopics.getForum() ;
118         UIPostForm uiForm = (UIPostForm) uiPosts.getSibling(UIPostForm.class) ;
119         uiForm.setNewTopicInfo(forum) ;
120       UIForumPortlet forumPortlet = (UIForumPortlet)uiPosts.getAncestorOfType(UIForumPortlet.class);
121       forumPortlet.addHistoryElement(uiPosts);
122       forumPortlet.setRenderedComponent(UIPostForm.class);
123       ((UIToolbarPanel)forumPortlet.getChildComponentOfType(UIToolbarPanel.class)).setRendered(true);
124         }
125   }
126   
127   static public class QuotePostActionListener extends ExoActionListener {
128         public void execute(ExoActionEvent event) throws Exception JavaDoc {
129             UIPosts uiPosts = (UIPosts) event.getComponent() ;
130             String JavaDoc postId = event.getParameter("postId") ;
131       Post post = uiPosts.service_.getPost(postId) ;
132       UIPostForm uiForm = (UIPostForm) uiPosts.getSibling(UIPostForm.class) ;
133       uiForm.setQuotePostInfo(uiPosts.topic_, post) ;
134       UIForumPortlet forumPortlet = (UIForumPortlet)uiPosts.getAncestorOfType(UIForumPortlet.class);
135       forumPortlet.addHistoryElement(uiPosts);
136       forumPortlet.setRenderedComponent(UIPostForm.class);
137       ((UIToolbarPanel)forumPortlet.getChildComponentOfType(UIToolbarPanel.class)).setRendered(true);
138         }
139   }
140   
141   static public class EditPostActionListener extends ExoActionListener {
142         public void execute(ExoActionEvent event) throws Exception JavaDoc {
143             UIPosts uiPosts = (UIPosts) event.getComponent() ;
144             String JavaDoc postId = event.getParameter("postId") ;
145       Post post = uiPosts.service_.getPost(postId) ;
146       UIPostForm uiForm = (UIPostForm) uiPosts.getSibling(UIPostForm.class) ;
147       uiForm.setEditPostInfo(uiPosts.topic_, post) ;
148       UIForumPortlet forumPortlet = (UIForumPortlet)uiPosts.getAncestorOfType(UIForumPortlet.class);
149       forumPortlet.addHistoryElement(uiPosts);
150       forumPortlet.setRenderedComponent(UIPostForm.class);
151       ((UIToolbarPanel)forumPortlet.getChildComponentOfType(UIToolbarPanel.class)).setRendered(true);
152         }
153   }
154   
155   static public class ReplyActionListener extends ExoActionListener {
156         public void execute(ExoActionEvent event) throws Exception JavaDoc {
157             UIPosts uiPosts = (UIPosts) event.getComponent() ;
158             UIPostForm uiForm = (UIPostForm) uiPosts.getSibling(UIPostForm.class) ;
159         uiForm.setNewPostInfo(uiPosts.topic_) ;
160       UIForumPortlet forumPortlet = (UIForumPortlet)uiPosts.getAncestorOfType(UIForumPortlet.class);
161       forumPortlet.addHistoryElement(uiPosts);
162       forumPortlet.setRenderedComponent(UIPostForm.class);
163       ((UIToolbarPanel)forumPortlet.getChildComponentOfType(UIToolbarPanel.class)).setRendered(true);
164         }
165   }
166 }
Popular Tags