1 5 package org.exoplatform.portal.faces.component; 6 7 import java.util.List ; 8 import java.util.ResourceBundle ; 9 import javax.faces.context.FacesContext; 10 import org.exoplatform.Constants; 11 import org.exoplatform.commons.utils.ExpressionUtil; 12 import org.exoplatform.container.SessionContainer; 13 import org.exoplatform.portal.PortalConstants; 14 import org.exoplatform.portal.faces.listener.container.AddContainerActionListener; 15 import org.exoplatform.portal.faces.listener.container.AddPortletActionListener; 16 import org.exoplatform.portal.faces.listener.container.ChangeTabActionListener; 17 import org.exoplatform.portal.faces.listener.container.PlaceBodyActionListener; 18 import org.exoplatform.portal.faces.listener.share.DeleteActionListener; 19 import org.exoplatform.portal.faces.listener.share.EditPropertiesActionListener; 20 import org.exoplatform.portal.faces.listener.share.MoveActionListener; 21 import org.exoplatform.portal.session.RequestInfo; 22 import org.exoplatform.services.portal.model.Body; 23 import org.exoplatform.services.portal.model.Component; 24 import org.exoplatform.services.portal.model.Container; 25 import org.exoplatform.services.portal.model.Portlet; 26 import org.exoplatform.services.portal.skin.SkinConfigService; 27 import org.exoplatform.services.portal.skin.model.Style; 28 29 37 public class UIContainer extends UIBasicComponent { 38 final static public String DEFAULT_CONTAINER_RENDERER = "ContainerRowRenderer" ; 39 40 private Container componentModel_ ; 41 private int selectedComponent_ = 0; 42 protected String displayTitle_ ; 43 44 public UIContainer() { 45 registerListeners() ; 46 } 47 48 public UIContainer(Container container) { 49 componentModel_ = container ; 50 initBasicComponent(componentModel_, "default") ; 51 setComponentMode(UIBasicComponent.COMPONENT_EDIT_MODE) ; 52 registerListeners() ; 53 } 54 55 public UIContainer(Container config, String defaultStyle, String configurationSource) { 56 componentModel_ = config ; 57 initBasicComponent(config, defaultStyle) ; 58 List childrenConfig = config.getChildren() ; 59 initChildren(childrenConfig, configurationSource) ; 60 registerListeners() ; 61 } 62 63 private void registerListeners() { 64 addActionListener(EditPropertiesActionListener.class, PortalConstants.EDIT_ACTION) ; 65 addActionListener(DeleteActionListener.class, PortalConstants.DELETE_ACTION) ; 66 addActionListener(MoveActionListener.class, PortalConstants.MOVE_UP_ACTION) ; 67 addActionListener(MoveActionListener.class, PortalConstants.MOVE_DOWN_ACTION) ; 68 69 addActionListener(AddContainerActionListener.class, PortalConstants.ADD_CONTAINER_ACTION) ; 70 addActionListener(AddPortletActionListener.class, PortalConstants.ADD_PORTLET_ACTION) ; 71 addActionListener(PlaceBodyActionListener.class, PortalConstants.PLACE_BODY_ACTION) ; 72 addActionListener(ChangeTabActionListener.class, PortalConstants.CHANGE_CONTAINER_TAB_ACTION) ; 73 } 74 75 final protected void initChildren(List childrenConfig, String configurationSource) { 76 List children = getChildren() ; 77 for (int i = 0; i < childrenConfig.size() ; i++) { 78 Object childConfig = childrenConfig.get(i) ; 79 if (childConfig instanceof Portlet) { 80 Portlet portletConfig = (Portlet) childConfig ; 81 UIPortlet uiPortlet = 82 new UIPortlet(portletConfig, getDecorator(), configurationSource) ; 83 children.add(uiPortlet) ; 84 } else if (childConfig instanceof Container) { 85 Container containerConfig = (Container) childConfig ; 86 UIContainer uiContainer = 87 new UIContainer(containerConfig, getDecorator(), configurationSource) ; 88 children.add(uiContainer) ; 89 } else if (childConfig instanceof Body) { 90 Body bodyConfig = (Body) childConfig ; 91 UIBody uiBody = new UIBody(bodyConfig, getDecorator()) ; 92 children.add(uiBody) ; 93 } 94 } 95 } 96 97 public Component getComponentModel() { return componentModel_ ; } 98 public Container getContainerModel() { return componentModel_ ; } 99 public Container getEditableContainerModel() { 100 if(!modified_) { 101 componentModel_ = (Container)componentModel_.softCloneObject() ; 102 } 103 return componentModel_ ; 104 } 105 106 public String getTitle() { return displayTitle_ ; } 107 108 protected String getIdPrefix() { return "c" ; } 109 public String getFamily() { return "org.exoplatform.portal.faces.component.UIContainer" ; } 110 protected String getSkinName() { return "default" ; } 111 protected String getDefaultRendererType() { return DEFAULT_CONTAINER_RENDERER ; } 112 protected Style getDecoratorStyle(SkinConfigService service, String renderer, String style) { 113 return service.getContainerDecoratorStyle(renderer, style) ; 114 } 115 116 public void processDecodes(FacesContext context) { 117 decode(context) ; 118 } 119 120 public void buildTreeModel(Container parent) { 121 componentModel_.getChildren().clear() ; 122 List uichildren = getChildren() ; 123 for(int i = 0; i < uichildren.size(); i++) { 124 UIBasicComponent uiChild =(UIBasicComponent) uichildren.get(i) ; 125 uiChild.buildTreeModel(componentModel_) ; 126 } 127 if(parent != null) parent.getChildren().add(componentModel_) ; 128 } 129 130 public int getSelectedComponent() {return selectedComponent_;} 131 public void setSelectedComponent(int selectedComponent) { 132 selectedComponent_ = selectedComponent; 133 } 134 135 public void changeLocale(ResourceBundle res) { 136 String title = componentModel_.getTitle() ; 137 if(title == null) { 138 displayTitle_ = getId() ; 139 } else { 140 displayTitle_ = ExpressionUtil.getExpressionValue(res, componentModel_.getTitle()) ; 141 } 142 } 143 144 145 public String getBaseURL() { 146 if (baseURL_ == null) { 147 RequestInfo rinfo = (RequestInfo)SessionContainer.getComponent(RequestInfo.class); 148 if(getAncestorOfType(UIPage.class) == null) { 149 baseURL_ = rinfo.getOwnerURI(); 150 baseURL_ += "?" + Constants.COMPONENT_PARAMETER + "=" + getId() ; 151 } else { 152 baseURL_ = rinfo.getPageURI(); 153 baseURL_ += "?" + Constants.COMPONENT_PARAMETER + "=" + getId() ; 154 } 155 } 156 return baseURL_ ; 157 } 158 } | Popular Tags |