예제 #1
0
        public AndPredicate Read_AndPredicate(XmlNode nodeRepresentation)
        {
            AndPredicate predicate = new AndPredicate();

            foreach (XmlNode childNode in nodeRepresentation.ChildNodes)
            {
                TextPredicate child = this.ReadTextPredicate(childNode);
                predicate.AddChild(child);
            }
            return(predicate);
        }
        private void AndButton_Clicked(object sender, EventArgs e)
        {
            AndPredicate  and   = new AndPredicate();
            TextPredicate child = this.getPendingChildPredicate();

            if (child != null)
            {
                and.AddChild(child);
                this.openPredicates.Add(and);
            }
            else
            {
                this.addChild(and);
            }
            this.updateLayout();
        }
        // add the given predicate as a child of the leafmost existing predicate
        private void addChild(TextPredicate predicate)
        {
            if (this.openPredicates.Count < 1)
            {
                // no predicates already exist, this one becomes the primary one
                this.openPredicates.Add(predicate);
                return;
            }
            TextPredicate last = this.openPredicates.Last();
            OrPredicate   or   = last as OrPredicate;

            if (or != null)
            {
                // we have a pending 'or'; add it here
                or.AddChild(predicate);
                return;
            }
            AndPredicate and = last as AndPredicate;

            if (and != null)
            {
                // we have a pending 'and'; add it here
                and.AddChild(predicate);
                return;
            }
            NotPredicate not = last as NotPredicate;

            if (not != null)
            {
                // we have a pending 'not'; add it here
                not.Child = predicate;
                return;
            }
            if (last == null)
            {
                // We have an empty spot to add this predicate to
                // This user is expected to attach this to a parent later
                // If the user doesn't attach this to a parent later, we will for them
                this.openPredicates.RemoveAt(this.openPredicates.Count - 1);
                this.openPredicates.Add(predicate);
                return;
            }
            // error; do nothing
        }