KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portal > faces > component > UIBody


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.portal.faces.component;
6
7 import java.util.List JavaDoc;
8 import javax.faces.component.UIComponent;
9 import org.exoplatform.services.portal.model.*;
10 import org.exoplatform.services.portal.skin.SkinConfigService;
11 import org.exoplatform.services.portal.skin.model.Style;
12 /**
13  * Fri, May 30, 2003 @
14  * @author : Mestrallet Benjamin
15  * @email: benjmestrallet@users.sourceforge.net
16  * @author: Tuan Nguyen
17  * @email: tuan08@users.sourceforge.net
18  * @version: $Id: UIBody.java,v 1.8 2004/09/27 18:25:51 tuan08 Exp $
19  */

20 public class UIBody extends UIBasicComponent {
21     public static final String JavaDoc COMPONENT_ID = "UIBody";
22   public static final String JavaDoc DEFAULT_RENDERER = "ChildrenRenderer";
23   
24   private Body componentModel_ ;
25   private UIComponent uiBodyComponent_ ;
26   private UIComponent uiLastBodyComponent_ ;
27   
28   public UIBody(Body config, String JavaDoc defaultStyle) {
29     componentModel_ = config ;
30     initBasicComponent(config, defaultStyle) ;
31     setId(COMPONENT_ID) ;
32   }
33   
34   protected String JavaDoc getIdPrefix() { return "rc" ; }
35   //public String getFamily() { return "org.exoplatform.portal.faces.component.UIBody" ; }
36
protected String JavaDoc getSkinName() { return "default" ; }
37   protected String JavaDoc getDefaultRendererType() { return DEFAULT_RENDERER ; }
38   protected Style getDecoratorStyle(SkinConfigService service, String JavaDoc renderer, String JavaDoc style) {
39     return null ;
40   }
41
42   public Component getComponentModel() { return componentModel_ ; }
43   public Body getEditableBodyModel() {
44     if(!modified_) {
45         componentModel_ = (Body)componentModel_.softCloneObject() ;
46     }
47     return componentModel_ ;
48   }
49   
50   public void setComponentMode(int mode) {
51     mode_ = mode ;
52   }
53   
54   public void setBodyMode(int mode) {
55     List JavaDoc children = getChildren() ;
56     for (int i = 0; i < children.size(); i++ ) {
57         Object JavaDoc o = children.get(i) ;
58         if(o instanceof UIBasicComponent) {
59             UIBasicComponent uiChild = (UIBasicComponent) o ;
60             uiChild.setComponentMode(mode) ;
61         }
62     }
63   }
64   
65   public UIComponent getBodyComponent() { return uiBodyComponent_ ; }
66   public void setBodyComponent(UIComponent component) {
67     uiBodyComponent_ = component ;
68     List JavaDoc children = getChildren() ;
69     if(children.size() > 0) {
70       uiLastBodyComponent_ = (UIComponent) children.remove(0);
71     }
72     children.add(component) ;
73     boolean renderSibling = true ;
74     if (component instanceof UIPage) {
75       UIPage uiPage = (UIPage) component ;
76       if(Page.MAXIMIZE_STATE.equals(uiPage.getPageModel().getState())) {
77         renderSibling = false ;
78       }
79     } else {
80       renderSibling = false ;
81     }
82     
83     List JavaDoc siblings = getParent().getChildren() ;
84     for (int i = 0; i < siblings.size() ; i++) {
85       UIComponent uiSibling = (UIComponent) siblings.get(i) ;
86       uiSibling.setRendered(renderSibling) ;
87     }
88     this.setRendered(true) ;
89   }
90
91   public UIComponent getLastBodyComponent() { return uiLastBodyComponent_ ; }
92   public void setLastBodyComponent() {
93     if(uiLastBodyComponent_ != null) {
94       setBodyComponent(uiLastBodyComponent_) ;
95     }
96   }
97   
98   
99   public void initDefaultBodyComponent() {
100     UIPortal uiPortal = (UIPortal) getAncestorOfType(UIPortal.class) ;
101     if(Body.PAGE_NODE_TYPE.equals(componentModel_.getComponentType())) {
102       Node selectedNode = uiPortal.getSelectedNode() ;
103       Node selectNode = selectedNode.findNode(componentModel_.getComponentId()) ;
104       if(selectNode == null) selectNode = selectedNode ;
105       uiPortal.setSelectedNode(selectNode) ;
106     }
107   }
108   
109   public void buildTreeModel(Container parent) {
110     parent.getChildren().add(componentModel_) ;
111   }
112 }
Popular Tags