1 5 package org.exoplatform.portal.faces.component; 6 7 import java.io.IOException ; 8 import java.util.List ; 9 import java.util.ResourceBundle ; 10 import javax.faces.context.FacesContext; 11 import javax.faces.event.AbortProcessingException; 12 import javax.faces.event.ActionListener; 13 import javax.faces.event.FacesEvent; 14 import org.apache.commons.logging.Log; 15 import org.exoplatform.Constants; 16 import org.exoplatform.container.SessionContainer; 17 import org.exoplatform.faces.core.component.UIExoCommand; 18 import org.exoplatform.portal.session.RequestInfo; 19 import org.exoplatform.services.portal.model.Component; 20 import org.exoplatform.services.portal.model.Container; 21 import org.exoplatform.services.portal.skin.SkinConfigService; 22 import org.exoplatform.services.portal.skin.model.Style; 23 29 abstract public class UIBasicComponent extends UIExoCommand { 30 final static public short FLOAT_RIGHT = 0 ; 31 final static public short FLOAT_BOTTOM = 1 ; 32 33 protected static Log log_ = getLog("org.exoplatform.portal.faces") ; 34 final static public int COMPONENT_VIEW_MODE = 1 ; 35 final static public int COMPONENT_EDIT_MODE = 2 ; 36 37 protected String decorator_ ; 38 protected String customizedId_ ; 39 private short float_ ; 40 protected boolean componentAdminRole_ = false ; 41 protected boolean modified_ ; 42 protected int mode_ = COMPONENT_VIEW_MODE ; 43 44 public String getCustomizedId() { return customizedId_ ; } 45 public void setCustomizedId(String id) { customizedId_ = id ; } 46 47 public short getFloat() { return float_ ; } 48 public void setFloat(short val) { float_ = val ;} 49 50 abstract public Component getComponentModel() ; 51 52 final protected void initBasicComponent(Component componentModel, String defaultStyle) { 53 setDecorator(componentModel.getDecorator(), defaultStyle) ; 54 setRendererType(componentModel.getRenderer()) ; 55 setId(componentModel.getId()) ; 56 } 57 58 public void updateChange() { 59 Component model = getComponentModel() ; 60 setDecorator(model.getDecorator(), "default") ; 61 setRendererType(model.getRenderer()) ; 62 } 63 64 public String getDecorator() { return decorator_; } 65 public void setDecorator(String decorator, String defaultDecorator) { 66 if(decorator == null || decorator.length() == 0) { 67 decorator_ = defaultDecorator ; 68 } else { 69 decorator_ = decorator ; 70 } 71 } 72 73 public int getComponentMode() { return mode_ ; } 74 public void setComponentMode(int mode) { 75 mode_ = mode ; 76 List children = getChildren() ; 77 for(int i = 0; i < children.size(); i++) { 78 UIBasicComponent uiChild = (UIBasicComponent) children.get(i) ; 79 uiChild.setComponentMode(mode) ; 80 } 81 } 82 83 public boolean hasComponentAdminRole() { return componentAdminRole_ ; } 84 public void setComponentAdminRole(boolean b) { 85 componentAdminRole_ = b ; 86 List children = getChildren() ; 87 for (int i = 0 ; i < children.size(); i++) { 88 UIBasicComponent uiChild = (UIBasicComponent) children.get(i) ; 89 uiChild.setComponentAdminRole(b) ; 90 } 91 } 92 93 public void setRendererType(String type) { 94 String rendererType = type ; 95 if(type == null || type.length() == 0 || "default".equals(type)) { 96 rendererType = getDefaultRendererType() ; 97 } 98 super.setRendererType(rendererType) ; 99 } 100 101 public boolean getRendersChildren(){ return true; } 102 103 public boolean isComponentModified() { return modified_ ; } 104 public void setComponentModified(boolean b) { 105 modified_ = b ; 106 setComponentDirty(b) ; 107 } 108 109 public void clearComponentModified() { 110 modified_ = false ; 111 List children = getChildren() ; 112 for(int i = 0; i < children.size(); i++) { 113 UIBasicComponent uichild = (UIBasicComponent) children.get(i) ; 114 uichild.clearComponentModified() ; 115 } 116 } 117 118 public void setComponentDirty(boolean b) { 119 UIBasicComponent uiParent = (UIBasicComponent) getParent() ; 120 uiParent.setComponentDirty(b) ; 121 } 122 123 final public void decode(FacesContext context) { 124 getRenderer(context).decode(context, this) ; 125 } 126 127 public void setId(String id) { 128 if (id == null || id.length() == 0) { 129 id = new String (getIdPrefix() + Integer.toString(hashCode())); 130 } else { 131 setCustomizedId(id); 132 } 133 super.setId(id) ; 134 } 135 136 public void removeChild(UIBasicComponent child) { 137 List children = getChildren() ; 138 children.remove(child) ; 139 setComponentModified(true) ; 140 } 141 142 public String getBaseURL() { 143 if (baseURL_ == null) { 144 RequestInfo rinfo = (RequestInfo)SessionContainer.getComponent(RequestInfo.class); 145 baseURL_ = rinfo.getOwnerURI(); 146 baseURL_ += "?" + Constants.COMPONENT_PARAMETER + "=" + getId() ; 147 } 148 return baseURL_ ; 149 } 150 151 public void changeLocale(ResourceBundle res) { } 152 153 abstract protected String getDefaultRendererType() ; 154 abstract protected String getIdPrefix() ; 155 abstract protected Style getDecoratorStyle(SkinConfigService service, String renderer, String style) ; 156 abstract public void buildTreeModel(Container parent) ; 157 158 final public void encodeBegin(FacesContext context) throws IOException { } 159 final public void encodeEnd(FacesContext context) throws IOException { } 160 161 public void broadcast(FacesEvent event) throws AbortProcessingException { 162 ActionListener[] listener = this.getActionListeners() ; 163 for(int i = 0; i < listener.length; i++) { 164 if (event.isAppropriateListener(listener[i])) { 165 event.processListener(listener[i]); 166 } 167 } 168 } 169 } | Popular Tags |