KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
8 import org.exoplatform.faces.application.ExoFacesMessage;
9 import org.exoplatform.faces.core.component.InformationProvider;
10 import org.exoplatform.faces.core.component.UIGrid;
11 import org.exoplatform.faces.core.component.model.*;
12 import org.exoplatform.faces.core.event.ExoActionEvent;
13 import org.exoplatform.faces.core.event.ExoActionListener;
14 import org.exoplatform.services.communication.forum.Category;
15 import org.exoplatform.services.communication.forum.Forum;
16 import org.exoplatform.services.communication.forum.ForumService;
17
18 /**
19  * Sat, Jan 03, 2004 @ 11:16
20  * @author: Tuan Nguyen
21  * @email: tuan08@users.sourceforge.net
22  * @version: $Id: UICategory.java,v 1.15 2004/10/20 18:46:31 benjmestrallet Exp $
23  */

24 public class UICategory extends UIGrid {
25   private static String JavaDoc FORUM_ID_PARAM = "forum" ;
26   private static Parameter VIEW_TOPICS = new Parameter(ACTION, "viewTopics") ;
27   private static Parameter[] selectCategoryParams = { new Parameter(ACTION, "selectCategory")} ;
28   
29   private ForumService service_ ;
30   
31   public UICategory(ForumService service, Category category) throws Exception JavaDoc {
32     super() ;
33     String JavaDoc id = "category_" + category.getId() ;
34     setId(id) ;
35     setClazz("UICategory");
36     service_ = service ;
37     List JavaDoc forums = service.getForums(category.getId()) ;
38     String JavaDoc forumIcon = "#{UICategory.img.forum-icon}" ;
39     Parameter forumIdParam = new Parameter(FORUM_ID_PARAM, "") ;
40     Parameter[] viewTopicsParams = {VIEW_TOPICS, forumIdParam} ;
41     add(new Row().
42         add(new ListComponentCell().
43             add(new Button(category.getCategoryName(), selectCategoryParams)).
44             addHeight("30").addColspan("5").addClazz("left-indent"))) ;
45     add(new HeaderRow().
46         add(new Cell("#{UICategory.header.forum}").
47             addWidth("*").addColspan("2")).
48         add(new Cell("#{UICategory.header.topics}").addWidth("75")).
49         add(new Cell("#{UICategory.header.posts}").addWidth("75")).
50         add(new Cell("#{UICategory.header.last-post}").addWidth("200")));
51     
52     for(int j = 0 ; j < forums.size(); j++) {
53       Forum forum = (Forum) forums.get(j) ;
54       forumIdParam.setValue(forum.getId()) ;
55       String JavaDoc lastPostBy = forum.getLastPostBy() ;
56       if(lastPostBy == null) lastPostBy = "guest" ;
57       add(new Row().
58           add(new Cell(forumIcon).addWidth("30")).
59           add(new ListComponentCell().
60               add(new Button(forum.getForumName(), viewTopicsParams)).
61               add("<br/>").add(forum.getDescription()).addClazz("left-indent")).
62           add(new Cell(forum.getTopicCount())).
63           add(new Cell(forum.getPostCount())).
64           add(new Cell(forum.getLastPostDate() + "<br/>" + lastPostBy)));
65     }
66     addActionListener(SelectCategoryActionListener.class, "selectCategory") ;
67     addActionListener(ViewTopicsActionListener.class, "viewTopics") ;
68   }
69   
70   static public class SelectCategoryActionListener extends ExoActionListener {
71         public void execute(ExoActionEvent event) throws Exception JavaDoc {
72             UICategory uiCategory = (UICategory) event.getComponent() ;
73             List JavaDoc rows = uiCategory.getRows() ;
74         for (int i = 1 ; i < rows.size(); i++) {
75             Row row = (Row)rows.get(i);
76           row.setVisible(!row.isVisible()) ;
77         }
78         }
79   }
80   
81   static public class ViewTopicsActionListener extends ExoActionListener {
82         public void execute(ExoActionEvent event) throws Exception JavaDoc {
83             UICategory uiCategory = (UICategory) event.getComponent() ;
84             String JavaDoc forumId = event.getParameter(FORUM_ID_PARAM) ;
85       Forum forum = uiCategory.service_.getForum(forumId) ;
86       UIForumPortlet uiController =
87         (UIForumPortlet)uiCategory.getAncestorOfType(UIForumPortlet.class) ;
88       UITopics uiTopics = (UITopics) uiController.getChildComponentOfType(UITopics.class) ;
89       if(uiTopics.setForum(forum)) {
90         uiController.addHistoryElement(uiCategory.getParent());
91         uiController.setRenderedComponent(UITopics.class) ;
92         ((UIToolbarPanel)uiController.getChildComponentOfType(UIToolbarPanel.class)).setRendered(true);
93       } else {
94         InformationProvider iprovider = findInformationProvider(uiCategory) ;
95         iprovider.addMessage(new ExoFacesMessage("#{UICategory.msg.no-view-forum-role}"));
96       }
97         }
98   }
99 }
Popular Tags