KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ResourceBundle JavaDoc;
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 /**
30  * Fri, May 30, 2003 @
31  * @author : Mestrallet Benjamin
32  * @email: benjmestrallet@users.sourceforge.net
33  * @author: Tuan Nguyen
34  * @email: tuan08@users.sourceforge.net
35  * @version: $Id: UIContainer.java,v 1.10 2004/11/03 01:19:45 tuan08 Exp $
36  */

37 public class UIContainer extends UIBasicComponent {
38   final static public String JavaDoc DEFAULT_CONTAINER_RENDERER = "ContainerRowRenderer" ;
39   
40     private Container componentModel_ ;
41   private int selectedComponent_ = 0;
42   protected String JavaDoc 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 JavaDoc defaultStyle, String JavaDoc configurationSource) {
56     componentModel_ = config ;
57     initBasicComponent(config, defaultStyle) ;
58     List JavaDoc 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 JavaDoc childrenConfig, String JavaDoc configurationSource) {
76     List JavaDoc children = getChildren() ;
77     for (int i = 0; i < childrenConfig.size() ; i++) {
78       Object JavaDoc 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 JavaDoc getTitle() { return displayTitle_ ; }
107   
108   protected String JavaDoc getIdPrefix() { return "c" ; }
109   public String JavaDoc getFamily() { return "org.exoplatform.portal.faces.component.UIContainer" ; }
110   protected String JavaDoc getSkinName() { return "default" ; }
111   protected String JavaDoc getDefaultRendererType() { return DEFAULT_CONTAINER_RENDERER ; }
112   protected Style getDecoratorStyle(SkinConfigService service, String JavaDoc renderer, String JavaDoc 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 JavaDoc 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 JavaDoc res) {
136     String JavaDoc 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 JavaDoc 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