private void _addFilter(CswNbtViewEditorData Return)
        {
            CswNbtViewRelationship parent = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(Request.Property.ParentArbitraryId);

            CswNbtViewRoot.forEachRelationship eachRel = relationship =>
            {
                if (parent.SecondId == relationship.SecondId)
                {
                    CswNbtViewProperty viewProp = relationship.Properties.FirstOrDefault(vp => vp.Name == Request.Property.Name);
                    if (null != viewProp)
                    {
                        if (false == _hasFilter(viewProp))
                        {
                            CurrentView.AddViewPropertyFilter(viewProp,
                                                              Conjunction: (CswEnumNbtFilterConjunction)Request.FilterConjunction,
                                                              SubFieldName: (CswEnumNbtSubFieldName)Request.FilterSubfield,
                                                              FilterMode: (CswEnumNbtFilterMode)Request.FilterMode,
                                                              Value: Request.FilterValue);
                        }
                    }
                    else
                    {
                        ICswNbtMetaDataProp Prop = null;
                        if (Request.Property.Type.Equals(CswEnumNbtViewPropType.NodeTypePropId))
                        {
                            Prop = _CswNbtResources.MetaData.getNodeTypeProp(Request.Property.NodeTypePropId);
                        }
                        else if (Request.Property.Type.Equals(CswEnumNbtViewPropType.ObjectClassPropId))
                        {
                            Prop = _CswNbtResources.MetaData.getObjectClassProp(Request.Property.ObjectClassPropId);
                        }

                        CurrentView.AddViewPropertyAndFilter(relationship, Prop,
                                                             Value: Request.FilterValue,
                                                             Conjunction: Request.FilterConjunction,
                                                             SubFieldName: (CswEnumNbtSubFieldName)Request.FilterSubfield,
                                                             FilterMode: (CswEnumNbtFilterMode)Request.FilterMode,
                                                             ShowInGrid: false       // the user is filtering on a prop not in the grid, don't show it in the grid
                                                             );
                    }
                }
            };
            CurrentView.Root.eachRelationship(eachRel, null);

            _getFilters(Return, CurrentView);
            HashSet <string> seenRels = new HashSet <string>();

            CswNbtViewRoot.forEachRelationship eachRelationship = relationship =>
            {
                if (false == seenRels.Contains(relationship.TextLabel))
                {
                    seenRels.Add(relationship.TextLabel);
                    Return.Step4.Relationships.Add(relationship);
                }
            };
            CurrentView.Root.eachRelationship(eachRelationship, null);

            Return.Step4.ViewJson = CswConvert.ToString(CurrentView.ToJson());
        }
        public override CswNbtViewEditorData HandleAction()
        {
            CswNbtViewEditorData Return = new CswNbtViewEditorData();

            if (Request.Action == "Click")
            {
                CswNbtViewNode foundNode = Request.CurrentView.FindViewNodeByArbitraryId(Request.ArbitraryId);
                if (null != foundNode)
                {
                    CswNbtView TempView = _CswNbtResources.ViewSelect.restoreView(CurrentView.ToString());
                    if (foundNode is CswNbtViewPropertyFilter)
                    {
                        Return.Step6.FilterNode = (CswNbtViewPropertyFilter)foundNode;
                    }
                    else if (foundNode is CswNbtViewRelationship)
                    {
                        CswNbtViewRelationship asRelationship = (CswNbtViewRelationship)foundNode;

                        if (asRelationship.SecondType == CswEnumNbtViewRelatedIdType.NodeTypeId)
                        {
                            CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(asRelationship.SecondId);
                            foreach (CswNbtViewProperty prop in _getProps(NodeType, TempView, new HashSet <string>(), asRelationship))
                            {
                                if (((CswEnumNbtViewRenderingMode.Tree == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.List == Request.CurrentView.ViewMode) && CswEnumNbtFieldType.Button != prop.FieldType) ||
                                    CswEnumNbtViewRenderingMode.Grid == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.Table == Request.CurrentView.ViewMode)
                                {
                                    Return.Step6.Properties.Add(prop);
                                }
                            }
                        }
                        else if (asRelationship.SecondType == CswEnumNbtViewRelatedIdType.ObjectClassId)
                        {
                            CswNbtMetaDataObjectClass ObjClass = _CswNbtResources.MetaData.getObjectClass(asRelationship.SecondId);
                            foreach (CswNbtViewProperty prop in _getProps(ObjClass, TempView, new HashSet <string>(), asRelationship))
                            {
                                if (((CswEnumNbtViewRenderingMode.Tree == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.List == Request.CurrentView.ViewMode) && CswEnumNbtFieldType.Button != prop.FieldType) ||
                                    CswEnumNbtViewRenderingMode.Grid == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.Table == Request.CurrentView.ViewMode)
                                {
                                    Return.Step6.Properties.Add(prop);
                                }
                            }
                        }
                        else
                        {
                            CswNbtMetaDataPropertySet PropSet   = _CswNbtResources.MetaData.getPropertySet(asRelationship.SecondId);
                            HashSet <string>          seenProps = new HashSet <string>();
                            foreach (CswNbtMetaDataObjectClass ObjClass in PropSet.getObjectClasses())
                            {
                                foreach (CswNbtViewProperty prop in _getProps(ObjClass, TempView, seenProps, asRelationship).OrderBy(prop => prop.TextLabel))
                                {
                                    if (((CswEnumNbtViewRenderingMode.Tree == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.List == Request.CurrentView.ViewMode) && CswEnumNbtFieldType.Button != prop.FieldType) ||
                                        CswEnumNbtViewRenderingMode.Grid == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.Table == Request.CurrentView.ViewMode)
                                    {
                                        Return.Step6.Properties.Add(prop);
                                    }
                                }
                            }
                        }

                        Return.Step6.Relationships = getViewChildRelationshipOptions(CurrentView, asRelationship.ArbitraryId);

                        Return.Step6.RelationshipNode = asRelationship;
                    }
                    else if (foundNode is CswNbtViewRoot && CurrentView.Visibility != CswEnumNbtViewVisibility.Property)  //can't add to view root on Prop view
                    {
                        TempView.Root.ChildRelationships.Clear();
                        foreach (CswNbtMetaDataNodeType NodeType in _CswNbtResources.MetaData.getNodeTypes().OrderBy(NT => NT.NodeTypeName))
                        {
                            Return.Step6.Relationships.Add(TempView.AddViewRelationship(NodeType, false));
                        }
                        foreach (CswNbtMetaDataObjectClass ObjClass in _CswNbtResources.MetaData.getObjectClasses().OrderBy(OC => OC.ObjectClass.Value))
                        {
                            Return.Step6.Relationships.Add(TempView.AddViewRelationship(ObjClass, false));
                        }
                        foreach (CswNbtMetaDataPropertySet PropSet in _CswNbtResources.MetaData.getPropertySets().OrderBy(PS => PS.Name))
                        {
                            Return.Step6.Relationships.Add(TempView.AddViewRelationship(PropSet, false));
                        }
                        Return.Step6.RootNode = (CswNbtViewRoot)foundNode;
                    }
                    else if (foundNode is CswNbtViewProperty && CswEnumNbtFieldType.Button != ((CswNbtViewProperty)foundNode).FieldType)
                    {
                        Return.Step6.PropertyNode = (CswNbtViewProperty)foundNode;
                        Request.Relationship      = (CswNbtViewRelationship)foundNode.Parent; //getFilterProps needs Request.Relationship to be populated
                        _getFilterProps(Return);
                    }
                }
            }
            else if (Request.Action == "AddProp")
            {
                ICswNbtMetaDataProp prop = null;
                if (Request.Property.Type == CswEnumNbtViewPropType.NodeTypePropId)
                {
                    prop = _CswNbtResources.MetaData.getNodeTypeProp(Request.Property.NodeTypePropId);
                }
                else
                {
                    prop = _CswNbtResources.MetaData.getObjectClassProp(Request.Property.ObjectClassPropId);
                }
                CswNbtViewRelationship relToAddTo = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(Request.Relationship.ArbitraryId);
                CurrentView.AddViewProperty(relToAddTo, prop, CurrentView.getOrderedViewProps(false).Count + 1);
            }
            else if (Request.Action == "AddRelationship")
            {
                CswNbtViewRelationship relToAddTo = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(Request.ArbitraryId);
                ICswNbtMetaDataProp    prop       = null;
                if (Request.Relationship.PropType == CswEnumNbtViewPropIdType.NodeTypePropId)
                {
                    prop = _CswNbtResources.MetaData.getNodeTypeProp(Request.Relationship.PropId);
                }
                else
                {
                    prop = _CswNbtResources.MetaData.getObjectClassProp(Request.Relationship.PropId);
                }
                CurrentView.AddViewRelationship(relToAddTo, Request.Relationship.PropOwner, prop, true);
            }
            else if (Request.Action == "AddFilter")
            {
                CswNbtViewProperty propNode = (CswNbtViewProperty)CurrentView.FindViewNodeByArbitraryId(Request.PropArbId);
                if (false == _hasFilter(propNode))
                {
                    CurrentView.AddViewPropertyFilter(propNode,
                                                      Conjunction: (CswEnumNbtFilterConjunction)Request.FilterConjunction,
                                                      SubFieldName: (CswEnumNbtSubFieldName)Request.FilterSubfield,
                                                      FilterMode: (CswEnumNbtFilterMode)Request.FilterMode,
                                                      Value: Request.FilterValue
                                                      );
                }
                Return.Step6.PropertyNode = propNode;
            }
            else if (Request.Action == "RemoveNode")
            {
                CswNbtViewNode nodeToRemove = CurrentView.FindViewNodeByArbitraryId(Request.ArbitraryId);
                CswNbtViewNode parent       = nodeToRemove.Parent;
                parent.RemoveChild(nodeToRemove);

                if (parent.ViewNodeType == CswEnumNbtViewNodeType.CswNbtViewProperty)
                {
                    Return.Step6.PropertyNode = (CswNbtViewProperty)parent;
                }
                else if (parent.ViewNodeType == CswEnumNbtViewNodeType.CswNbtViewRelationship)
                {
                    Return.Step6.RelationshipNode = (CswNbtViewRelationship)parent;
                }
                else if (parent.ViewNodeType == CswEnumNbtViewNodeType.CswNbtViewRoot)
                {
                    Return.Step6.RootNode = (CswNbtViewRoot)parent;
                }
            }
            else if (Request.Action == "UpdateView")
            {
                string grp = string.Empty;
                if (null != Request.Property)
                {
                    CswNbtViewRelationship selectedPropsParent = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(Request.Property.ParentArbitraryId);
                    Request.Property.Parent = selectedPropsParent;
                    CswNbtViewProperty rel = (CswNbtViewProperty)CurrentView.FindViewNodeByArbitraryId(Request.Property.ArbitraryId);
                    if (null == rel)
                    {
                        CswNbtViewRelationship parent = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(Request.Property.ParentArbitraryId);
                        ICswNbtMetaDataProp    prop   = null;
                        if (Request.Property.Type == CswEnumNbtViewPropType.NodeTypePropId)
                        {
                            prop = _CswNbtResources.MetaData.getNodeTypeProp(Request.Property.NodeTypePropId);
                        }
                        else
                        {
                            prop = _CswNbtResources.MetaData.getObjectClassProp(Request.Property.ObjectClassPropId);
                        }
                        rel = CurrentView.AddViewProperty(parent, prop);
                    }
                    grp = rel.TextLabel;
                }

                CurrentView.GridGroupByCol = grp;
            }

            base.Finalize(Return);
            return(Return);
        }