public virtual ValueEditor GetValueEditor(DataType?type = null) { ValueEditor result = DefaultEditor; type = type ?? DataType; if (result == null) { switch (type.Value) { case DataType.Date: case DataType.Time: case DataType.DateTime: result = new DateTimeValueEditor(); break; case DataType.Bool: result = new CustomListValueEditor("BooleanValues", "MENU"); break; default: result = new TextValueEditor(); break; } } if (result is DateTimeValueEditor) { ((DateTimeValueEditor)result).SubType = type.Value; } return(result); }
/// <summary> /// Copies all attribute's properties from another entity attribute /// </summary> /// <param name="attr">An EntityAttr object to copy from.</param> public virtual void CopyFrom(MetaEntityAttr attr) { Caption = attr.Caption; DataType = attr.DataType; Description = attr.Description; Expr = attr.Expr; ID = attr.ID; Kind = attr.Kind; _lookupAttrId = attr._lookupAttrId; _defaultEditor = attr.DefaultEditor; Size = attr.Size; UserData = attr.UserData; IsNullable = attr.IsNullable; IsPrimaryKey = attr.IsPrimaryKey; IsForeignKey = attr.IsForeignKey; IsEditable = attr.IsEditable; IsVisible = attr.IsVisible; }
/// <summary> /// Copies all attribute's properties from another entity attribute /// </summary> /// <param name="attr">An EntityAttr object to copy from.</param> public virtual void CopyFrom(MetaEntityAttr attr) { Caption = attr.Caption; DataType = attr.DataType; Description = attr.Description; Expr = attr.Expr; Id = attr.Id; Kind = attr.Kind; _lookupAttrId = attr._lookupAttrId; _defaultEditor = attr.DefaultEditor; Size = attr.Size; UserData = attr.UserData; IsNullable = attr.IsNullable; IsPrimaryKey = attr.IsPrimaryKey; IsForeignKey = attr.IsForeignKey; IsEditable = attr.IsEditable; ShowInLookup = attr.ShowInLookup; ShowOnView = attr.ShowOnView; ShowOnEdit = attr.ShowOnEdit; ShowOnCreate = attr.ShowOnCreate; }
/// <summary> /// Creates a value editor based on the value of "tag" property and reads the content of the newly created editor from JSON (asynchronous way). /// </summary> /// <param name="reader">The reader.</param> /// <param name="ct">The cancellation token.</param> /// <returns>Task<ValueEditor>.</returns> /// <exception cref="BadJsonFormatException"> /// </exception> public static async Task <ValueEditor> ReadFromJsonAsync(JsonReader reader, CancellationToken ct = default) { if (reader.TokenType != JsonToken.StartObject) { throw new BadJsonFormatException(reader.Path); } var jObject = await JObject.LoadAsync(reader, ct).ConfigureAwait(false); if (!jObject.TryGetValue("tag", out var tagToken)) { throw new BadJsonFormatException(jObject.Path); } var editor = ValueEditor.Create(tagToken.ToString()); var editorReader = jObject.CreateReader(); await editorReader.ReadAsync(ct).ConfigureAwait(false); await editor.ReadContentFromJsonAsync(editorReader, ct).ConfigureAwait(false); return(editor); }
/// <summary> /// Initializes the <see cref="MetaData"/> class. /// Registers the main value editors types. /// </summary> static MetaData() { ValueEditor.RegisterCreator(new BasicValueEditorsCreator()); }
/// <summary> /// Inserts an element into the <see cref="T:System.Collections.ObjectModel.Collection`1"></see> at the specified index. /// </summary> /// <param name="index">The zero-based index at which item should be inserted.</param> /// <param name="item">The object to insert. The value can be null for reference types.</param> protected override void InsertItem(int index, ValueEditor item) { base.InsertItem(index, item); item.Model = Model; }
/// <summary> /// Sets default editor without adding it to model. /// </summary> public void SetDefaultEditorWithoutChecking(ValueEditor editor) { _defaultEditor = editor; }