Data model paths - Added support for lists

Data model paths - Added deferred compilation to accessors
Data models - Fixed property name being empty sometimes
Plugins - Fixed disabling plugins that failed to load
This commit is contained in:
Robert committed 2020-10-05 19:52:22 +02:00
1 parent 3be217a33b
commit 3fcfe4ceec
10 files changed
+176 -96

No files matched your search

@@ -1,5 +1,4 @@
using System;
using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared.Services;
@@ -11,8 +10,11 @@ namespace Artemis.UI.Shared
private int _index;
private Type _listType;
public DataModelListPropertiesViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, DataModelPath dataModelPath) : base(dataModel, parent, dataModelPath)
public DataModelListPropertiesViewModel(DataModel dataModel, object listItem) : base(null, null, null)
{
DataModel = dataModel;
ListType = listItem.GetType();
DisplayValue = listItem;
}
public int Index
@@ -42,7 +44,7 @@ namespace Artemis.UI.Shared
return;
ListType = DisplayValue.GetType();
PopulateProperties(dataModelUIService);
PopulateProperties(dataModelUIService, DisplayValue);
foreach (var dataModelVisualizationViewModel in Children)
dataModelVisualizationViewModel.Update(dataModelUIService);
}
@@ -51,5 +53,11 @@ namespace Artemis.UI.Shared
{
return DisplayValue;
}
/// <inheritdoc />
public override string ToString()
{
return $"[List item {Index}] {DisplayPath ?? Path}";
}
}
}
@@ -1,5 +1,4 @@
using System;
using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared.Services;
@@ -10,8 +9,19 @@ namespace Artemis.UI.Shared
private int _index;
private Type _listType;
public DataModelListPropertyViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, DataModelPath dataModelPath) : base(dataModel, parent, dataModelPath)
public DataModelListPropertyViewModel(DataModel dataModel, object listItem, DataModelDisplayViewModel displayViewModel) : base(null, null, null)
{
DataModel = dataModel;
ListType = listItem.GetType();
DisplayValue = listItem;
DisplayViewModel = displayViewModel;
}
public DataModelListPropertyViewModel(DataModel dataModel, object listItem) : base(null, null, null)
{
DataModel = dataModel;
ListType = listItem.GetType();
DisplayValue = listItem;
}
public int Index
@@ -43,5 +53,11 @@ namespace Artemis.UI.Shared
ListType = DisplayValue.GetType();
UpdateDisplayParameters();
}
/// <inheritdoc />
public override string ToString()
{
return $"[List item {Index}] {DisplayPath ?? Path} - {DisplayValue}";
}
}
}
@@ -105,20 +105,25 @@ namespace Artemis.UI.Shared
protected DataModelVisualizationViewModel CreateListChild(IDataModelUIService dataModelUIService, object listItem)
{
var listType = listItem.GetType();
var path = new DataModelPath(listItem, "");
// If a display VM was found, prefer to use that in any case
var typeViewModel = dataModelUIService.GetDataModelDisplayViewModel(listType);
if (typeViewModel != null)
return new DataModelListPropertyViewModel(DataModel, this, path) {DisplayViewModel = typeViewModel};
return new DataModelListPropertyViewModel(DataModel, listItem, typeViewModel);
// For primitives, create a property view model, it may be null that is fine
if (listType.IsPrimitive || listType.IsEnum || listType == typeof(string))
return new DataModelListPropertyViewModel(DataModel, this, path) {ListType = listType};
return new DataModelListPropertyViewModel(DataModel, listItem);
// For other value types create a child view model
if (listType.IsClass || listType.IsStruct())
return new DataModelListPropertiesViewModel(DataModel, this, path) {ListType = listType};
return new DataModelListPropertiesViewModel(DataModel, listItem);
return null;
}
/// <inheritdoc />
public override string ToString()
{
return $"[List] {DisplayPath ?? Path} - {List.Count} item(s)";
}
}
}
@@ -13,7 +13,7 @@ namespace Artemis.UI.Shared
public override void Update(IDataModelUIService dataModelUIService)
{
// Always populate properties
PopulateProperties(dataModelUIService);
PopulateProperties(dataModelUIService, null);
// Only update children if the parent is expanded
if (Parent != null && !Parent.IsVisualizationExpanded && !Parent.IsRootViewModel)
@@ -28,9 +28,15 @@ namespace Artemis.UI.Shared
return Parent.IsRootViewModel ? DataModel : base.GetCurrentValue();
}
protected override int GetChildDepth()
internal override int GetChildDepth()
{
return PropertyDescription != null && !PropertyDescription.ResetsDepth ? Depth + 1 : 1;
}
/// <inheritdoc />
public override string ToString()
{
return DisplayPath ?? Path;
}
}
}
@@ -50,5 +50,11 @@ namespace Artemis.UI.Shared
{
DisplayViewModel?.UpdateValue(DisplayValue);
}
/// <inheritdoc />
public override string ToString()
{
return $"[{DisplayValueType.Name}] {DisplayPath ?? Path} - {DisplayValue}";
}
}
}
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using Artemis.Core;
@@ -136,21 +137,6 @@ namespace Artemis.UI.Shared
IsMatchingFilteredTypes = filteredTypes.Any(t => t == type || t == typeof(Enum) && type.IsEnum);
}
public DataModelVisualizationViewModel GetChildForCondition(DataModelConditionPredicate predicate, DataModelConditionSide side)
{
if (side == DataModelConditionSide.Left)
{
if (predicate.LeftDataModel == null || predicate.LeftPropertyPath == null)
return null;
return GetChildByPath(predicate.LeftDataModel.PluginInfo.Guid, predicate.LeftPropertyPath);
}
if (predicate.RightDataModel == null || predicate.RightPropertyPath == null)
return null;
return GetChildByPath(predicate.RightDataModel.PluginInfo.Guid, predicate.RightPropertyPath);
}
public DataModelVisualizationViewModel GetChildByPath(Guid dataModelGuid, string propertyPath)
{
if (DataModel.PluginInfo.Guid != dataModelGuid)
@@ -183,31 +169,44 @@ namespace Artemis.UI.Shared
return null;
}
protected virtual int GetChildDepth()
internal virtual int GetChildDepth()
{
return 0;
}
protected void PopulateProperties(IDataModelUIService dataModelUIService)
internal void PopulateProperties(IDataModelUIService dataModelUIService, object overrideValue)
{
if (IsRootViewModel)
if (IsRootViewModel && overrideValue == null)
return;
Type modelType;
if (overrideValue != null)
modelType = overrideValue.GetType();
else if (Parent.IsRootViewModel)
modelType = DataModel.GetType();
else
modelType = DataModelPath.GetPropertyType();
// Add missing static children
var modelType = Parent.IsRootViewModel ? DataModel.GetType() : DataModelPath.GetPropertyType();
foreach (var propertyInfo in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
var childPath = Path != null ? $"{Path}.{propertyInfo.Name}" : propertyInfo.Name;
if (Children.Any(c => c.Path != null && c.Path.Equals(childPath)))
continue;
if (propertyInfo.GetCustomAttribute<DataModelIgnoreAttribute>() != null)
continue;
var child = CreateChild(dataModelUIService, childPath, GetChildDepth());
var child = CreateChild(dataModelUIService, childPath, GetChildDepth(), overrideValue);
if (child != null)
Children.Add(child);
}
// Remove static children that should be hidden
var hiddenProperties = DataModel.GetHiddenProperties();
ReadOnlyCollection<PropertyInfo> hiddenProperties;
if (overrideValue != null && overrideValue is DataModel overrideValueDataModel)
hiddenProperties = overrideValueDataModel.GetHiddenProperties();
else
hiddenProperties = DataModel.GetHiddenProperties();
foreach (var hiddenProperty in hiddenProperties)
{
var childPath = Path != null ? $"{Path}.{hiddenProperty.Name}" : hiddenProperty.Name;
@@ -217,7 +216,11 @@ namespace Artemis.UI.Shared
}
// Add missing dynamic children
var value = Parent.IsRootViewModel ? DataModel : DataModelPath.GetValue();
object value;
if (overrideValue != null)
value = overrideValue;
else
value = Parent.IsRootViewModel ? DataModel : DataModelPath.GetValue();
if (value is DataModel dataModel)
{
foreach (var kvp in dataModel.DynamicDataModels)
@@ -226,7 +229,7 @@ namespace Artemis.UI.Shared
if (Children.Any(c => c.Path != null && c.Path.Equals(childPath)))
continue;
var child = CreateChild(dataModelUIService, childPath, GetChildDepth());
var child = CreateChild(dataModelUIService, childPath, GetChildDepth(), overrideValue);
if (child != null)
Children.Add(child);
}
@@ -238,12 +241,12 @@ namespace Artemis.UI.Shared
Children.RemoveRange(toRemoveDynamic);
}
protected DataModelVisualizationViewModel CreateChild(IDataModelUIService dataModelUIService, string path, int depth)
private DataModelVisualizationViewModel CreateChild(IDataModelUIService dataModelUIService, string path, int depth, object overrideValue)
{
if (depth > MaxDepth)
return null;
var dataModelPath = new DataModelPath(DataModel, path);
var dataModelPath = new DataModelPath(overrideValue ?? DataModel, path);
if (!dataModelPath.IsValid)
return null;