UI - Centralized default editors registration into a service

Display conditions - Added more test operators 
Display conditions - Implemented operator selection
Display conditions - Implemented property selection and rules
This commit is contained in:
Robert committed 2020-07-06 19:07:18 +02:00
1 parent 0ac6431755
commit 2ad78411c8
26 files changed
+470 -179

No files matched your search

@@ -5,13 +5,26 @@ namespace Artemis.UI.Shared.DataModelVisualization
{
public abstract class DataModelInputViewModel<T> : DataModelInputViewModel
{
protected DataModelInputViewModel(DataModelPropertyAttribute description)
private T _inputValue;
protected DataModelInputViewModel(DataModelPropertyAttribute description, T initialValue)
{
Description = description;
InputValue = initialValue;
}
public T InputValue
{
get => _inputValue;
set => SetAndNotify(ref _inputValue, value);
}
public DataModelPropertyAttribute Description { get; }
internal override object InternalGuard { get; } = null;
protected void Submit()
{
}
}
/// <summary>
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Artemis.Core.Extensions;
@@ -19,6 +20,7 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
private DataModelVisualizationViewModel _parent;
private DataModelPropertyAttribute _propertyDescription;
private PropertyInfo _propertyInfo;
private bool _isMatchingFilteredTypes;
internal DataModelVisualizationViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, PropertyInfo propertyInfo)
{
@@ -26,6 +28,7 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
PropertyInfo = propertyInfo;
Parent = parent;
Children = new BindableCollection<DataModelVisualizationViewModel>();
IsMatchingFilteredTypes = true;
if (dataModel == null && parent == null && propertyInfo == null)
IsRootViewModel = true;
@@ -65,6 +68,12 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
set => SetAndNotify(ref _children, value);
}
public bool IsMatchingFilteredTypes
{
get => _isMatchingFilteredTypes;
set => SetAndNotify(ref _isMatchingFilteredTypes, value);
}
public abstract void Update(IDataModelVisualizationService dataModelVisualizationService);
public virtual object GetCurrentValue()
@@ -72,6 +81,34 @@ namespace Artemis.UI.Shared.DataModelVisualization.Shared
return Parent == null ? null : PropertyInfo.GetValue(Parent.GetCurrentValue());
}
public void ApplyTypeFilter(params Type[] filteredTypes)
{
// If the VM has children, its own type is not relevant
if (Children.Any())
{
foreach (var child in Children)
child.ApplyTypeFilter(filteredTypes);
IsMatchingFilteredTypes = true;
return;
}
// If null is passed, clear the type filter
if (filteredTypes == null || filteredTypes.Length == 0)
{
IsMatchingFilteredTypes = true;
return;
}
// If this VM has no property info, assume it does not match
if (PropertyInfo == null)
{
IsMatchingFilteredTypes = false;
return;
}
IsMatchingFilteredTypes = filteredTypes.Any(t => t.IsAssignableFrom(PropertyInfo.PropertyType));
}
public DataModelVisualizationViewModel GetChildByPath(Guid dataModelGuid, string propertyPath)
{
var path = propertyPath.Split(".");
@@ -18,8 +18,6 @@ namespace Artemis.UI.Shared.Services
private readonly IKernel _kernel;
private readonly List<DataModelVisualizationRegistration> _registeredDataModelDisplays;
private readonly List<DataModelVisualizationRegistration> _registeredDataModelEditors;
private DataModelPropertiesViewModel _cachedMainDataModel;
private Dictionary<Plugin, DataModelPropertiesViewModel> _cachedDataModels;
public DataModelVisualizationService(IDataModelService dataModelService, IKernel kernel)
{
@@ -27,38 +25,24 @@ namespace Artemis.UI.Shared.Services
_kernel = kernel;
_registeredDataModelEditors = new List<DataModelVisualizationRegistration>();
_registeredDataModelDisplays = new List<DataModelVisualizationRegistration>();
_cachedDataModels = new Dictionary<Plugin, DataModelPropertiesViewModel>();
}
public IReadOnlyCollection<DataModelVisualizationRegistration> RegisteredDataModelEditors => _registeredDataModelEditors.AsReadOnly();
public IReadOnlyCollection<DataModelVisualizationRegistration> RegisteredDataModelDisplays => _registeredDataModelDisplays.AsReadOnly();
public DataModelPropertiesViewModel GetMainDataModelVisualization(bool useCache)
public DataModelPropertiesViewModel GetMainDataModelVisualization()
{
// Return from cache if found
if (useCache && _cachedMainDataModel != null)
return _cachedMainDataModel;
var viewModel = new DataModelPropertiesViewModel(null, null, null);
foreach (var dataModelExpansion in _dataModelService.DataModelExpansions)
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModelExpansion, viewModel, null));
// Update to populate children
viewModel.Update(this);
// Add to cache
_cachedMainDataModel = viewModel;
return viewModel;
}
public DataModelPropertiesViewModel GetPluginDataModelVisualization(Plugin plugin, bool useCache)
public DataModelPropertiesViewModel GetPluginDataModelVisualization(Plugin plugin)
{
// Return from cache if found
var isCached = _cachedDataModels.TryGetValue(plugin, out var cachedMainDataModel);
if (useCache && isCached)
return cachedMainDataModel;
var dataModel = _dataModelService.GetPluginDataModel(plugin);
if (dataModel == null)
return null;
@@ -68,11 +52,6 @@ namespace Artemis.UI.Shared.Services
// Update to populate children
viewModel.Update(this);
// Add to cache
if (!isCached)
_cachedDataModels.Add(plugin, viewModel);
return viewModel;
}
@@ -81,12 +60,6 @@ namespace Artemis.UI.Shared.Services
return _dataModelService.GetPluginExtendsDataModel(plugin);
}
public void BustCache()
{
_cachedMainDataModel = null;
_cachedDataModels.Clear();
}
public DataModelVisualizationRegistration RegisterDataModelInput<T>(PluginInfo pluginInfo) where T : DataModelInputViewModel
{
var viewModelType = typeof(T);
@@ -173,8 +146,8 @@ namespace Artemis.UI.Shared.Services
public interface IDataModelVisualizationService : IArtemisSharedUIService
{
DataModelPropertiesViewModel GetMainDataModelVisualization(bool useCached);
DataModelPropertiesViewModel GetPluginDataModelVisualization(Plugin plugin, bool useCached);
DataModelPropertiesViewModel GetMainDataModelVisualization();
DataModelPropertiesViewModel GetPluginDataModelVisualization(Plugin plugin);
/// <summary>
/// Determines whether the given plugin expands the main data model
@@ -183,8 +156,6 @@ namespace Artemis.UI.Shared.Services
/// <returns></returns>
bool GetPluginExtendsDataModel(Plugin plugin);
void BustCache();
DataModelVisualizationRegistration RegisterDataModelInput<T>(PluginInfo pluginInfo) where T : DataModelInputViewModel;
DataModelVisualizationRegistration RegisterDataModelDisplay<T>(PluginInfo pluginInfo) where T : DataModelDisplayViewModel;
void RemoveDataModelInput(DataModelVisualizationRegistration registration);
@@ -22,6 +22,8 @@ namespace Artemis.UI.Shared.Services.Dialog
_viewManager = viewManager;
}
public bool IsExceptionDialogOpen { get; private set; }
public async Task<bool> ShowConfirmDialog(string header, string text, string confirmText = "Confirm", string cancelText = "Cancel")
{
var arguments = new IParameter[]
@@ -90,31 +92,28 @@ namespace Artemis.UI.Shared.Services.Dialog
public async Task ShowExceptionDialog(string message, Exception exception)
{
if (IsExceptionDialogOpen)
return;
IsExceptionDialogOpen = true;
var arguments = new IParameter[]
{
new ConstructorArgument("message", message),
new ConstructorArgument("exception", exception)
};
try
await Execute.OnUIThreadAsync(async () =>
{
await Execute.OnUIThreadAsync(async () =>
try
{
try
{
DialogHost.CloseDialogCommand.Execute(new object(), null);
await ShowDialog<ExceptionDialogViewModel>(arguments);
}
catch (Exception)
{
// ignored
}
});
}
catch (Exception)
{
// ignored
}
DialogHost.CloseDialogCommand.Execute(new object(), null);
await ShowDialog<ExceptionDialogViewModel>(arguments);
}
finally
{
IsExceptionDialogOpen = false;
}
});
}
private async Task<object> ShowDialog(string identifier, DialogViewModelBase viewModel)
@@ -102,5 +102,7 @@ namespace Artemis.UI.Shared.Services.Interfaces
/// <param name="exception">The exception to display. The exception message and stacktrace will be shown.</param>
/// <returns>A task resolving when the dialog is closed</returns>
Task ShowExceptionDialog(string message, Exception exception);
bool IsExceptionDialogOpen { get; }
}
}