| 1 17 package org.alfresco.web.ui.repo.component.property; 18 19 import java.io.IOException ; 20 import java.text.MessageFormat ; 21 22 import javax.faces.component.NamingContainer; 23 import javax.faces.component.UIComponent; 24 import javax.faces.component.UIOutput; 25 import javax.faces.component.UIPanel; 26 import javax.faces.context.FacesContext; 27 import javax.faces.el.ValueBinding; 28 29 import org.alfresco.service.cmr.dictionary.PropertyDefinition; 30 import org.alfresco.web.app.Application; 31 import org.alfresco.web.bean.repository.DataDictionary; 32 import org.alfresco.web.bean.repository.Node; 33 import org.alfresco.web.ui.common.Utils; 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 import org.springframework.web.jsf.FacesContextUtils; 37 38 43 public abstract class PropertySheetItem extends UIPanel implements NamingContainer 44 { 45 private static Log logger = LogFactory.getLog(PropertySheetItem.class); 46 47 protected String name; 48 protected String displayLabel; 49 protected String converter; 50 protected Boolean readOnly; 51 52 55 public void encodeBegin(FacesContext context) throws IOException  56 { 57 UIComponent parent = this.getParent(); 59 if ((parent instanceof UIPropertySheet) == false) 60 { 61 throw new IllegalStateException (getIncorrectParentMsg()); 62 } 63 64 int howManyKids = getChildren().size(); 66 if (howManyKids == 0) 67 { 68 UIPropertySheet propSheet = (UIPropertySheet)parent; 69 generateItem(context, propSheet.getNode(), propSheet.getVar()); 70 } 71 72 super.encodeBegin(context); 73 } 74 75 78 public String getDisplayLabel() 79 { 80 if (this.displayLabel == null) 81 { 82 ValueBinding vb = getValueBinding("displayLabel"); 83 if (vb != null) 84 { 85 this.displayLabel = (String )vb.getValue(getFacesContext()); 86 } 87 } 88 89 return this.displayLabel; 90 } 91 92 95 public void setDisplayLabel(String displayLabel) 96 { 97 this.displayLabel = displayLabel; 98 } 99 100 103 public String getName() 104 { 105 if (this.name == null) 106 { 107 ValueBinding vb = getValueBinding("name"); 108 if (vb != null) 109 { 110 this.name = (String )vb.getValue(getFacesContext()); 111 } 112 } 113 114 return this.name; 115 } 116 117 120 public void setName(String name) 121 { 122 this.name = name; 123 } 124 125 128 public String getConverter() 129 { 130 if (this.converter == null) 131 { 132 ValueBinding vb = getValueBinding("converter"); 133 if (vb != null) 134 { 135 this.converter = (String )vb.getValue(getFacesContext()); 136 } 137 } 138 139 return this.converter; 140 } 141 142 145 public void setConverter(String converter) 146 { 147 this.converter = converter; 148 } 149 150 153 public boolean isReadOnly() 154 { 155 if (this.readOnly == null) 156 { 157 ValueBinding vb = getValueBinding("readOnly"); 158 if (vb != null) 159 { 160 this.readOnly = (Boolean )vb.getValue(getFacesContext()); 161 } 162 } 163 164 if (this.readOnly == null) 165 { 166 this.readOnly = Boolean.FALSE; 167 } 168 169 return this.readOnly; 170 } 171 172 175 public void setReadOnly(boolean readOnly) 176 { 177 this.readOnly = readOnly; 178 } 179 180 183 public void restoreState(FacesContext context, Object state) 184 { 185 Object values[] = (Object [])state; 186 super.restoreState(context, values[0]); 188 this.name = (String )values[1]; 189 this.displayLabel = (String )values[2]; 190 this.readOnly = (Boolean )values[3]; 191 this.converter = (String )values[4]; 192 } 193 194 197 public Object saveState(FacesContext context) 198 { 199 Object values[] = new Object [5]; 200 values[0] = super.saveState(context); 202 values[1] = this.name; 203 values[2] = this.displayLabel; 204 values[3] = this.readOnly; 205 values[4] = this.converter; 206 return (values); 207 } 208 209 216 protected abstract void generateItem(FacesContext context, Node node, String var) 217 throws IOException ; 218 219 225 protected abstract String getIncorrectParentMsg(); 226 227 234 protected void generateLabel(FacesContext context, String displayLabel) 235 { 236 UIOutput label = (UIOutput)context.getApplication(). 237 createComponent("javax.faces.Output"); 238 label.setId(context.getViewRoot().createUniqueId()); 239 label.setRendererType("javax.faces.Text"); 240 label.setValue(displayLabel + ": "); 241 this.getChildren().add(label); 242 243 if (logger.isDebugEnabled()) 244 logger.debug("Created label " + label.getClientId(context) + 245 " for '" + displayLabel + "' and added it to component " + this); 246 } 247 } 248 | Popular Tags |