/// <summary>
        /// Gets the value corresponding to a value property.
        /// The value type can be obtained from <see cref="ValuePropertyTypeTable"/>.
        /// </summary>
        /// <param name="propertyName">Property name.</param>
        /// <param name="value">Value of the property upon return.</param>
        /// <param name="minValue">Min value of the property upon return. Only applies to enum and booleans.</param>
        /// <param name="maxValue">Max value of the property upon return. Only applies to enum and booleans.</param>
        public virtual void PropertyToValue(string propertyName, out object value, out int minValue, out int maxValue)
        {
            Debug.Assert(!string.IsNullOrEmpty(propertyName));
            Debug.Assert(ValuePropertyTypeTable.ContainsKey(propertyName));

            value    = null;
            minValue = -1;
            maxValue = -1;
            bool IsHandled = false;

            switch (ValuePropertyTypeTable[propertyName])
            {
            case ValuePropertyType.Boolean:
            case ValuePropertyType.Enum:
                value = NodeTreeHelper.GetEnumValue(Node, propertyName);
                NodeTreeHelper.GetEnumRange(Node.GetType(), propertyName, out minValue, out maxValue);
                IsHandled = true;
                break;

            case ValuePropertyType.String:
                value     = NodeTreeHelper.GetString(Node, propertyName);
                IsHandled = true;
                break;

            case ValuePropertyType.Guid:
                value     = NodeTreeHelper.GetGuid(Node, propertyName);
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);
        }
        /// <summary>
        /// Checks that a frame is correctly constructed.
        /// </summary>
        /// <param name="nodeType">Type of the node this frame can describe.</param>
        /// <param name="nodeTemplateTable">Table of templates with all frames.</param>
        /// <param name="commentFrameCount">Number of comment frames found so far.</param>
        public override bool IsValid(Type nodeType, FrameTemplateReadOnlyDictionary nodeTemplateTable, ref int commentFrameCount)
        {
            bool IsValid = true;

            IsValid &= base.IsValid(nodeType, nodeTemplateTable, ref commentFrameCount);
            IsValid &= Items != null && Items.Count > 0;
            IsValid &= NodeTreeHelper.IsEnumProperty(nodeType, PropertyName) || NodeTreeHelper.IsBooleanProperty(nodeType, PropertyName);

            NodeTreeHelper.GetEnumRange(nodeType, PropertyName, out int Min, out int Max);
            IsValid &= Min == 0;
            IsValid &= Max + 1 == Items.Count;

            foreach (IFrameKeywordFrame Item in Items)
            {
                IsValid &= Item.IsValid(nodeType, nodeTemplateTable, ref commentFrameCount);
            }

            Debug.Assert(IsValid);
            return(IsValid);
        }
Exemple #3
0
        private protected virtual void ExecuteChangeDiscreteValue(WriteableChangeDiscreteValueOperation operation)
        {
            Node   ParentNode   = operation.ParentNode;
            string PropertyName = operation.PropertyName;
            int    NewValue     = operation.NewValue;

            IWriteableNodeState State = (IWriteableNodeState)GetState(ParentNode);

            Debug.Assert(State != null);
            Debug.Assert(State.ValuePropertyTypeTable.ContainsKey(PropertyName));
            Debug.Assert(State.ValuePropertyTypeTable[PropertyName] == Constants.ValuePropertyType.Boolean || State.ValuePropertyTypeTable[PropertyName] == Constants.ValuePropertyType.Enum);

            int OldValue = NodeTreeHelper.GetEnumValue(State.Node, PropertyName);

            NodeTreeHelper.GetEnumRange(Type.FromGetType(State.Node), PropertyName, out int Min, out int Max);

            Debug.Assert(NewValue >= Min && NewValue <= Max);

            NodeTreeHelper.SetEnumValue(State.Node, PropertyName, NewValue);

            operation.Update(State, OldValue);

            NotifyDiscreteValueChanged(operation);
        }
        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());
        }