using System; using System.Collections.Generic; using Artemis.Core; using Artemis.UI.Shared.Services; namespace Artemis.UI.Shared.DataModelVisualization { /// /// Represents a layer brush registered through /// or /// /// public class DataModelVisualizationRegistration { private readonly IDataModelUIService _dataModelUIService; internal DataModelVisualizationRegistration(IDataModelUIService dataModelUIService, RegistrationType registrationType, Plugin plugin, Type supportedType, Type viewModelType) { _dataModelUIService = dataModelUIService; RegistrationType = registrationType; Plugin = plugin; SupportedType = supportedType; ViewModelType = viewModelType; if (Plugin != Constants.CorePlugin) Plugin.Disabled += InstanceOnDisabled; } /// /// Gets the type of registration, either a display or an input /// public RegistrationType RegistrationType { get; } /// /// Gets the plugin that registered the visualization /// public Plugin Plugin { get; } /// /// Gets the type supported by the visualization /// public Type SupportedType { get; } /// /// Gets the view model type of the visualization /// public Type ViewModelType { get; } /// /// Gets a read only collection of types this visualization can convert to and from /// public IReadOnlyCollection? CompatibleConversionTypes { get; internal set; } internal void Unsubscribe() { if (Plugin != Constants.CorePlugin) Plugin.Disabled -= InstanceOnDisabled; } private void InstanceOnDisabled(object? sender, EventArgs e) { if (RegistrationType == RegistrationType.Input) _dataModelUIService.RemoveDataModelInput(this); else if (RegistrationType == RegistrationType.Display) _dataModelUIService.RemoveDataModelDisplay(this); } } /// /// Represents a type of data model visualization registration /// public enum RegistrationType { /// /// A visualization used for displaying values /// Display, /// /// A visualization used for inputting values /// Input } }