1 5 package org.exoplatform.portal.faces.component; 6 7 import java.util.List ; 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 20 public class UIBody extends UIBasicComponent { 21 public static final String COMPONENT_ID = "UIBody"; 22 public static final String DEFAULT_RENDERER = "ChildrenRenderer"; 23 24 private Body componentModel_ ; 25 private UIComponent uiBodyComponent_ ; 26 private UIComponent uiLastBodyComponent_ ; 27 28 public UIBody(Body config, String defaultStyle) { 29 componentModel_ = config ; 30 initBasicComponent(config, defaultStyle) ; 31 setId(COMPONENT_ID) ; 32 } 33 34 protected String getIdPrefix() { return "rc" ; } 35 protected String getSkinName() { return "default" ; } 37 protected String getDefaultRendererType() { return DEFAULT_RENDERER ; } 38 protected Style getDecoratorStyle(SkinConfigService service, String renderer, String 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 children = getChildren() ; 56 for (int i = 0; i < children.size(); i++ ) { 57 Object 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 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 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 |