예제 #1
0
        //-----------------------------------------------------------------------
        public DataItem Filter(string filter, Regex regex, bool caseSensitive, bool showMatchesOnly)
        {
            RefreshChildren();

            DataItem foundInChild = null;

            if (Children.Count > 0)
            {
                foreach (var item in Children)
                {
                    var match = item.Filter(filter, regex, caseSensitive, showMatchesOnly);

                    if (match != null)
                    {
                        foundInChild = match;
                    }
                }

                if (foundInChild != null && !showMatchesOnly)
                {
                    if ((this is StructItem && Parent is CollectionChildItem) || (this is CollectionChildItem && ((CollectionChildItem)this).WrappedItem is StructItem))
                    {
                        foreach (var item in Descendants)
                        {
                            item.IsSearchFiltered = false;
                            item.RaisePropertyChangedEvent("IsVisible");
                        }
                    }
                }
            }

            bool matchFound = false;

            if (filter == null)
            {
                m_isSearchFiltered = false;
                IsFilterMatched    = true;
            }
            else
            {
                if (IsVisibleFromBindings)
                {
                    List <string> stringsToCheck = new List <string>();

                    if (caseSensitive)
                    {
                        stringsToCheck.Add(Name);

                        if (!matchFound && IsPrimitive)
                        {
                            var value = GetValue();
                            if (value != null)
                            {
                                stringsToCheck.Add(value);
                            }
                        }
                        if (this is ComplexDataItem)
                        {
                            var attr = (this as ComplexDataItem).Attributes;
                            foreach (var att in attr)
                            {
                                stringsToCheck.Add(att.Name);

                                var value = att.GetValue();
                                if (value != null)
                                {
                                    stringsToCheck.Add(value);
                                }
                            }
                        }
                    }
                    else
                    {
                        stringsToCheck.Add(Name.ToLower());

                        if (!matchFound && IsPrimitive)
                        {
                            var value = GetValue()?.ToLower();
                            if (value != null)
                            {
                                stringsToCheck.Add(value);
                            }
                        }
                        if (this is ComplexDataItem)
                        {
                            var attr = (this as ComplexDataItem).Attributes;
                            foreach (var att in attr)
                            {
                                stringsToCheck.Add(att.Name.ToLower());

                                var value = att.GetValue()?.ToLower();
                                if (value != null)
                                {
                                    stringsToCheck.Add(value);
                                }
                            }
                        }
                    }

                    foreach (var s in stringsToCheck)
                    {
                        if (string.IsNullOrWhiteSpace(s))
                        {
                            continue;
                        }

                        if (regex != null)
                        {
                            matchFound = regex.IsMatch(s);
                        }
                        else
                        {
                            matchFound = s.Contains(filter);
                        }

                        if (matchFound)
                        {
                            break;
                        }
                    }

                    m_isSearchFiltered = !(matchFound || foundInChild != null);
                }
                else
                {
                    m_isSearchFiltered = true;
                    foundInChild       = null;
                }

                IsFilterMatched = matchFound;
            }

            if (foundInChild != null)
            {
                IsExpanded = true;
            }

            if (this is GraphNodeItem)
            {
                var gni = this as GraphNodeItem;

                if (foundInChild != null)
                {
                    IsFilterMatched = true;
                }
            }

            if (this is GraphReferenceItem)
            {
                var gri = this as GraphReferenceItem;
                if (gri.WrappedItem != null && !gri.IsCircular())
                {
                    gri.WrappedItem.Filter(filter, regex, caseSensitive, showMatchesOnly);
                }
            }

            RaisePropertyChangedEvent("IsVisible");

            if (matchFound)
            {
                return(this);
            }
            else
            {
                return(foundInChild);
            }
        }
예제 #2
0
        //-----------------------------------------------------------------------
        public void UpdateVisibleIfBinding()
        {
            foreach (var group in VisibleIfStatements)
            {
                foreach (var stmnt in group)
                {
                    if (stmnt.Target != null)
                    {
                        stmnt.Target.PropertyChanged -= VisibilityPropertyChanged;
                    }
                }
            }
            VisibleIfStatements.Clear();

            if (Definition.VisibleIf != null)
            {
                // decompose into or groups
                var orgroups = Definition.VisibleIf.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var orgroup in orgroups)
                {
                    var group = new List <Statement>();
                    VisibleIfStatements.Add(group);

                    // decompose into and statements
                    var statements = orgroup.Split(new string[] { "&&" }, StringSplitOptions.RemoveEmptyEntries);

                    // extract the linked element and value from the boolean and setup the binding
                    foreach (var statement in statements)
                    {
                        var stmnt = new Statement(statement);
                        group.Add(stmnt);

                        // find the referenced element and bind to it
                        DataItem current = FirstComplexParent(this);
                        foreach (var part in stmnt.TargetPath)
                        {
                            if (part == "Root")
                            {
                                current = Root;
                            }
                            else if (part == "Parent")
                            {
                                current = FirstComplexParent(current);
                            }
                            else
                            {
                                // Combine children and attributes into one block
                                List <DataItem> collection = current.Children.ToList();
                                if (current is ComplexDataItem)
                                {
                                    collection.AddRange((current as ComplexDataItem).Attributes);
                                }

                                // If we are an attribute then replace the children list with the parent attribute list
                                if (current.Parent is ComplexDataItem && ((ComplexDataItem)current.Parent).Attributes.Contains(this))
                                {
                                    collection = ((ComplexDataItem)current.Parent).Attributes.ToList();
                                }

                                current = collection.FirstOrDefault(e => e.Name == part);
                            }

                            if (current == null)
                            {
                                break;
                            }
                        }

                        if (current != null)
                        {
                            stmnt.SetTarget(current);
                            current.PropertyChanged += VisibilityPropertyChanged;
                        }
                    }
                }
            }
        }