KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
8 import java.util.List JavaDoc;
9 import javax.faces.context.FacesContext;
10 import org.apache.commons.logging.Log;
11 import org.exoplatform.faces.core.component.UIGrid;
12 import org.exoplatform.faces.core.component.model.Cell;
13 import org.exoplatform.faces.core.component.model.ComponentCell;
14 import org.exoplatform.faces.core.component.model.Row;
15 import org.exoplatform.services.communication.forum.Category;
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: UIViewCategories.java,v 1.8 2004/10/20 18:46:31 benjmestrallet Exp $
23  */

24 public class UIViewCategories extends UIGrid {
25   protected static Log log_ = getLog("org.exoplatform.portlets.communication.forum") ;
26   private ForumService service_ ;
27   private long lastModifiedTime_ ;
28   
29   public UIViewCategories(ForumService service) throws Exception JavaDoc {
30     super() ;
31     setId("UIViewCategories") ;
32     service_ = service ;
33     lastModifiedTime_ = service.getLastModifiedTime() ;
34     buildTree() ;
35   }
36   
37   private void buildTree() throws Exception JavaDoc {
38     getChildren().clear() ;
39     getRows().clear() ;
40     List JavaDoc categories = service_.getCategories();
41     if(categories.size() > 0) {
42       for (int i = 0; i < categories.size(); i++) {
43         Category category = (Category) categories.get(i) ;
44         UICategory uiCategory = new UICategory(service_, category) ;
45         add(new Row().
46             add(new ComponentCell(this, uiCategory))) ;
47       }
48     } else {
49       add(new Row().
50           add(new Cell("#{UIViewCategories.msg.no-category}").addColspan("2"))) ;
51     }
52     lastModifiedTime_ = service_.getLastModifiedTime() ;
53   }
54   
55   public void encodeBegin(FacesContext context) throws IOException JavaDoc {
56     if(lastModifiedTime_ < service_.getLastModifiedTime()) {
57       try {
58         buildTree();
59       } catch (Exception JavaDoc ex) {
60         log_.error("Error: " , ex) ;
61       }
62     }
63     super.encodeBegin(context) ;
64   }
65   
66 }
Popular Tags