private static void LocalizeRelatedField(string fieldName, GridColumn column, Entity entity) { var fieldSegments = fieldName.Split('.'); if (fieldSegments.Length == 2) { var mainPropertyName = fieldSegments[0]; var subPropertyName = fieldSegments[1]; var mainLocalizedLabel = GetLocalizedLabel(entity, mainPropertyName + "Id"); var entityType = DynamicDataServiceContext.GetTypeDefinition(entity.PhysicalName); var propertyType = entityType.NavigationProperties().Single(p => p.Name == mainPropertyName).ToEntityType(); var subPropertyEntity = MetadataProvider.Instance.EntiyMetadata.First(e => e.PhysicalName == propertyType.Name); var subLocalizedLabel = GetLocalizedLabel(subPropertyEntity, subPropertyName); var columnMetadata = subPropertyEntity.Attributes.FirstOrDefault(a => a.PhysicalName == subPropertyName); column.Caption = string.Format(Resources.ColumnCaptionFormat, mainLocalizedLabel ?? string.Empty, subLocalizedLabel); if (columnMetadata != null && columnMetadata.OptionSetId != null) { var lookUpEdit = new RepositoryItemLookUpEdit(); lookUpEdit.BindPickList(subPropertyEntity, subPropertyName); column.ColumnEdit = lookUpEdit; } else if (columnMetadata != null && columnMetadata.LogicalName == "MultipleLineText") { var memoEdit = new RepositoryItemMemoEdit(); column.ColumnEdit = memoEdit; } } }
public static void InitColumns(this ColumnView view, string entityName) { var entityMetaSet = MetadataProvider.Instance.EntiyMetadata.First(e => e.PhysicalName == entityName); var columnFieldMappings = GetColumnFieldMapping(entityName); foreach (GridColumn column in view.Columns) { var fieldName = column.FieldName; var mapping = columnFieldMappings.FirstOrDefault(m => m.FieldNameMapping == fieldName); if (mapping != null) { fieldName = mapping.FieldName; } var isComplexField = IsComplexField(fieldName); if (isComplexField) { LocalizeRelatedField(fieldName, column, entityMetaSet); continue; } var columnMetadata = entityMetaSet.Attributes.FirstOrDefault(a => a.PhysicalName == fieldName); if (columnMetadata != null && columnMetadata.OptionSetId != null) { var lookUpEdit = new RepositoryItemLookUpEdit(); lookUpEdit.BindPickList(entityMetaSet, fieldName); column.ColumnEdit = lookUpEdit; } else if (columnMetadata != null && columnMetadata.LogicalName == "MultipleLineText") { var memoEdit = new RepositoryItemMemoEdit(); column.ColumnEdit = memoEdit; } var localizedLabel = GetLocalizedLabel(entityMetaSet, fieldName) ?? GetLocalizedLabel(entityMetaSet, column.Caption); if (!string.IsNullOrEmpty(localizedLabel)) { column.Caption = localizedLabel; } } }
private static void InitColumn(GridColumn column, EntityAttribute attribute) { var isComplexField = attribute.AttributeLookupValues.Any(); if (isComplexField) { LocalizeRelatedField(column, attribute); return; } if (attribute.OptionSetId != null) { var lookUpEdit = new RepositoryItemLookUpEdit(); lookUpEdit.BindPickList(attribute); column.ColumnEdit = lookUpEdit; } else if (attribute.LogicalName == "MultipleLineText") { var memoEdit = new RepositoryItemMemoEdit(); column.ColumnEdit = memoEdit; } var localizedLabel = GetLocalizedLabel(attribute.AttributeId); if (string.IsNullOrEmpty(localizedLabel)) { var captionAttribute = attribute.Entity.Attributes.FirstOrDefault(a => a.PhysicalName == column.Caption); if (captionAttribute != null) { localizedLabel = GetLocalizedLabel(captionAttribute.AttributeId); } } if (!string.IsNullOrEmpty(localizedLabel)) { column.Caption = localizedLabel; } }