From bbe953a2f166263e66546c97fb6aa7d1c43e3686 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 25 Sep 2017 18:59:07 -0400 Subject: [PATCH] SyntheticEditor2 - adding row error border --- .../Securities/Synthetic2/ParameterRow.cs | 17 +++++++++--- .../Synthetic2/SyntheticEditor2.xaml | 13 +++++++-- .../Synthetic2/SyntheticEditor2.xaml.cs | 27 ++++++++++++++++--- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/client/spark/mspark/Shell/Securities/Synthetic2/ParameterRow.cs b/src/client/spark/mspark/Shell/Securities/Synthetic2/ParameterRow.cs index 6b06bff11..5014816c3 100644 --- a/src/client/spark/mspark/Shell/Securities/Synthetic2/ParameterRow.cs +++ b/src/client/spark/mspark/Shell/Securities/Synthetic2/ParameterRow.cs @@ -2,6 +2,7 @@ using mbts.ui.spark; using System; using System.Collections.Generic; +using System.Linq; namespace mbts.spark { @@ -37,7 +38,8 @@ namespace mbts.spark public virtual IReadOnlyCollection sub_items { get; } public abstract T get_value(LegSpreaderParamsTuple leg_tup); public abstract void set_value(LegSpreaderParamsTuple leg_tup, T value); - public object create_cell(LegSpreaderParamsTuple leg_tup) { return new ParameterRowCell(this, leg_tup); } + public virtual bool has_errors(IReadOnlyCollection leg_tups) { return false; } + public SyntheticEditor2.ICell create_cell(LegSpreaderParamsTuple leg_tup) { return new ParameterRowCell(this, leg_tup); } } internal class SizeRowModel : ParameterBase { @@ -67,6 +69,7 @@ namespace mbts.spark public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) { leg_tup.leg_params.IsActiveQuoting = value; } public override string display_name { get; } = "Is Active Quote"; public override string[] section_path { get; } = new[] { SectionNames.Quote }; + public override bool has_errors(IReadOnlyCollection leg_tups) { return !leg_tups.Any(lt => lt.leg_params.IsActiveQuoting); } } #region Quote @@ -180,7 +183,7 @@ namespace mbts.spark } #endregion - internal class ParameterRowCell { + internal class ParameterRowCell : SyntheticEditor2.ICell { public ParameterRowCell(IParameter model, LegSpreaderParamsTuple leg_tup) { _model = model; _leg_tup = leg_tup; @@ -189,7 +192,15 @@ namespace mbts.spark private readonly IParameter _model; private readonly LegSpreaderParamsTuple _leg_tup; - public T value { get => _model.get_value(_leg_tup); set => _model.set_value(_leg_tup, value); } + public T value { + get => _model.get_value(_leg_tup); + set { + _model.set_value(_leg_tup, value); + value_changed?.Invoke(); + } + } + + public event Action value_changed; } } } \ No newline at end of file diff --git a/src/client/spark/mspark/Shell/Securities/Synthetic2/SyntheticEditor2.xaml b/src/client/spark/mspark/Shell/Securities/Synthetic2/SyntheticEditor2.xaml index 7f5df288f..40d89b5e3 100644 --- a/src/client/spark/mspark/Shell/Securities/Synthetic2/SyntheticEditor2.xaml +++ b/src/client/spark/mspark/Shell/Securities/Synthetic2/SyntheticEditor2.xaml @@ -112,8 +112,8 @@ SnapsToDevicePixels="True"> - - + + + + + + + + leg_tups); + ICell create_cell(LegSpreaderParamsTuple leg_tup); + } + + public interface ICell + { + event Action value_changed; } #region SyntheticName @@ -79,16 +85,25 @@ namespace mbts.ui.spark internal class ParameterRow : DataGridExRow { public ParameterRow(IParameter model, IReadOnlyCollection legs) { - _cells = new ReadOnlyDictionary(legs.ToDictionary(l => l.leg.Security, model.create_cell)); + _has_errors = backing(nameof(has_errors), false); + _cells = new ReadOnlyDictionary(legs.ToDictionary(l => l.leg.Security, model.create_cell)); + foreach(var c in _cells.Values) { + _has_errors.set(model.has_errors(legs)); + c.value_changed += () => _has_errors.set(model.has_errors(legs)); + } display_name = model.display_name; section_path = model.section_path; } - private readonly IReadOnlyDictionary _cells; + + private readonly IReadOnlyDictionary _cells; + private readonly Property _has_errors; + public string display_name { get; } public string[] section_path { get; } public int section_count => section_path.Length; public override object get_cell(Security col_key) { return _cells[col_key]; } public string this[string section_no] => int.TryParse(section_no, out int i) && i < section_path.Length ? section_path[i] : null; + public bool has_errors => _has_errors.Value; } #endregion @@ -113,6 +128,12 @@ namespace mbts.ui.spark public DataTemplateSelector ParameterCellEditingTemplateSelector { get => GetValue(ParameterCellEditingTemplateSelectorProperty) as DataTemplateSelector; set => SetValue(ParameterCellEditingTemplateSelectorProperty, value); } #endregion + #region RowHasError + public static readonly DependencyProperty RowHasErrorsProperty = DependencyProperty.RegisterAttached("RowHasErrors", typeof(bool), typeof(SyntheticEditor2), new PropertyMetadata(false)); + public static bool GetRowHasErrors(DependencyObject d) { return (bool)d.GetValue(RowHasErrorsProperty); } + public static void SetRowHasErrors(DependencyObject d, bool value) { d.SetValue(RowHasErrorsProperty, value); } + #endregion + private static void GenerateParameterRows(DependencyObject d, DependencyPropertyChangedEventArgs e) { var parameters = d.GetValue(ParametersProperty) as IReadOnlyCollection; var legs = d.GetValue(LegTuplesProperty) as IReadOnlyCollection;