1 5 package org.exoplatform.portlets.communication.forum.component; 6 7 import java.io.IOException ; 8 import java.util.List ; 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 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 { 30 super() ; 31 setId("UIViewCategories") ; 32 service_ = service ; 33 lastModifiedTime_ = service.getLastModifiedTime() ; 34 buildTree() ; 35 } 36 37 private void buildTree() throws Exception { 38 getChildren().clear() ; 39 getRows().clear() ; 40 List 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 { 56 if(lastModifiedTime_ < service_.getLastModifiedTime()) { 57 try { 58 buildTree(); 59 } catch (Exception ex) { 60 log_.error("Error: " , ex) ; 61 } 62 } 63 super.encodeBegin(context) ; 64 } 65 66 } | Popular Tags |