1 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 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 REPLY = "reply"; 36 private static final String 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 { 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 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 { 70 forum_ = forum ; 71 topic_ = topic ; 72 uiPageIterator_.setPageList(service_.getPosts(topic_.getId())) ; 73 } 74 75 public void reload() throws Exception { 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 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 { 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 { 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 { 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 { 129 UIPosts uiPosts = (UIPosts) event.getComponent() ; 130 String 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 { 143 UIPosts uiPosts = (UIPosts) event.getComponent() ; 144 String 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 { 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 |