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 UIAssociation extends PropertySheetItem 43 { 44 private static final String MSG_ERROR_ASSOC = "error_association"; 45 private static final String MSG_ERROR_NOT_ASSOC = "error_not_association"; 46 47 private static Log logger = LogFactory.getLog(UIAssociation.class); 48 49 52 public UIAssociation() 53 { 54 setRendererType("org.alfresco.faces.AssociationRenderer"); 56 } 57 58 61 public String getFamily() 62 { 63 return "org.alfresco.faces.Association"; 64 } 65 66 69 protected String getIncorrectParentMsg() 70 { 71 return "The association 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 association definition for association '" + associationName + "'"); 89 90 String msg = MessageFormat.format(Application.getMessage(context, MSG_ERROR_ASSOC), new Object [] {associationName}); 93 Utils.addErrorMessage(msg); 94 } 95 else 96 { 97 if (assocDef.isChild()) 100 { 101 String msg = MessageFormat.format(Application.getMessage(context, MSG_ERROR_NOT_ASSOC), new Object [] {associationName}); 102 Utils.addErrorMessage(msg); 103 } 104 else 105 { 106 String displayLabel = (String )getDisplayLabel(); 107 if (displayLabel == null) 108 { 109 displayLabel = assocDef.getTitle(); 111 112 if (displayLabel == null) 114 { 115 displayLabel = assocDef.getName().getLocalName(); 116 } 117 } 118 119 generateLabel(context, displayLabel); 121 generateControl(context, assocDef, var); 122 } 123 } 124 } 125 126 135 private void generateControl(FacesContext context, AssociationDefinition assocDef, 136 String varName) 137 { 138 UIPropertySheet propSheet = (UIPropertySheet)this.getParent(); 139 ValueBinding vb = context.getApplication().createValueBinding("#{" + varName + "}"); 140 141 UIAssociationEditor control = (UIAssociationEditor)context. 142 getApplication().createComponent("org.alfresco.faces.AssociationEditor"); 143 control.setAssociationName(assocDef.getName().toString()); 144 145 control.setId(context.getViewRoot().createUniqueId()); 147 control.setValueBinding("value", vb); 148 149 if (propSheet.getMode().equalsIgnoreCase(UIPropertySheet.VIEW_MODE) || isReadOnly() || assocDef.isProtected()) 151 { 152 control.setDisabled(true); 153 } 154 155 this.getChildren().add(control); 157 } 158 } 159 | Popular Tags |