diff --git a/src/client/spark/view/Controls/DataGridEx/Filters/IDataGridColumnFilter.cs b/src/client/spark/view/Controls/DataGridEx/Filters/IDataGridColumnFilter.cs index 0b87f4cce..9ed627562 100644 --- a/src/client/spark/view/Controls/DataGridEx/Filters/IDataGridColumnFilter.cs +++ b/src/client/spark/view/Controls/DataGridEx/Filters/IDataGridColumnFilter.cs @@ -12,6 +12,8 @@ namespace mbts.spark.filters { ICommand cancel { get; } bool filter(object row); event Action filter_changed; + void load_state(object state); + object get_state(); } interface IDataGridColumnFilter : IDataGridColumnFilter { @@ -20,6 +22,6 @@ namespace mbts.spark.filters { interface IDataGridColumnPersistentFilter : IDataGridColumnFilter { void load_state(TState state); - TState get_state(); + new TState get_state(); } -} \ No newline at end of file +} diff --git a/src/client/spark/view/Controls/DataGridEx/Filters/VM/FilterVMBase.cs b/src/client/spark/view/Controls/DataGridEx/Filters/VM/FilterVMBase.cs index 67297a6e3..bf73d8377 100644 --- a/src/client/spark/view/Controls/DataGridEx/Filters/VM/FilterVMBase.cs +++ b/src/client/spark/view/Controls/DataGridEx/Filters/VM/FilterVMBase.cs @@ -1,5 +1,6 @@ using mbts.ui; using mbts.ui.shell; +using mbts.utils; using System; using System.Windows.Input; @@ -53,6 +54,15 @@ namespace mbts.spark.filters { _raise_filter_changed(); } + object IDataGridColumnFilter.get_state() => + get_state(); + + void IDataGridColumnFilter.load_state(object state) { + if (state is TState fstate) + load_state(fstate); + else if (state != null) throw ExceptionBuilder.Argument.not_of_type(nameof(state), state?.GetType()); + } + protected abstract bool _get_active(); protected abstract bool _filter(TValue value); protected abstract void _load_state_internal(TState state); @@ -111,4 +121,4 @@ namespace mbts.spark.filters { bool IDataGridColumnFilter.filter(object row) => filter(ConvertUtils.try_convert(row)); } -} \ No newline at end of file +} diff --git a/src/client/spark/view/Controls/DataGridEx/Filters/VM/TupleFilterVM.cs b/src/client/spark/view/Controls/DataGridEx/Filters/VM/TupleFilterVM.cs index c0be31570..30a9c2263 100644 --- a/src/client/spark/view/Controls/DataGridEx/Filters/VM/TupleFilterVM.cs +++ b/src/client/spark/view/Controls/DataGridEx/Filters/VM/TupleFilterVM.cs @@ -1,6 +1,7 @@ using bts; using mbts.ui; using mbts.ui.shell; +using mbts.utils; using System; using System.Windows.Input; @@ -60,16 +61,24 @@ namespace mbts.spark.filters { public TCompoundState get_state() => _get_state(_filter1.get_state(), _filter2.get_state()); + object IDataGridColumnFilter.get_state() => + get_state(); + public void load_state(TCompoundState state) { _filter1.load_state(_get_filter1_state(state)); _filter2.load_state(_get_filter2_state(state)); } + void IDataGridColumnFilter.load_state(object state) { + if (state is TCompoundState cstate) + load_state(cstate); + else throw ExceptionBuilder.Argument.not_of_type(nameof(state), state?.GetType()); + } + protected void _raise_request_update() => RequestUpdate?.Invoke(); - bool IDataGridColumnFilter.filter(object row) => filter(ConvertUtils.try_convert(row)); } -} \ No newline at end of file +} diff --git a/src/client/spark_core/utils/Exceptions/ExceptionBuilder.cs b/src/client/spark_core/utils/Exceptions/ExceptionBuilder.cs index cefe54893..86bb986fb 100644 --- a/src/client/spark_core/utils/Exceptions/ExceptionBuilder.cs +++ b/src/client/spark_core/utils/Exceptions/ExceptionBuilder.cs @@ -9,11 +9,16 @@ namespace mbts.utils { public static ArgumentException unexpected_case(T value, string name) => new ArgumentException($"Unexpected {typeof(T)} '{value}.'", name); - public static ArgumentException not_of_type(object value, string name) => - not_of_type(value, name, typeof(T)); + public static ArgumentException not_of_type(string name, Type actual = null) => + actual is null ? + not_of_type(name, typeof(T)) : + not_of_type(name, typeof(T), actual); - public static ArgumentException not_of_type(object value, string name, Type t) => - new ArgumentException($"Value is not of the expected type '{t}.'"); + public static ArgumentException not_of_type(string name, Type t) => + new ArgumentException(Format.NotOfType(t), name); + + public static ArgumentException not_of_type(string name, Type expected, Type actual) => + new ArgumentException(Format.NotOfType(expected, actual), name); public static ArgumentException null_or_empty(string name) => new ArgumentException("Value is null or empty.", name); @@ -49,6 +54,8 @@ namespace mbts.utils { public static string LessThanOrEqualTo(int value) => $"{Messages.LessThanOrEqualTo} {value}."; public static string GreaterThan(int value) => $"{Messages.GreaterThan} {value}."; public static string GreaterThanOrEqualTo(int value) => $"{Messages.GreaterThanOrEqualTo} {value}."; + public static string NotOfType(Type type) => $"Argument is not of expected type '{type}.'"; + public static string NotOfType(Type expected, Type actual) => $"Argument is not of expected type '{expected}' (actually '{actual}')."; } public static class Messages { @@ -59,4 +66,4 @@ namespace mbts.utils { GreaterThanOrEqualTo = "Greater than or equal to"; } } -} \ No newline at end of file +}