Ejemplo n.º 1
0
        private void _addProp(ICswNbtMetaDataProp prop)
        {
            CswNbtViewRoot.forEachRelationship eachRelationship = relationship =>
            {
                //we have to iterate a temp view, but use the relationships on the "real" view
                relationship = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(relationship.ArbitraryId);

                //For property views, we ignore the top lvl relationship
                if ((false == (relationship.Parent is CswNbtViewRoot) && CurrentView.Visibility == CswEnumNbtViewVisibility.Property) ||
                    CurrentView.Visibility != CswEnumNbtViewVisibility.Property)
                {
                    int Id = relationship.SecondId;
                    CswEnumNbtViewRelatedIdType type = relationship.SecondType;
                    if (relationship.PropOwner.Equals(CswEnumNbtViewPropOwnerType.First) && Int32.MinValue != relationship.FirstId && CurrentView.Visibility == CswEnumNbtViewVisibility.Property)
                    {
                        Id   = relationship.FirstId;
                        type = relationship.FirstType;
                    }

                    CswNbtViewProperty existingViewProp = relationship.findPropertyByName(prop.PropName);
                    if (null != existingViewProp)
                    {
                        existingViewProp.ShowInGrid = true;
                    }
                    else
                    {
                        if (null != Request.Relationship)
                        {
                            int ownerTargetId = Request.Relationship.SecondId;

                            Collection <CswNbtViewRelationship> relations = getViewChildRelationshipOptions(CurrentView, relationship.ArbitraryId);
                            foreach (CswNbtViewRelationship related in relations)
                            {
                                ICswNbtMetaDataProp relProp = related.getProp();
                                int relatedTargetId         = related.SecondId;

                                if (ownerTargetId == relatedTargetId && Request.Relationship.getRelatedType() == related.getRelatedType())
                                {
                                    if (related.getRelatedType() == CswEnumNbtViewRelatedIdType.NodeTypeId)
                                    {
                                        CswNbtMetaDataNodeType ownerNT = _CswNbtResources.MetaData.getNodeType(relatedTargetId);
                                        foreach (CswNbtMetaDataNodeTypeProp ntp in ownerNT.getNodeTypeProps().Where(ntp => ntp.PropName == prop.PropName))
                                        {
                                            CswNbtViewRelationship parentRel      = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(related.ParentArbitraryId);
                                            CswNbtViewRelationship relToAddPropTo = relationship.findChildRelationshipByNodeTypeId(relatedTargetId);
                                            if (null == relToAddPropTo)
                                            {
                                                relToAddPropTo = CurrentView.AddViewRelationship(parentRel, related.PropOwner, relProp, false);
                                            }
                                            CurrentView.AddViewProperty(relToAddPropTo, ntp);
                                        }
                                    }
                                    else if (related.getRelatedType() == CswEnumNbtViewRelatedIdType.ObjectClassId)
                                    {
                                        CswNbtMetaDataObjectClass ownerOC = _CswNbtResources.MetaData.getObjectClass(relatedTargetId);
                                        foreach (CswNbtMetaDataObjectClassProp ocp in ownerOC.getObjectClassProps().Where(ocp => ocp.PropName == prop.PropName))
                                        {
                                            CswNbtViewRelationship parentRel      = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(related.ParentArbitraryId);
                                            CswNbtViewRelationship relToAddPropTo = relationship.findChildRelationshipByObjClassId(relatedTargetId);
                                            if (null == relToAddPropTo)
                                            {
                                                relToAddPropTo = CurrentView.AddViewRelationship(parentRel, related.PropOwner, relProp, false);
                                            }
                                            CurrentView.AddViewProperty(relToAddPropTo, ocp);
                                        }
                                    }
                                    else
                                    {
                                        CswNbtMetaDataPropertySet ownerPS = _CswNbtResources.MetaData.getPropertySet(relatedTargetId);
                                        foreach (CswNbtMetaDataObjectClass oc in ownerPS.getObjectClasses())
                                        {
                                            foreach (CswNbtMetaDataNodeType nt in oc.getNodeTypes())
                                            {
                                                foreach (CswNbtMetaDataNodeTypeProp ntp in nt.getNodeTypeProps())
                                                {
                                                    if (ntp.PropName == prop.PropName)
                                                    {
                                                        CswNbtViewRelationship parentRel      = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(related.ParentArbitraryId);
                                                        CswNbtViewRelationship relToAddPropTo = relationship.findChildRelationshipByPropSetId(relatedTargetId);
                                                        if (null == relToAddPropTo)
                                                        {
                                                            relToAddPropTo = CurrentView.AddViewRelationship(parentRel, related.PropOwner, relProp, false);
                                                        }
                                                        CurrentView.AddViewProperty(relToAddPropTo, ntp);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            CswNbtViewRelationship realRelationship = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(relationship.ArbitraryId);

                            if (type.Equals(CswEnumNbtViewRelatedIdType.NodeTypeId))
                            {
                                CswNbtMetaDataNodeType     nt  = _CswNbtResources.MetaData.getNodeType(Id);
                                CswNbtMetaDataNodeTypeProp ntp = nt.getNodeTypeProp(prop.PropName);
                                if (null != ntp)
                                {
                                    CurrentView.AddViewProperty(realRelationship, ntp);
                                }
                            }
                            else if (type.Equals(CswEnumNbtViewRelatedIdType.ObjectClassId))
                            {
                                CswNbtMetaDataObjectClass     oc  = _CswNbtResources.MetaData.getObjectClass(Id);
                                CswNbtMetaDataObjectClassProp ocp = oc.getObjectClassProp(prop.PropName);
                                if (null != ocp)
                                {
                                    CurrentView.AddViewProperty(realRelationship, prop);
                                }
                                else
                                {
                                    foreach (CswNbtMetaDataNodeType nt in oc.getNodeTypes())
                                    {
                                        CswNbtMetaDataNodeTypeProp ntp = nt.getNodeTypeProp(prop.PropName);
                                        if (null != ntp)
                                        {
                                            CurrentView.AddViewProperty(realRelationship, prop);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                CswNbtMetaDataPropertySet     ps  = _CswNbtResources.MetaData.getPropertySet(Id);
                                CswNbtMetaDataObjectClassProp ocp = ps.getPropertySetProps().FirstOrDefault(PropSetProp => PropSetProp.PropName == prop.PropName);
                                if (null != ocp)
                                {
                                    CurrentView.AddViewProperty(realRelationship, prop);
                                }
                                else
                                {
                                    foreach (CswNbtMetaDataObjectClass oc in ps.getObjectClasses())
                                    {
                                        foreach (CswNbtMetaDataNodeType nt in oc.getNodeTypes())
                                        {
                                            CswNbtMetaDataNodeTypeProp ntp = nt.getNodeTypeProp(prop.PropName);
                                            if (null != ntp)
                                            {
                                                CurrentView.AddViewProperty(realRelationship, prop);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
            CswNbtView tempView = _CswNbtResources.ViewSelect.restoreView(CurrentView.ToString());

            tempView.Root.eachRelationship(eachRelationship, null);
        }
        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);
        }
        private void _addRelationship()
        {
            if (Request.Relationship.PropOwner == CswEnumNbtViewPropOwnerType.First && Int32.MinValue != Request.Relationship.FirstId)
            {
                CswNbtViewRelationship parentToAddTo = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(Request.Relationship.ParentArbitraryId);
                ICswNbtMetaDataProp    prop          = null;
                if (Request.Relationship.PropType == CswEnumNbtViewPropIdType.NodeTypePropId)
                {
                    prop = _CswNbtResources.MetaData.getNodeTypeProp(Request.Relationship.PropId);
                }
                else
                {
                    prop = _CswNbtResources.MetaData.getObjectClassProp(Request.Relationship.PropId);
                }

                if (null != prop)
                {
                    CurrentView.AddViewRelationship(parentToAddTo, Request.Relationship.PropOwner, prop, true);
                }
            }
            else
            {
                if (Request.Relationship.SecondType == CswEnumNbtViewRelatedIdType.NodeTypeId)
                {
                    CswNbtMetaDataNodeType nt     = _CswNbtResources.MetaData.getNodeType(Request.Relationship.SecondId);
                    CswNbtViewRelationship parent = null;
                    if (CurrentView.Visibility == CswEnumNbtViewVisibility.Property)
                    {
                        parent = _addPropViewRelationshiop(CurrentView, Request.Relationship);
                    }
                    else
                    {
                        parent = CurrentView.AddViewRelationship(nt, true);
                    }
                    _addNameTemplateProps(CurrentView, parent, nt);
                }
                else if (Request.Relationship.SecondType == CswEnumNbtViewRelatedIdType.ObjectClassId)
                {
                    CswNbtMetaDataObjectClass oc     = _CswNbtResources.MetaData.getObjectClass(Request.Relationship.SecondId);
                    CswNbtViewRelationship    parent = null;
                    if (CurrentView.Visibility == CswEnumNbtViewVisibility.Property)
                    {
                        parent = _addPropViewRelationshiop(CurrentView, Request.Relationship);
                    }
                    else
                    {
                        parent = CurrentView.AddViewRelationship(oc, true);
                    }
                    foreach (CswNbtMetaDataNodeType NodeType in oc.getNodeTypes())
                    {
                        _addNameTemplateProps(CurrentView, parent, NodeType);
                    }
                }
                else
                {
                    CswNbtMetaDataPropertySet ps     = _CswNbtResources.MetaData.getPropertySet(Request.Relationship.SecondId);
                    CswNbtViewRelationship    parent = null;
                    if (CurrentView.Visibility == CswEnumNbtViewVisibility.Property)
                    {
                        parent = _addPropViewRelationshiop(CurrentView, Request.Relationship);
                    }
                    else
                    {
                        parent = CurrentView.AddViewRelationship(ps, true);
                    }
                    foreach (CswNbtMetaDataObjectClass oc in ps.getObjectClasses())
                    {
                        foreach (CswNbtMetaDataNodeType NodeType in oc.getNodeTypes())
                        {
                            _addNameTemplateProps(CurrentView, parent, NodeType);
                        }
                    }
                }
            }
        }