public void SetBooleanExpression(BooleanFunctionViewModel vm)
 {
     _Model          = (BooleanFunction)vm.Model;
     _Model.Consumer = this.Parent.Model;
     vm.Parent       = this;
     SetModelToParent();
     if (_Model is ComparisonOperator)
     {
         this.IsCommandPanelVisible = true;
         this.View = new ComparisonOperatorView((ComparisonOperatorViewModel)vm);
     }
     else if (_Model is BooleanOperator)
     {
         this.IsCommandPanelVisible = false;
         this.View = new BooleanOperatorView((BooleanOperatorViewModel)vm);
     }
 }
Ejemplo n.º 2
0
 public void RemoveChildOperator(BooleanFunctionViewModel child)
 {
     this.Operands.Remove(child);
 }
Ejemplo n.º 3
0
        private void RemoveBooleanOperator()
        {
            BooleanOperator model = this.Model as BooleanOperator;

            if (model == null)
            {
                return;
            }

            if (model.IsRoot)
            {
                if (this.Parent is BooleanExpressionViewModel)
                {
                    ((BooleanExpressionViewModel)this.Parent).ClearBooleanExpression();
                }
            }
            else
            {
                BooleanOperatorViewModel parent = this.Parent as BooleanOperatorViewModel;
                if (parent == null)
                {
                    return;
                }

                BooleanOperator consumer = model.Consumer as BooleanOperator;
                if (consumer == null)
                {
                    return;
                }

                if (consumer.Operands.Count == 0)
                {
                    return;
                }

                consumer.Operands.Remove(model);
                parent.RemoveChildOperator(this);

                if (parent.Operands.Count == 1)
                {
                    BooleanFunctionViewModel orphan = parent.Operands[0];

                    if (parent.Parent is BooleanExpressionViewModel)
                    {
                        orphan.Name = parent.Name;
                        ((BooleanExpressionViewModel)parent.Parent).SetBooleanExpression(orphan);
                    }
                    else if (parent.Parent is BooleanOperatorViewModel)
                    {
                        orphan.Parent         = parent.Parent;
                        orphan.Model.Consumer = parent.Parent.Model;

                        int index_to_replace = ((BooleanOperator)consumer.Consumer).Operands.IndexOf(consumer);
                        ((BooleanOperator)consumer.Consumer).Operands.RemoveAt(index_to_replace);
                        ((BooleanOperator)consumer.Consumer).Operands.Insert(index_to_replace, (BooleanOperator)orphan.Model);

                        index_to_replace = ((BooleanOperatorViewModel)parent.Parent).Operands.IndexOf(parent);
                        ((BooleanOperatorViewModel)parent.Parent).Operands.RemoveAt(index_to_replace);
                        ((BooleanOperatorViewModel)parent.Parent).Operands.Insert(index_to_replace, orphan);
                    }
                }
            }
        }