/// <summary> /// Initializes a new instance of the <see cref="FieldControlTab"/> class. /// </summary> /// <param name="definition"> /// The definition. /// </param> /// <param name="offset"> /// The offset. /// </param> /// <param name="fieldControl"> /// The field control. /// </param> public FieldControlTab(List <object> definition, int offset, FieldControl fieldControl) { this.FieldControl = fieldControl; this.Label = (string)definition[0]; this.Type = (string)definition[1]; var fielddefs = (definition[2] as JArray)?.ToObject <List <object> >(); if (fielddefs == null) { this.AllFields = null; } else { var count = fielddefs.Count; this.AllFields = new List <UPConfigFieldControlField>(count); for (var i = 0; i < count; i++) { var def = (fielddefs[i] as JArray)?.ToObject <List <object> >(); if (def == null) { continue; } this.AllFields.Add(new UPConfigFieldControlField(def, offset + i, this)); } } this.FieldOffset = offset; if (definition.Count > 3) { var attributeDefs = definition[3] as List <List <object> >; if (attributeDefs != null && attributeDefs.Count > 0) { var attributes = new List <object>(attributeDefs.Count); var attributeDictionary = new Dictionary <string, List <ConfigFieldControlTabAttribute> >(attributeDefs.Count); foreach (var attributeDef in attributeDefs) { var attribute = new ConfigFieldControlTabAttribute(attributeDef); attributes.Add(attribute); var arrayForKey = attributeDictionary[attribute.Key]; if (arrayForKey != null) { arrayForKey.Add(attribute); attributeDictionary[attribute.Key] = arrayForKey; } else { attributeDictionary[attribute.Key] = new List <ConfigFieldControlTabAttribute> { attribute }; } } this.attributeDictionary = attributeDictionary; this.attributes = attributes; } } }
/* editModes: New=1, Update=2, Delete=4, View=8, Search=16, List=32 */ /// <summary> /// Values for attribute. /// </summary> /// <param name="attributeKey"> /// The attribute key. /// </param> /// <param name="editMode"> /// The edit mode. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public string ValueForAttribute(string attributeKey, int editMode) { ConfigFieldControlTabAttribute tabAttribute = null; foreach (var attr in this.attributeDictionary[attributeKey]) { if ((attr.EditMode & editMode) != editMode) { continue; } if (tabAttribute == null || attr.EditMode < tabAttribute.EditMode) { tabAttribute = attr; } } return(tabAttribute != null ? tabAttribute.Value : string.Empty); }
/// <summary> /// Values for attribute. /// </summary> /// <param name="attributeKey"> /// The attribute key. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public string ValueForAttribute(string attributeKey) { if (this.attributeDictionary == null) { return(string.Empty); } ConfigFieldControlTabAttribute tabAttribute = null; foreach (var attr in this.attributeDictionary.ValueOrDefault(attributeKey)) { if (tabAttribute == null || attr.EditMode > tabAttribute.EditMode) { tabAttribute = attr; } } return(tabAttribute != null ? tabAttribute.Value : string.Empty); }