private static FieldControl CreateFieldControlByHint(string hint) { FieldControl control = null; var designator = hint.Split(new char[] { ':' }); if (designator.Count() != 2) { Logger.WriteWarning(string.Concat("Malformed field control hint: ", hint, ", falling back to default.")); return(null); } var namespaces = from TagPrefixInfo tag in TagPrefixInfos where tag.TagPrefix.Equals(designator[0], StringComparison.InvariantCultureIgnoreCase) select tag.Namespace; var types = namespaces.Select(ns => TypeHandler.GetType(string.Concat(ns, ".", designator[1]))).Where(t => t != null); if (types.Count() > 0) { control = (FieldControl)Activator.CreateInstance(types.First()); } if (control == null) { Logger.WriteWarning(string.Concat("Failed to instantiate field control by hint: ", hint, ", falling back to default.")); } return(control); }
private static FieldControl CreateDefaultLongTextControl(LongTextFieldSetting longTextSetting) { Type controlType = null; FieldControl control = null; if (longTextSetting != null) { if (longTextSetting.ControlHint == "control:ChoiceOptionEditor") { controlType = typeof(ChoiceOptionEditor); } else { switch (longTextSetting.TextType) { case TextType.RichText: controlType = typeof(RichText); break; case TextType.AdvancedRichText: controlType = typeof(RichText); break; default: controlType = typeof(LongText); break; } } control = (FieldControl)Activator.CreateInstance(controlType); } return(control); }
private static FieldControl CreateFieldControlByHint(string hint) { FieldControl control = null; var designator = hint.Split(new char[] { ':' }); if (designator.Count() != 2) { SnLog.WriteWarning($"Malformed field control hint: {hint}, falling back to default."); return(null); } var namespaces = from TagPrefixInfo tag in TagPrefixInfos where tag.TagPrefix.Equals(designator[0], StringComparison.InvariantCultureIgnoreCase) select tag.Namespace; var controlType = namespaces .Select(ns => TypeResolver.GetType(string.Concat(ns, ".", designator[1]), false)) .FirstOrDefault(t => t != null); if (controlType != null) { control = (FieldControl)Activator.CreateInstance(controlType); } if (control == null) { SnLog.WriteWarning($"Failed to instantiate field control by hint: {hint}, falling back to default."); } return(control); }
private static FieldControl CreateDefaultDateTimeControl(DateTimeFieldSetting dateTimeFieldSetting) { Type controlType = null; FieldControl control = null; controlType = typeof(DatePicker); control = (FieldControl)Activator.CreateInstance(controlType); return(control); }
public static FieldControl CreateDefaultFieldControl(Field field) { FieldControl control = null; var choiceSetting = field.FieldSetting as ChoiceFieldSetting; var longTextSetting = field.FieldSetting as LongTextFieldSetting; var dateTimeFieldSetting = field.FieldSetting as DateTimeFieldSetting; string hint = field.FieldSetting.ControlHint; if (!string.IsNullOrEmpty(hint)) { control = CreateFieldControlByHint(hint); } //choice field? else if (choiceSetting != null) { control = CreateDefaultChoiceControl(choiceSetting); } //longtext field? else if (longTextSetting != null) { control = CreateDefaultLongTextControl(longTextSetting); } //datetime field? else if (dateTimeFieldSetting != null) { control = CreateDefaultDateTimeControl(dateTimeFieldSetting); } //generic way, also a fallback logic if we don't have a field control by now if (control == null) { Type controlType = null; if (!ControlTable.TryGetValue(field.FieldSetting.ShortName, out controlType)) { throw new ApplicationException(String.Concat("Cannot resolve the generic field control by '", field.GetType().FullName, "'")); } control = (FieldControl)Activator.CreateInstance(controlType); } if (control == null) { throw new ApplicationException(string.Concat("Failed to instantiate a field control for field ", field.Name)); } control.FieldName = field.Name; control.DoAutoConfigure(field.FieldSetting); return(control); }
private void SetFieldInControl(FieldControl fieldControl) { Field field = null; if (!this.Content.Fields.TryGetValue(fieldControl.FieldName, out field)) throw new ApplicationException(String.Concat("ContentType '", this.Content.ContentHandler.Name, "' does not contain Field: ", fieldControl.FieldName)); fieldControl.Field = field; }
internal void RegisterFieldControl(FieldControl fieldControl) { SetFieldInControl(fieldControl); this.FieldControls.Add(fieldControl); }