Data model conditions - Simplified list VM code

Data model conditions - When selecting a different type, recheck if a new preferred operator is available
This commit is contained in:
SpoinkyNL committed 2020-10-31 19:44:24 +01:00
1 parent 13df88ca40
commit e1eb03667e
10 files changed
+60 -110

No files matched your search

@@ -15,8 +15,6 @@ namespace Artemis.UI.Shared
{
DataModel = ListPredicateWrapperDataModel.Create(listType);
ListType = listType;
IsRootViewModel = false;
}
public int Index
@@ -44,31 +44,7 @@ namespace Artemis.UI.Shared
}
public BindableCollection<DataModelVisualizationViewModel> ListChildren { get; set; }
public DataModelPropertiesViewModel GetListTypeViewModel(IDataModelUIService dataModelUIService)
{
Type listType = DataModelPath.GetPropertyType()?.GetGenericEnumerableType();
if (listType == null)
return null;
// Create a property VM describing the type of the list
DataModelVisualizationViewModel viewModel = CreateListChild(dataModelUIService, listType);
viewModel.Update(dataModelUIService);
// Put an empty value into the list type property view model
if (viewModel is DataModelListPropertiesViewModel dataModelListClassViewModel) return dataModelListClassViewModel;
if (viewModel is DataModelListPropertyViewModel dataModelListPropertyViewModel)
{
dataModelListPropertyViewModel.DisplayValue = Activator.CreateInstance(dataModelListPropertyViewModel.ListType);
DataModelPropertiesViewModel wrapper = new DataModelPropertiesViewModel(null, null, null);
wrapper.Children.Add(dataModelListPropertyViewModel);
return wrapper;
}
return null;
}
public override void Update(IDataModelUIService dataModelUIService)
{
if (Parent != null && !Parent.IsVisualizationExpanded)
@@ -142,41 +142,6 @@ namespace Artemis.UI.Shared
IsMatchingFilteredTypes = filteredTypes.Any(t => t == type || t == typeof(Enum) && type.IsEnum);
}
public DataModelVisualizationViewModel GetChildByPath(Guid dataModelGuid, string propertyPath)
{
if (!IsRootViewModel)
{
if (DataModel.PluginInfo.Guid != dataModelGuid)
return null;
if (propertyPath == null)
return null;
if (Path != null && Path.StartsWith(propertyPath, StringComparison.OrdinalIgnoreCase))
return null;
}
// Ensure children are populated by requesting an update
if (!IsVisualizationExpanded)
{
IsVisualizationExpanded = true;
RequestUpdate();
IsVisualizationExpanded = false;
}
foreach (DataModelVisualizationViewModel child in Children)
{
// Try the child itself first
if (child.Path == propertyPath)
return child;
// Try a child on the child next, this will go recursive
DataModelVisualizationViewModel match = child.GetChildByPath(dataModelGuid, propertyPath);
if (match != null)
return match;
}
return null;
}
internal virtual int GetChildDepth()
{
return 0;
@@ -187,7 +152,7 @@ namespace Artemis.UI.Shared
if (IsRootViewModel && DataModel == null)
return;
Type modelType = IsRootViewModel ? DataModel.GetType() : DataModelPath?.GetPropertyType() ?? DataModel.GetType();
Type modelType = IsRootViewModel ? DataModel.GetType() : DataModelPath.GetPropertyType();
// Add missing static children
foreach (PropertyInfo propertyInfo in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(t => t.MetadataToken))