Bevisuali.UX.MainWindow.OnModelSelectedVariableUpdated C# (CSharp) Method

OnModelSelectedVariableUpdated() private method

private OnModelSelectedVariableUpdated ( IWorkbench workbench ) : void
workbench IWorkbench
return void
        void OnModelSelectedVariableUpdated(IWorkbench workbench)
        {
            // Lookup variable.
            string selectedName;
            RandomVariable selectedVariable;
            List<FRandomVariable> selectedVariableParents;
            IDictionary<string, string> abbreviations;

            if (workbench.SelectedVariable != null)
            {
                selectedName = workbench.SelectedVariable;
                selectedVariable =
                    workbench
                    .BayesianNetwork
                    .GetVariable(workbench.SelectedVariable);
                selectedVariableParents =
                    selectedVariable
                    .Parents
                    .Select(p => workbench.BayesianNetwork.GetVariable(p))
                    .ToList();
                abbreviations = workbench.BayesianNetworkVariableAbbreviations;
            }
            else
            {
                selectedName = null;
                selectedVariable = null;
                selectedVariableParents = null;
                abbreviations = null;
            }

            Dispatcher.Invoke(delegate
            {
                // Update the CPT inspector.
                xConditionalDistributions.SetDistribution(
                    selectedVariable,
                    abbreviations,
                    selectedVariableParents,
                    null);

                // Update the posterior marginal inspector.
                {
                    DiscreteDistribution posteriorDistribution;
                    IScenario scenario
                        = Model
                        .Scenarios
                        .FirstOrDefault(s => s.Id == "1");
                    if (scenario != null)
                    {
                        if (selectedName == null)
                        {
                            posteriorDistribution = null;
                        }
                        else
                        {
                            scenario
                                .PosteriorMarginals
                                .TryGetValue(selectedName, out posteriorDistribution);
                        }
                    }
                    else
                    {
                        posteriorDistribution = null;
                    }

                    xMarginalPosteriorDistributions.SetDistribution(
                        selectedVariable,
                        abbreviations,
                        selectedVariableParents,
                        posteriorDistribution);
                }

                // Update node selected property.
                OnModelSelectedVariableModeUpdated(workbench);
            });
        }