Merge pull request #330 from telerik/hhristov/data-form-update
RadDataForm EntityProvider is now initialized immediately
This commit is contained in:
Коммит
5feceb7210
|
@ -55,6 +55,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Common\ContainerGeneration\HexItemModelGenerator.cs" />
|
||||
<Compile Include="DataForm\View\Editors\DataFormComboBoxItem.cs" />
|
||||
<Compile Include="DataForm\View\Editors\IEditor.cs" />
|
||||
<Compile Include="DataForm\View\Editors\SegmentedControlCustomEditor.cs" />
|
||||
<Compile Include="DataForm\View\Editors\SliderCustomEditor.cs" />
|
||||
<Compile Include="ListView\Data\ListViewDataView.cs" />
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Telerik.Data.Core;
|
||||
using Telerik.UI.Xaml.Controls.Data.DataForm;
|
||||
using Telerik.UI.Xaml.Controls.Data.DataForm.View;
|
||||
|
@ -8,8 +10,8 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
internal partial class DataFormModel
|
||||
{
|
||||
private Entity entity;
|
||||
|
||||
private EntityEditorGenerator containerGenerator;
|
||||
private Dictionary<EntityProperty, EntityPropertyControl> propertyToEditor = new Dictionary<EntityProperty, EntityPropertyControl>();
|
||||
|
||||
internal DataFormModel(IDataFormView view)
|
||||
{
|
||||
|
@ -86,10 +88,14 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
this.CreateDefaultEntityProvider();
|
||||
}
|
||||
|
||||
this.entityProvider.OnItemChanged(newItem);
|
||||
this.containerGenerator.RemoveAll();
|
||||
this.Entity = this.entityProvider.GenerateEntity();
|
||||
this.Entity.IsReadOnly = this.View.IsReadOnly;
|
||||
if (this.entityProvider.Context != newItem)
|
||||
{
|
||||
this.entityProvider.OnItemChanged(newItem);
|
||||
this.containerGenerator.RemoveAll();
|
||||
this.Entity = this.entityProvider.GenerateEntity();
|
||||
this.Entity.IsReadOnly = this.View.IsReadOnly;
|
||||
}
|
||||
|
||||
this.BuildEditors();
|
||||
}
|
||||
|
||||
|
@ -120,6 +126,13 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
this.BuildEditors();
|
||||
}
|
||||
|
||||
internal object GetEditorCurrentValue(EntityProperty entityProperty)
|
||||
{
|
||||
EntityPropertyControl control;
|
||||
this.propertyToEditor.TryGetValue(entityProperty, out control);
|
||||
return control?.GetCurrentValue();
|
||||
}
|
||||
|
||||
private void Validator_ErrorsChanged(object sender, System.ComponentModel.DataErrorsChangedEventArgs e)
|
||||
{
|
||||
this.TransactionService.ErrorsChanged(sender, e.PropertyName);
|
||||
|
@ -132,30 +145,34 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
|
||||
private void BuildEditors()
|
||||
{
|
||||
var properties = this.entity.Properties.OrderBy((property) => property.Index);
|
||||
|
||||
foreach (var entityProperty in properties)
|
||||
if (this.View.IsTemplateApplied)
|
||||
{
|
||||
object groupContainer = null;
|
||||
this.propertyToEditor.Clear();
|
||||
|
||||
if (entityProperty.GroupKey != null)
|
||||
var properties = this.entity.Properties.OrderBy((property) => property.Index);
|
||||
|
||||
foreach (var entityProperty in properties)
|
||||
{
|
||||
groupContainer = this.GetOrCreateGroupContainer(entityProperty.GroupKey);
|
||||
}
|
||||
|
||||
var editor = this.containerGenerator.CreateContainer(entityProperty);
|
||||
|
||||
if (editor != null)
|
||||
{
|
||||
this.containerGenerator.PrepareContainer(editor, entityProperty);
|
||||
|
||||
if (entityProperty.GroupKey == null)
|
||||
object groupContainer = null;
|
||||
if (entityProperty.GroupKey != null)
|
||||
{
|
||||
this.View.AddEditor(editor);
|
||||
groupContainer = this.GetOrCreateGroupContainer(entityProperty.GroupKey);
|
||||
}
|
||||
else
|
||||
|
||||
var editor = this.containerGenerator.CreateContainer(entityProperty);
|
||||
if (editor != null)
|
||||
{
|
||||
this.containerGenerator.AddViewToGroupContainer(groupContainer, editor);
|
||||
this.propertyToEditor.Add(entityProperty, editor);
|
||||
this.containerGenerator.PrepareContainer(editor, entityProperty);
|
||||
|
||||
if (entityProperty.GroupKey == null)
|
||||
{
|
||||
this.View.AddEditor(editor);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.containerGenerator.AddViewToGroupContainer(groupContainer, editor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
CommandService CommandService { get; }
|
||||
ITransactionService TransactionService { get; }
|
||||
|
||||
bool IsTemplateApplied { get; }
|
||||
bool IsReadOnly { get; }
|
||||
|
||||
void AddEditor(object element);
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents an AutoCompleteEditor control.
|
||||
/// </summary>
|
||||
public class AutoCompleteEditor : RadAutoCompleteBox, ITypeEditor
|
||||
public class AutoCompleteEditor : RadAutoCompleteBox, ITypeEditor, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="LabelIconStyle"/> dependency property.
|
||||
|
@ -78,6 +78,11 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
set { this.SetValue(IconDisplayModeProperty, value); }
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
return this.Text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used for generating bindings for the <see cref="ITypeEditor"/> properties.
|
||||
/// </summary>
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents a BooleanEditor control.
|
||||
/// </summary>
|
||||
public class BooleanEditor : CheckBox, ITypeEditor
|
||||
public class BooleanEditor : CheckBox, ITypeEditor, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="CheckedStateBackgroundBrush"/> dependency property.
|
||||
|
@ -40,6 +40,11 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
}
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
return this.IsChecked;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used for generating bindings for the <see cref="ITypeEditor"/> properties.
|
||||
/// </summary>
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents a ToggleSwitchCustomEditor control.
|
||||
/// </summary>
|
||||
public class ToggleSwitchCustomEditor : CustomEditorBase<ToggleSwitch>
|
||||
public class ToggleSwitchCustomEditor : CustomEditorBase<ToggleSwitch>, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="SelectedBackgroundBrush"/> dependency property.
|
||||
|
@ -89,6 +89,17 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
}
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
var editor = this.EditorControl;
|
||||
if (editor != null)
|
||||
{
|
||||
return editor.IsOn;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="M:OnApplyTemplate" /> method has been called and the template is already successfully applied.
|
||||
/// </summary>
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents a DateEditor control.
|
||||
/// </summary>
|
||||
public class DateEditor : RadDatePicker, ITypeEditor
|
||||
public class DateEditor : RadDatePicker, ITypeEditor, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="LabelIconStyle"/> dependency property.
|
||||
|
@ -126,6 +126,11 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
set { this.SetValue(SelectedForegroundProperty, value); }
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
return this.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used for generating bindings for the <see cref="ITypeEditor"/> properties.
|
||||
/// </summary>
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace Telerik.UI.Xaml.Controls.Data.DataForm.View
|
|||
|
||||
internal EditorFactory EditorFactory { get; set; }
|
||||
|
||||
public object CreateContainer(EntityProperty entityProperty)
|
||||
public EntityPropertyControl CreateContainer(EntityProperty entityProperty)
|
||||
{
|
||||
var element = this.EditorFactory.CreateEditor(entityProperty);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Telerik.Data.Core;
|
||||
using System;
|
||||
using Telerik.Data.Core;
|
||||
using Telerik.UI.Xaml.Controls.Data.DataForm;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
@ -220,6 +221,17 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
}
|
||||
}
|
||||
|
||||
internal object GetCurrentValue()
|
||||
{
|
||||
var editor = this.View as IEditor;
|
||||
if (editor != null)
|
||||
{
|
||||
return editor.GetCurrentValue();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override bool ApplyTemplateCore()
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents an EnumEditor control.
|
||||
/// </summary>
|
||||
public class EnumEditor : ComboBox, ITypeEditor
|
||||
public class EnumEditor : ComboBox, ITypeEditor, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnumEditor"/> class.
|
||||
|
@ -18,6 +18,11 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
this.DefaultStyleKey = typeof(EnumEditor);
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
return this.SelectedItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used for generating bindings for the <see cref="ITypeEditor"/> properties.
|
||||
/// </summary>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
namespace Telerik.UI.Xaml.Controls.Data
|
||||
{
|
||||
internal interface IEditor
|
||||
{
|
||||
object GetCurrentValue();
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents a ListEditor control.
|
||||
/// </summary>
|
||||
public class ListEditor : ComboBox, ITypeEditor
|
||||
public class ListEditor : ComboBox, ITypeEditor, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ListEditor"/> class.
|
||||
|
@ -18,6 +18,11 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
this.DefaultStyleKey = typeof(ListEditor);
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
return this.SelectedItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used for generating bindings for the <see cref="ITypeEditor"/> properties.
|
||||
/// </summary>
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents a NumericEditor control.
|
||||
/// </summary>
|
||||
public class NumericEditor : RadNumericBox, ITypeEditor
|
||||
public class NumericEditor : RadNumericBox, ITypeEditor, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="ErrorIconStyle"/> dependency property.
|
||||
|
@ -109,6 +109,11 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
set { this.SetValue(ButtonsPointerOverBackgroundBrushProperty, value); }
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
return this.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used for generating bindings for the <see cref="ITypeEditor"/> properties.
|
||||
/// </summary>
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents a SegmentedCustomEditor control.
|
||||
/// </summary>
|
||||
public class SegmentedCustomEditor : RadSegmentedControl, ITypeEditor
|
||||
public class SegmentedCustomEditor : RadSegmentedControl, ITypeEditor, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SegmentedCustomEditor"/> class.
|
||||
|
@ -19,6 +19,11 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
this.DefaultStyleKey = typeof(SegmentedCustomEditor);
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
return this.SelectedItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used for generating bindings for the <see cref="ITypeEditor"/> properties.
|
||||
/// </summary>
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents a SliderCustomEditor control.
|
||||
/// </summary>
|
||||
public class SliderCustomEditor : Slider, ITypeEditor
|
||||
public class SliderCustomEditor : Slider, ITypeEditor, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="ThumbBackground"/> dependency property.
|
||||
|
@ -41,6 +41,11 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
}
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
return this.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used for generating bindings for the <see cref="ITypeEditor"/> properties.
|
||||
/// </summary>
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents a StringEditor control.
|
||||
/// </summary>
|
||||
public class StringEditor : TextBox, ITypeEditor
|
||||
public class StringEditor : TextBox, ITypeEditor, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="LabelIconStyle"/> dependency property.
|
||||
|
@ -78,6 +78,11 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
set { this.SetValue(ErrorIconStyleProperty, value); }
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
return this.Text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used for generating bindings for the <see cref="ITypeEditor"/> properties.
|
||||
/// </summary>
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
/// <summary>
|
||||
/// Represents a TimeEditor control.
|
||||
/// </summary>
|
||||
public class TimeEditor : RadTimePicker, ITypeEditor
|
||||
public class TimeEditor : RadTimePicker, ITypeEditor, IEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="IconDisplayMode"/> dependency property.
|
||||
|
@ -126,6 +126,11 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
set { this.SetValue(SelectedForegroundProperty, value); }
|
||||
}
|
||||
|
||||
object IEditor.GetCurrentValue()
|
||||
{
|
||||
return this.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used for generating bindings for the <see cref="ITypeEditor"/> properties.
|
||||
/// </summary>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using Telerik.Data.Core;
|
||||
using Telerik.UI.Automation.Peers;
|
||||
|
@ -238,6 +239,14 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
}
|
||||
}
|
||||
|
||||
bool IDataFormView.IsTemplateApplied
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.IsTemplateApplied;
|
||||
}
|
||||
}
|
||||
|
||||
internal DataFormModel Model { get; set; }
|
||||
|
||||
internal Entity Entity
|
||||
|
@ -332,6 +341,17 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
this.Model.RefreshLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the editor current value. Used in tests.
|
||||
/// </summary>
|
||||
/// <param name="entityProperty">The property associated with the editor.</param>
|
||||
/// <returns>The editor value.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public object GetEditorValueForProperty(EntityProperty entityProperty)
|
||||
{
|
||||
return this.Model.GetEditorCurrentValue(entityProperty);
|
||||
}
|
||||
|
||||
void IDataFormView.PrepareEditor(object editor, object groupVisual)
|
||||
{
|
||||
var editorElement = editor as EntityPropertyControl;
|
||||
|
@ -478,10 +498,7 @@ namespace Telerik.UI.Xaml.Controls.Data
|
|||
private static void OnItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
RadDataForm form = d as RadDataForm;
|
||||
if (form.IsTemplateApplied)
|
||||
{
|
||||
form.Model.OnItemChanged(e.NewValue);
|
||||
}
|
||||
form.Model.OnItemChanged(e.NewValue);
|
||||
}
|
||||
|
||||
private static void OnEntityProviderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
|
|
Загрузка…
Ссылка в новой задаче