Data model conditions - Moved events into a separate 'mode'

This commit is contained in:
SpoinkyNL committed 2020-11-01 19:44:45 +01:00
1 parent e1eb03667e
commit 997ab005d8
26 files changed
+331 -128

No files matched your search

@@ -131,6 +131,8 @@ namespace Artemis.UI.Shared.Input
}
}
public bool LoadEventChildren { get; set; } = true;
public void ChangeDataModel(DataModelPropertiesViewModel dataModel)
{
if (DataModelViewModel != null)
@@ -199,17 +201,17 @@ namespace Artemis.UI.Shared.Input
private void OnUpdateTimerOnElapsed(object sender, ElapsedEventArgs e)
{
// if (!IsDataModelViewModelOpen)
// return;
//
// UpdateDataModelVisualization();
if (!IsDataModelViewModelOpen)
return;
UpdateDataModelVisualization();
}
private void UpdateDataModelVisualization()
{
DataModelViewModel.Update(_dataModelUIService);
DataModelViewModel.Update(_dataModelUIService, new DataModelUpdateConfiguration(LoadEventChildren));
foreach (DataModelPropertiesViewModel extraDataModelViewModel in ExtraDataModelViewModels)
extraDataModelViewModel.Update(_dataModelUIService);
extraDataModelViewModel.Update(_dataModelUIService, new DataModelUpdateConfiguration(LoadEventChildren));
}
#endregion
@@ -1,4 +1,6 @@
using Artemis.Core;
using System;
using System.Linq;
using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared.Services;
@@ -6,12 +8,36 @@ namespace Artemis.UI.Shared
{
public class DataModelEventViewModel : DataModelVisualizationViewModel
{
private Type _displayValueType;
internal DataModelEventViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, DataModelPath dataModelPath) : base(dataModel, parent, dataModelPath)
{
}
public override void Update(IDataModelUIService dataModelUIService)
public Type DisplayValueType
{
get => _displayValueType;
set => SetAndNotify(ref _displayValueType, value);
}
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
DisplayValueType = DataModelPath?.GetPropertyType();
if (configuration != null)
{
if (configuration.CreateEventChildren)
PopulateProperties(dataModelUIService, configuration);
else if (Children.Any())
Children.Clear();
}
// Only update children if the parent is expanded
if (Parent != null && !Parent.IsRootViewModel && !Parent.IsVisualizationExpanded)
return;
foreach (DataModelVisualizationViewModel dataModelVisualizationViewModel in Children)
dataModelVisualizationViewModel.Update(dataModelUIService, configuration);
}
public override object GetCurrentValue()
@@ -39,17 +39,17 @@ namespace Artemis.UI.Shared
public override string DisplayPath => null;
public override void Update(IDataModelUIService dataModelUIService)
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
((ListPredicateWrapperDataModel) DataModel).UntypedValue = DisplayValue;
PopulateProperties(dataModelUIService);
PopulateProperties(dataModelUIService, configuration);
if (DisplayViewModel == null)
return;
if (IsVisualizationExpanded && !DisplayViewModel.IsVisualizationExpanded)
DisplayViewModel.IsVisualizationExpanded = IsVisualizationExpanded;
DisplayViewModel.Update(dataModelUIService);
DisplayViewModel.Update(dataModelUIService, null);
}
public override object GetCurrentValue()
@@ -39,7 +39,7 @@ namespace Artemis.UI.Shared
return DisplayValue;
}
public override void Update(IDataModelUIService dataModelUIService)
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
// Display value gets updated by parent, don't do anything if it is null
if (DisplayValue == null)
@@ -45,7 +45,7 @@ namespace Artemis.UI.Shared
public BindableCollection<DataModelVisualizationViewModel> ListChildren { get; set; }
public override void Update(IDataModelUIService dataModelUIService)
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
if (Parent != null && !Parent.IsVisualizationExpanded)
return;
@@ -83,7 +83,7 @@ namespace Artemis.UI.Shared
dataModelListPropertyViewModel.Index = index;
}
child.Update(dataModelUIService);
child.Update(dataModelUIService, configuration);
index++;
}
@@ -26,7 +26,7 @@ namespace Artemis.UI.Shared
set => SetAndNotify(ref _displayValue, value);
}
public override void Update(IDataModelUIService dataModelUIService)
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
DisplayValueType = DataModelPath?.GetPropertyType();
@@ -38,14 +38,14 @@ namespace Artemis.UI.Shared
DisplayValue = null;
// Always populate properties
PopulateProperties(dataModelUIService);
PopulateProperties(dataModelUIService, configuration);
// Only update children if the parent is expanded
if (Parent != null && !Parent.IsRootViewModel && !Parent.IsVisualizationExpanded)
return;
foreach (DataModelVisualizationViewModel dataModelVisualizationViewModel in Children)
dataModelVisualizationViewModel.Update(dataModelUIService);
dataModelVisualizationViewModel.Update(dataModelUIService, configuration);
}
public override object GetCurrentValue()
@@ -33,7 +33,7 @@ namespace Artemis.UI.Shared
set => SetAndNotify(ref _displayViewModel, value);
}
public override void Update(IDataModelUIService dataModelUIService)
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
if (Parent != null && !Parent.IsVisualizationExpanded && !Parent.IsRootViewModel)
return;
@@ -87,8 +87,9 @@ namespace Artemis.UI.Shared
/// <summary>
/// Updates the datamodel and if in an parent, any children
/// </summary>
/// <param name="dataModelUIService"></param>
public abstract void Update(IDataModelUIService dataModelUIService);
/// <param name="dataModelUIService">The data model UI service used during update</param>
/// <param name="configuration">The configuration to apply while updating</param>
public abstract void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration);
public virtual object GetCurrentValue()
{
@@ -147,7 +148,7 @@ namespace Artemis.UI.Shared
return 0;
}
internal void PopulateProperties(IDataModelUIService dataModelUIService)
internal void PopulateProperties(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration dataModelUpdateConfiguration)
{
if (IsRootViewModel && DataModel == null)
return;
@@ -260,4 +261,14 @@ namespace Artemis.UI.Shared
#endregion
}
public class DataModelUpdateConfiguration
{
public bool CreateEventChildren { get; }
public DataModelUpdateConfiguration(bool createEventChildren)
{
CreateEventChildren = createEventChildren;
}
}
}
@@ -6,21 +6,21 @@ namespace Artemis.UI.Shared
{
public static class DataModelWrapperExtensions
{
public static DataModelPropertiesViewModel CreateViewModel(this EventPredicateWrapperDataModel wrapper, IDataModelUIService dataModelUIService)
public static DataModelPropertiesViewModel CreateViewModel(this EventPredicateWrapperDataModel wrapper, IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(wrapper, null, new DataModelPath(wrapper));
viewModel.Update(dataModelUIService);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(dataModelUIService);
viewModel.Update(dataModelUIService, configuration);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(dataModelUIService, configuration);
viewModel.Children.First().IsVisualizationExpanded = true;
return viewModel;
}
public static DataModelPropertiesViewModel CreateViewModel(this ListPredicateWrapperDataModel wrapper, IDataModelUIService dataModelUIService)
public static DataModelPropertiesViewModel CreateViewModel(this ListPredicateWrapperDataModel wrapper, IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(wrapper, null, new DataModelPath(wrapper));
viewModel.Update(dataModelUIService);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(dataModelUIService);
viewModel.Update(dataModelUIService, configuration);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(dataModelUIService, configuration);
viewModel.Children.First().IsVisualizationExpanded = true;
return viewModel;
@@ -37,8 +37,8 @@ namespace Artemis.UI.Shared.Services
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModelExpansion, viewModel, new DataModelPath(dataModelExpansion)));
// Update to populate children
viewModel.Update(this);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(this);
viewModel.Update(this, null);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(this, null);
return viewModel;
}
@@ -67,8 +67,8 @@ namespace Artemis.UI.Shared.Services
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModel, viewModel, null));
// Update to populate children
viewModel.Update(this);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(this);
viewModel.Update(this, null);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(this, null);
return viewModel;
}
@@ -173,7 +173,7 @@ namespace Artemis.UI.Shared.Services
else
result = _kernel.Get<DefaultDataModelDisplayViewModel>();
if (result != null)
if (result != null)
result.PropertyDescription = description;
return result;