using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core;
using Artemis.Core.Modules;
using Artemis.UI.Shared.Services;
using ReactiveUI;
namespace Artemis.UI.Shared.DataModelVisualization.Shared;
///
/// Represents a view model that visualizes an event data model property
///
public class DataModelEventViewModel : DataModelVisualizationViewModel
{
private Type? _displayValueType;
internal DataModelEventViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, DataModelPath dataModelPath) : base(dataModel, parent, dataModelPath)
{
}
///
/// Gets the type of event arguments this event triggers and that must be displayed as children
///
public Type? DisplayValueType
{
get => _displayValueType;
set => this.RaiseAndSetIfChanged(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 && (configuration == null || !configuration.UpdateAllChildren))
return;
foreach (DataModelVisualizationViewModel dataModelVisualizationViewModel in Children)
dataModelVisualizationViewModel.Update(dataModelUIService, configuration);
}
///
public override IEnumerable GetSearchResults(string search)
{
if (PropertyDescription?.Name != null && PropertyDescription.Name.Contains(search, StringComparison.OrdinalIgnoreCase))
return [this];
return [];
}
///
/// Always returns for data model events
///
public override object? GetCurrentValue()
{
return null;
}
///
public override string? ToString()
{
return DisplayPath ?? Path;
}
internal override int GetChildDepth()
{
return PropertyDescription != null && !PropertyDescription.ResetsDepth ? Depth + 1 : 1;
}
}