private static bool OnUpdate(Node node, WalkCallbacks <string> callback, string data) { IList <string> PropertyNames = NodeTreeHelper.EnumChildNodeProperties(node); foreach (string PropertyName in PropertyNames) { if (NodeTreeHelperOptional.IsOptionalChildNodeProperty(node, PropertyName, out Type ChildNodeType)) { NodeTreeHelperOptional.GetChildNode(node, PropertyName, out bool IsAssigned, out Node ChildNode); if (!IsAssigned) { if (ChildNode is null) { Node NewChildNode = NodeHelper.CreateDefaultFromType(ChildNodeType); NodeTreeHelperOptional.SetOptionalChildNode(node, PropertyName, NewChildNode); NodeTreeHelperOptional.UnassignChildNode(node, PropertyName); } } else if (ChildNode is null) { Node NewChildNode = NodeHelper.CreateDefaultFromType(ChildNodeType); NodeTreeHelperOptional.SetOptionalChildNode(node, PropertyName, NewChildNode); } else if (NodeHelper.IsDefaultNode(ChildNode)) { } } } return(true); }
private protected virtual bool IsNodeTreeValid(Node node) { Type ChildNodeType; IList <string> PropertyNames = NodeTreeHelper.EnumChildNodeProperties(node); bool IsValid = true; foreach (string PropertyName in PropertyNames) { if (NodeTreeHelperChild.IsChildNodeProperty(node, PropertyName, out ChildNodeType)) { IsValid &= InvariantFailed(IsNodeTreeChildNodeValid(node, PropertyName)); } else if (NodeTreeHelperOptional.IsOptionalChildNodeProperty(node, PropertyName, out ChildNodeType)) { IsValid &= InvariantFailed(IsNodeTreeOptionalNodeValid(node, PropertyName)); } else if (NodeTreeHelperList.IsNodeListProperty(node, PropertyName, out ChildNodeType)) { IsValid &= InvariantFailed(IsNodeTreeListValid(node, PropertyName)); } else if (NodeTreeHelperBlockList.IsBlockListProperty(node, PropertyName, /*out Type ChildInterfaceType,*/ out ChildNodeType)) { IsValid &= InvariantFailed(IsNodeTreeBlockListValid(node, PropertyName)); } } return(IsValid); }
private protected virtual void SetNodeTypeToDefault(IFrameTemplateDictionary dictionary, Type nodeType) { Debug.Assert(dictionary.ContainsKey(nodeType)); Debug.Assert(dictionary[nodeType] == null); FrameHorizontalPanelFrame RootFrame = (FrameHorizontalPanelFrame)CreateHorizontalPanelFrame(); FrameNodeTemplate RootTemplate = (FrameNodeTemplate)CreateNodeTemplate(); RootTemplate.NodeType = nodeType; RootTemplate.Root = RootFrame; // Set the template, even if empty, in case the node recursively refers to itself (ex: expressions). dictionary[nodeType] = RootTemplate; RootFrame.Items.Add(CreateCommentFrame()); Type ChildNodeType; IList <string> Properties = NodeTreeHelper.EnumChildNodeProperties(nodeType); foreach (string PropertyName in Properties) { bool IsHandled = false; if (NodeTreeHelperChild.IsChildNodeProperty(nodeType, PropertyName, out ChildNodeType)) { FramePlaceholderFrame NewFrame = (FramePlaceholderFrame)CreatePlaceholderFrame(); NewFrame.PropertyName = PropertyName; RootFrame.Items.Add(NewFrame); IsHandled = true; } else if (NodeTreeHelperOptional.IsOptionalChildNodeProperty(nodeType, PropertyName, out ChildNodeType)) { FrameOptionalFrame NewFrame = (FrameOptionalFrame)CreateOptionalFrame(); NewFrame.PropertyName = PropertyName; RootFrame.Items.Add(NewFrame); IsHandled = true; } else if (NodeTreeHelperList.IsNodeListProperty(nodeType, PropertyName, out Type ListNodeType)) { FrameHorizontalListFrame NewFrame = (FrameHorizontalListFrame)CreateHorizontalListFrame(); NewFrame.PropertyName = PropertyName; RootFrame.Items.Add(NewFrame); IsHandled = true; } else if (NodeTreeHelperBlockList.IsBlockListProperty(nodeType, PropertyName, out Type ChildInterfaceType, out Type ChildItemType)) { FrameHorizontalBlockListFrame NewFrame = (FrameHorizontalBlockListFrame)CreateHorizontalBlockListFrame(); NewFrame.PropertyName = PropertyName; RootFrame.Items.Add(NewFrame); IsHandled = true; }
private protected virtual void AddBlockNodeTypes(FrameTemplateDictionary dictionary, Type nodeType) { IList <string> Properties = NodeTreeHelper.EnumChildNodeProperties(nodeType); foreach (string PropertyName in Properties) { if (NodeTreeHelperBlockList.IsBlockListProperty(nodeType, PropertyName, /*out Type ChildInterfaceType,*/ out Type ChildItemType)) { Type BlockListType = NodeTreeHelperBlockList.BlockListBlockType(nodeType, PropertyName); if (!dictionary.ContainsKey(BlockListType)) { dictionary.Add(BlockListType, null); } } } }
private protected virtual void BrowseChildrenOfNode(IReadOnlyBrowseContext browseNodeContext, INode node) { IList <string> PropertyNames = NodeTreeHelper.EnumChildNodeProperties(node); foreach (string PropertyName in PropertyNames) { INode ChildNode; Type ChildInterfaceType, ChildNodeType; IReadOnlyList <INode> ChildNodeList; IReadOnlyList <INodeTreeBlock> ChildBlockList; bool IsHandled = false; if (NodeTreeHelperChild.IsChildNodeProperty(node, PropertyName, out ChildNodeType)) { NodeTreeHelperChild.GetChildNode(node, PropertyName, out ChildNode); Debug.Assert(ChildNode != null); IReadOnlyBrowsingPlaceholderNodeIndex ChildNodeIndex = CreateChildNodeIndex(browseNodeContext, node, PropertyName, ChildNode); // Create a collection containing one index for this child node. IReadOnlyIndexCollection IndexCollection = CreatePlaceholderIndexCollection(browseNodeContext, PropertyName, ChildNodeIndex); browseNodeContext.AddIndexCollection(IndexCollection); IsHandled = true; } else if (NodeTreeHelperOptional.IsOptionalChildNodeProperty(node, PropertyName, out ChildNodeType)) { IReadOnlyBrowsingOptionalNodeIndex OptionalNodeIndex = CreateOptionalNodeIndex(browseNodeContext, node, PropertyName); // Create a collection containing one index for this optional node. IReadOnlyIndexCollection IndexCollection = CreateOptionalIndexCollection(browseNodeContext, PropertyName, OptionalNodeIndex); browseNodeContext.AddIndexCollection(IndexCollection); IsHandled = true; } else if (NodeTreeHelperList.IsNodeListProperty(node, PropertyName, out ChildNodeType)) { NodeTreeHelperList.GetChildNodeList(node, PropertyName, out ChildNodeList); Debug.Assert(ChildNodeList != null); // Create a collection containing indexes for each children. IReadOnlyIndexCollection IndexCollection = BrowseNodeList(browseNodeContext, node, PropertyName, ChildNodeList); browseNodeContext.AddIndexCollection(IndexCollection); IsHandled = true; } else if (NodeTreeHelperBlockList.IsBlockListProperty(node, PropertyName, out ChildInterfaceType, out ChildNodeType)) { NodeTreeHelperBlockList.GetChildBlockList(node, PropertyName, out ChildBlockList); Debug.Assert(ChildBlockList != null); // Create a collection containing indexes for each child blocks and their children. IReadOnlyIndexCollection IndexCollection = BrowseNodeBlockList(browseNodeContext, node, PropertyName, ChildBlockList); browseNodeContext.AddIndexCollection(IndexCollection); IsHandled = true; } else if (NodeTreeHelper.IsBooleanProperty(node, PropertyName)) { browseNodeContext.AddValueProperty(PropertyName, ValuePropertyType.Boolean); IsHandled = true; } else if (NodeTreeHelper.IsEnumProperty(node, PropertyName)) { browseNodeContext.AddValueProperty(PropertyName, ValuePropertyType.Enum); IsHandled = true; } else if (NodeTreeHelper.IsStringProperty(node, PropertyName)) { browseNodeContext.AddValueProperty(PropertyName, ValuePropertyType.String); IsHandled = true; } else if (NodeTreeHelper.IsGuidProperty(node, PropertyName)) { browseNodeContext.AddValueProperty(PropertyName, ValuePropertyType.Guid); IsHandled = true; } else if (NodeTreeHelper.IsDocumentProperty(node, PropertyName)) { IsHandled = true; // Ignore the doc node. } Debug.Assert(IsHandled); } }
private protected virtual void SetNodeTypeToDefault(FrameTemplateDictionary dictionary, Type nodeType) { Debug.Assert(dictionary.ContainsKey(nodeType)); Debug.Assert(dictionary[nodeType] == null); FrameHorizontalPanelFrame RootFrame = (FrameHorizontalPanelFrame)CreateHorizontalPanelFrame(); FrameNodeTemplate RootTemplate = (FrameNodeTemplate)CreateNodeTemplate(); RootTemplate.NodeType = nodeType; RootTemplate.Root = RootFrame; // Set the template, even if empty, in case the node recursively refers to itself (ex: expressions). dictionary[nodeType] = RootTemplate; RootFrame.Items.Add(CreateCommentFrame()); Type ChildNodeType; IList <string> Properties = NodeTreeHelper.EnumChildNodeProperties(nodeType); foreach (string PropertyName in Properties) { bool IsHandled = false; if (NodeTreeHelperChild.IsChildNodeProperty(nodeType, PropertyName, out ChildNodeType)) { FramePlaceholderFrame NewFrame = (FramePlaceholderFrame)CreatePlaceholderFrame(); NewFrame.PropertyName = PropertyName; RootFrame.Items.Add(NewFrame); IsHandled = true; } else if (NodeTreeHelperOptional.IsOptionalChildNodeProperty(nodeType, PropertyName, out ChildNodeType)) { FrameOptionalFrame NewFrame = (FrameOptionalFrame)CreateOptionalFrame(); NewFrame.PropertyName = PropertyName; RootFrame.Items.Add(NewFrame); IsHandled = true; } else if (NodeTreeHelperList.IsNodeListProperty(nodeType, PropertyName, out Type ListNodeType)) { FrameHorizontalListFrame NewFrame = (FrameHorizontalListFrame)CreateHorizontalListFrame(); NewFrame.PropertyName = PropertyName; RootFrame.Items.Add(NewFrame); IsHandled = true; } else if (NodeTreeHelperBlockList.IsBlockListProperty(nodeType, PropertyName, /*out Type ChildInterfaceType,*/ out Type ChildItemType)) { FrameHorizontalBlockListFrame NewFrame = (FrameHorizontalBlockListFrame)CreateHorizontalBlockListFrame(); NewFrame.PropertyName = PropertyName; RootFrame.Items.Add(NewFrame); IsHandled = true; } else if (NodeTreeHelper.IsBooleanProperty(nodeType, PropertyName)) { FrameDiscreteFrame NewDiscreteFrame = (FrameDiscreteFrame)CreateDiscreteFrame(); NewDiscreteFrame.PropertyName = PropertyName; FrameKeywordFrame KeywordFalseFrame = (FrameKeywordFrame)CreateKeywordFrame(); KeywordFalseFrame.Text = $"{PropertyName}=False"; NewDiscreteFrame.Items.Add(KeywordFalseFrame); FrameKeywordFrame KeywordTrueFrame = (FrameKeywordFrame)CreateKeywordFrame(); KeywordTrueFrame.Text = $"{PropertyName}=True"; NewDiscreteFrame.Items.Add(KeywordTrueFrame); RootFrame.Items.Add(NewDiscreteFrame); IsHandled = true; } else if (NodeTreeHelper.IsEnumProperty(nodeType, PropertyName)) { NodeTreeHelper.GetEnumRange(nodeType, PropertyName, out int Min, out int Max); FrameDiscreteFrame NewDiscreteFrame = (FrameDiscreteFrame)CreateDiscreteFrame(); NewDiscreteFrame.PropertyName = PropertyName; for (int i = Min; i <= Max; i++) { FrameKeywordFrame KeywordFrame = (FrameKeywordFrame)CreateKeywordFrame(); KeywordFrame.Text = $"{PropertyName}={i}"; NewDiscreteFrame.Items.Add(KeywordFrame); } RootFrame.Items.Add(NewDiscreteFrame); IsHandled = true; } else if (NodeTreeHelper.IsStringProperty(nodeType, PropertyName)) { FrameTextValueFrame NewDiscreteFrame = (FrameTextValueFrame)CreateTextValueFrame(); NewDiscreteFrame.PropertyName = PropertyName; RootFrame.Items.Add(NewDiscreteFrame); IsHandled = true; } else if (NodeTreeHelper.IsGuidProperty(nodeType, PropertyName)) { IsHandled = true; } else if (NodeTreeHelper.IsDocumentProperty(nodeType, PropertyName)) { IsHandled = true; } Debug.Assert(IsHandled); } RootFrame.UpdateParent(RootTemplate, GetRoot()); }
static void BrowseNode(ReadOnlyController controller, IReadOnlyIndex index, Stats stats) { Assert.That(index != null, "ReadOnly #0"); Assert.That(controller.Contains(index), "ReadOnly #1"); IReadOnlyNodeState State = controller.IndexToState(index); Assert.That(State != null, "ReadOnly #2"); Assert.That(State.ParentIndex == index, "ReadOnly #4"); Node Node; if (State is IReadOnlyPlaceholderNodeState AsPlaceholderState) { Node = AsPlaceholderState.Node; } else if (State is IReadOnlyPatternState AsPatternState) { Node = AsPatternState.Node; } else if (State is IReadOnlySourceState AsSourceState) { Node = AsSourceState.Node; } else { Assert.That(State is IReadOnlyOptionalNodeState, "ReadOnly #5"); IReadOnlyOptionalNodeState AsOptionalState = (IReadOnlyOptionalNodeState)State; IReadOnlyOptionalInner ParentInner = AsOptionalState.ParentInner; //Assert.That(ParentInner.IsAssigned, "ReadOnly #6"); Node = AsOptionalState.Node; } stats.NodeCount++; Type ChildNodeType; IList <string> PropertyNames = NodeTreeHelper.EnumChildNodeProperties(Node); foreach (string PropertyName in PropertyNames) { if (NodeTreeHelperChild.IsChildNodeProperty(Node, PropertyName, out ChildNodeType)) { stats.PlaceholderNodeCount++; IReadOnlyPlaceholderInner Inner = (IReadOnlyPlaceholderInner)State.PropertyToInner(PropertyName); IReadOnlyNodeState ChildState = Inner.ChildState; IReadOnlyIndex ChildIndex = ChildState.ParentIndex; BrowseNode(controller, ChildIndex, stats); } else if (NodeTreeHelperOptional.IsOptionalChildNodeProperty(Node, PropertyName, out ChildNodeType)) { stats.OptionalNodeCount++; NodeTreeHelperOptional.GetChildNode(Node, PropertyName, out bool IsAssigned, out Node ChildNode); Debug.Assert(ChildNode is not null); //if (IsAssigned) { if (IsAssigned) { stats.AssignedOptionalNodeCount++; } IReadOnlyOptionalInner Inner = (IReadOnlyOptionalInner)State.PropertyToInner(PropertyName); IReadOnlyNodeState ChildState = Inner.ChildState; IReadOnlyIndex ChildIndex = ChildState.ParentIndex; BrowseNode(controller, ChildIndex, stats); } /*else * stats.NodeCount++;*/ } else if (NodeTreeHelperList.IsNodeListProperty(Node, PropertyName, out ChildNodeType)) { stats.ListCount++; IReadOnlyListInner Inner = (IReadOnlyListInner)State.PropertyToInner(PropertyName); for (int i = 0; i < Inner.StateList.Count; i++) { stats.PlaceholderNodeCount++; IReadOnlyPlaceholderNodeState ChildState = Inner.StateList[i]; IReadOnlyIndex ChildIndex = ChildState.ParentIndex; BrowseNode(controller, ChildIndex, stats); } } else if (NodeTreeHelperBlockList.IsBlockListProperty(Node, PropertyName, /*out Type ChildInterfaceType,*/ out ChildNodeType)) { stats.BlockListCount++; IReadOnlyBlockListInner Inner = (IReadOnlyBlockListInner)State.PropertyToInner(PropertyName); for (int BlockIndex = 0; BlockIndex < Inner.BlockStateList.Count; BlockIndex++) { IReadOnlyBlockState BlockState = Inner.BlockStateList[BlockIndex]; stats.PlaceholderNodeCount++; BrowseNode(controller, BlockState.PatternIndex, stats); stats.PlaceholderNodeCount++; BrowseNode(controller, BlockState.SourceIndex, stats); for (int i = 0; i < BlockState.StateList.Count; i++) { stats.PlaceholderNodeCount++; IReadOnlyPlaceholderNodeState ChildState = BlockState.StateList[i]; IReadOnlyIndex ChildIndex = ChildState.ParentIndex; BrowseNode(controller, ChildIndex, stats); } } } else { Type NodeType = Type.FromGetType(Node); PropertyInfo Info = NodeType.GetProperty(PropertyName); if (Info.PropertyType.IsTypeof <Document>()) { } else if (Info.PropertyType.IsTypeof <bool>()) { } else if (Info.PropertyType.IsEnum) { } else if (Info.PropertyType.IsTypeof <string>()) { } else if (Info.PropertyType.IsTypeof <Guid>()) { } else { Assert.That(false, $"State Tree unexpected property: {Info.PropertyType.Name}"); } } } }