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.FacesException; 23 import javax.faces.component.UIOutput; 24 import javax.faces.context.FacesContext; 25 import javax.faces.convert.Converter; 26 import javax.faces.el.ValueBinding; 27 28 import org.alfresco.service.cmr.dictionary.AssociationDefinition; 29 import org.alfresco.web.app.Application; 30 import org.alfresco.web.bean.repository.DataDictionary; 31 import org.alfresco.web.bean.repository.Node; 32 import org.alfresco.web.ui.common.Utils; 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 import org.springframework.web.jsf.FacesContextUtils; 36 37 42 public class UIChildAssociation extends PropertySheetItem 43 { 44 private static final String MSG_ERROR_CHILD_ASSOC = "error_child_association"; 45 private static final String MSG_ERROR_NOT_CHILD_ASSOC = "error_not_child_association"; 46 47 private static Log logger = LogFactory.getLog(UIChildAssociation.class); 48 49 52 public UIChildAssociation() 53 { 54 setRendererType("org.alfresco.faces.ChildAssociationRenderer"); 56 } 57 58 61 public String getFamily() 62 { 63 return "org.alfresco.faces.ChildAssociation"; 64 } 65 66 69 protected String getIncorrectParentMsg() 70 { 71 return "The childAssociation component must be nested within a property sheet component"; 72 } 73 74 77 protected void generateItem(FacesContext context, Node node, String var) throws IOException 78 { 79 String associationName = (String )getName(); 80 81 DataDictionary dd = (DataDictionary)FacesContextUtils.getRequiredWebApplicationContext( 83 context).getBean(Application.BEAN_DATA_DICTIONARY); 84 AssociationDefinition assocDef = dd.getAssociationDefinition(node, associationName); 85 86 if (assocDef == null) 87 { 88 logger.warn("Failed to find child association definition for association '" + associationName + "'"); 89 90 String msg = MessageFormat.format(Application.getMessage(context, MSG_ERROR_CHILD_ASSOC), new Object [] {associationName}); 92 Utils.addErrorMessage(msg); 93 } 94 else 95 { 96 if (assocDef.isChild() == false) 99 { 100 String msg = MessageFormat.format(Application.getMessage(context, MSG_ERROR_NOT_CHILD_ASSOC), new Object [] {associationName}); 101 Utils.addErrorMessage(msg); 102 } 103 else 104 { 105 String displayLabel = (String )getDisplayLabel(); 106 if (displayLabel == null) 107 { 108 displayLabel = assocDef.getTitle(); 110 111 if (displayLabel == null) 113 { 114 displayLabel = assocDef.getName().getLocalName(); 115 } 116 } 117 118 generateLabel(context, displayLabel); 120 generateControl(context, assocDef, var); 121 } 122 } 123 } 124 125 134 private void generateControl(FacesContext context, AssociationDefinition assocDef, 135 String varName) 136 { 137 UIPropertySheet propSheet = (UIPropertySheet)this.getParent(); 138 ValueBinding vb = context.getApplication().createValueBinding("#{" + varName + "}"); 139 140 UIChildAssociationEditor control = (UIChildAssociationEditor)context. 141 getApplication().createComponent("org.alfresco.faces.ChildAssociationEditor"); 142 control.setAssociationName(assocDef.getName().toString()); 143 144 control.setId(context.getViewRoot().createUniqueId()); 146 control.setValueBinding("value", vb); 147 148 if (propSheet.getMode().equalsIgnoreCase(UIPropertySheet.VIEW_MODE) || isReadOnly() || assocDef.isProtected()) 150 { 151 control.setDisabled(true); 152 } 153 154 this.getChildren().add(control); 156 } 157 } 158 | Popular Tags |