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 15:21:57 +02:00
1 parent 71f6706eec
commit f944a675f1
26 files changed
+470 -179

No files matched your search

@@ -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; }
}
}