/// <summary>
        /// Shows the form.
        /// </summary>
        /// <param name="autoSave">Controls whether to apply to core.DefaultStatistics</param>
        internal static ObsFilter.Condition Show(Form owner, Core core, ObsFilter.Condition defaults, bool readOnly)
        {
            using (FrmEditObsFilterCondition frm = new FrmEditObsFilterCondition(owner, core, defaults, readOnly))
            {
                if (UiControls.ShowWithDim(owner, frm) == DialogResult.OK)
                {
                    var r = frm.GetSelection();
                    UiControls.Assert(r != null, "Expected selection to be present if dialogue returned OK.");

                    return(r);
                }

                return(null);
            }
        }
 private void UpdatePreview(ObsFilter.Condition r)
 {
     if (r != null)
     {
         int passed = this._core.Observations.Count(r.Preview);
         int failed = this._core.Observations.Count - passed;
         this._lblSigPeaks.Text        = "True: " + passed;
         this._lblInsigPeaks.Text      = "False: " + failed;
         this._lblSigPeaks.ForeColor   = (failed < passed) ? Color.Blue : this.ForeColor;
         this._lblInsigPeaks.ForeColor = (failed > passed) ? Color.Blue : this.ForeColor;
         this._lblSigPeaks.Visible     = true;
         this._lblInsigPeaks.Visible   = true;
     }
     else
     {
         this._lblSigPeaks.Visible   = false;
         this._lblInsigPeaks.Visible = false;
     }
 }
        /// <summary>
        /// Ctor.
        /// </summary>
        private FrmEditObsFilterCondition(Form owner, Core core, ObsFilter.Condition defaults, bool readOnly)
            : this()
        {
            this._core     = core;
            this._readOnly = readOnly;

            this.ctlTitleBar1.Text = readOnly ? "View Condition" : "Edit Condition";

            // Setup boxes
            this._cbAq    = DataSet.ForAcquisitions(core).CreateConditionBox(this._txtAq, this._btnAq);
            this._cbBatch = DataSet.ForBatches(core).CreateConditionBox(this._txtBatch, this._btnBatch);
            this._cbCond  = DataSet.ForConditions(core).CreateConditionBox(this._txtCond, this._btnCond);
            this._cbGroup = DataSet.ForGroups(core).CreateConditionBox(this._txtGroup, this._btnGroup);
            this._cbObs   = DataSet.ForObservations(core).CreateConditionBox(this._txtObs, this._btnObs);
            this._cbRep   = DataSet.ForReplicates(core).CreateConditionBox(this._txtRep, this._btnRep);
            this._cbTime  = DataSet.ForTimes(core).CreateConditionBox(this._txtTime, this._btnTime);

            this._lsoAq    = EnumComboBox.Create(this._lstAq, Filter.EElementOperator.Is);
            this._lsoBatch = EnumComboBox.Create(this._lstBatch, Filter.EElementOperator.Is);
            this._lsoCond  = EnumComboBox.Create(this._lstCond, Filter.EElementOperator.Is);
            this._lsoGroup = EnumComboBox.Create(this._lstGroup, Filter.EElementOperator.Is);
            this._lsoObs   = EnumComboBox.Create(this._lstObs, Filter.EElementOperator.Is);
            this._lsoRep   = EnumComboBox.Create(this._lstRep, Filter.EElementOperator.Is);
            this._lsoTime  = EnumComboBox.Create(this._lstDay, Filter.EElementOperator.Is);

            this._isInitialised = true;

            if (defaults == null)
            {
                this.checkBox1.Checked = false;
                this._radAnd.Checked   = true;
                this.something_Changed(null, null);
            }
            else
            {
                // Not
                this.checkBox1.Checked = defaults.Negate;
                this._radAnd.Checked   = defaults.CombiningOperator == Filter.ELogicOperator.And;
                this._radOr.Checked    = defaults.CombiningOperator == Filter.ELogicOperator.Or;

                if (defaults      is ObsFilter.ConditionAcquisition)
                {
                    var def = (ObsFilter.ConditionAcquisition)defaults;
                    this._chkAq.Checked      = true;
                    this._lsoAq.SelectedItem = def.Operator;
                    this._cbAq.SelectedItems = def.Possibilities;
                }
                else if (defaults is ObsFilter.ConditionBatch)
                {
                    var def = (ObsFilter.ConditionBatch)defaults;
                    this._chkBatch.Checked      = true;
                    this._lsoBatch.SelectedItem = def.Operator;
                    this._cbBatch.SelectedItems = def.Possibilities;
                }
                else if (defaults is ObsFilter.ConditionGroup)
                {
                    var def = (ObsFilter.ConditionGroup)defaults;
                    this._chkGroup.Checked      = true;
                    this._lsoGroup.SelectedItem = def.Operator;
                    this._cbGroup.SelectedItems = def.Possibilities;
                }
                else if (defaults is ObsFilter.ConditionRep)
                {
                    var def = (ObsFilter.ConditionRep)defaults;
                    this._chkRep.Checked      = true;
                    this._lsoRep.SelectedItem = def.Operator;
                    this._cbRep.SelectedItems = def.Possibilities;
                }
                else if (defaults is ObsFilter.ConditionTime)
                {
                    var def = (ObsFilter.ConditionTime)defaults;
                    this._chkTime.Checked      = true;
                    this._lsoTime.SelectedItem = def.Operator;
                    this._cbTime.SelectedItems = def.Possibilities;
                }
                else if (defaults is ObsFilter.ConditionObservation)
                {
                    var def = (ObsFilter.ConditionObservation)defaults;
                    this._chkObs.Checked      = true;
                    this._lsoObs.SelectedItem = def.Operator;
                    this._cbObs.SelectedItems = def.Possibilities;
                }
                else if (defaults is ObsFilter.ConditionCondition)
                {
                    var def = (ObsFilter.ConditionCondition)defaults;
                    this._chkCond.Checked      = true;
                    this._lsoCond.SelectedItem = def.Operator;
                    this._cbCond.SelectedItems = def.Possibilities;
                }
                else
                {
                    throw new SwitchException(defaults.GetType());
                }
            }

            if (readOnly)
            {
                UiControls.MakeReadOnly(this);
            }
        }
        private bool TryInvoke <T>(RadioButton radioButton, ConditionBox <T> conditionBox, EnumComboBox <Filter.EElementOperator> enumBox, Type type, out ObsFilter.Condition result)
        {
            if (!radioButton.Checked)
            {
                result = null;
                return(false);
            }

            Filter.ELogicOperator op = this._radAnd.Checked ? Filter.ELogicOperator.And : Filter.ELogicOperator.Or;

            bool negate = this.checkBox1.Checked;

            var sel = conditionBox.GetSelectionOrNull();

            this._checker.Check(conditionBox.TextBox, conditionBox.SelectionValid, "Select a condition");

            var en = enumBox.SelectedItem;

            this._checker.Check(enumBox.ComboBox, enumBox.HasSelection, "Select a condition");

            if (sel == null || !en.HasValue)
            {
                result = null;
                return(true);
            }

            Type[] types = { typeof(Filter.ELogicOperator), typeof(bool), typeof(Filter.EElementOperator), typeof(IEnumerable <T>) };
            result = (ObsFilter.Condition)type.GetConstructor(types).Invoke(new object[] { op, negate, en.Value, sel });
            return(true);
        }