add get/load_state methods to non-generic IDataGridColumnFilter

This commit is contained in:
John Colvin committed 2020-08-03 15:28:41 -05:00
1 parent a0a5d82139
commit 80256fbe12
4 files changed
+38 -10

No files matched your search

@@ -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<in TRow> : IDataGridColumnFilter {
@@ -20,6 +22,6 @@ namespace mbts.spark.filters {
interface IDataGridColumnPersistentFilter<in TRow, TState> : IDataGridColumnFilter<TRow> {
void load_state(TState state);
TState get_state();
new TState get_state();
}
}
}
@@ -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<TState>(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<TRow>(row));
}
}
}
@@ -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<TCompoundState>(nameof(state), state?.GetType());
}
protected void _raise_request_update() =>
RequestUpdate?.Invoke();
bool IDataGridColumnFilter.filter(object row) =>
filter(ConvertUtils.try_convert<TRow>(row));
}
}
}
@@ -9,11 +9,16 @@ namespace mbts.utils {
public static ArgumentException unexpected_case<T>(T value, string name) =>
new ArgumentException($"Unexpected {typeof(T)} '{value}.'", name);
public static ArgumentException not_of_type<T>(object value, string name) =>
not_of_type(value, name, typeof(T));
public static ArgumentException not_of_type<T>(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";
}
}
}
}