/// <summary>
 /// Recursively applies the cloning logic to the registered setters.
 /// </summary>
 public IPropertyBuildContext <TChild> CreateChildContext <TChild>(string name, GetInstanceDelegate <TChild> getHandler, SetInstanceDelegate <TChild> setHandler, AssignmentPolicy policy) where TChild : class
 {
     if (parent.useClone)
     {
         return(new OuterWrappingBuildContext <T1, T2, TChild>(this,
                                                               context.CreateChildContext(name, getHandler, setHandler, policy)));
     }
     else
     {
         return(context.CreateChildContext(name, getHandler, setHandler, policy));
     }
 }
예제 #2
0
        /// <summary>
        /// Method that populates the <see cref="IPropertyMap"/> for edge styles in a given context.
        /// </summary>
        /// <remarks>
        /// This implementation uses <see cref="GetStylePropertyMapBuilder"/> to retrieve the builder for the style.
        /// </remarks>
        /// <param name="context">The context to use for queries.</param>
        protected virtual void BuildStyleProperties(IPropertyBuildContext <IEdge> context)
        {
            IEdge edge = context.CurrentInstance;

            if (edge != null)
            {
                IEdgeStyle style = edge.Style;
                if (style != null)
                {
                    IPropertyMapBuilder propertyBuilder = GetStylePropertyMapBuilder(context, style);
                    if (propertyBuilder != null)
                    {
                        GetInstanceDelegate <IEdgeStyle> styleGetter = delegate { return(context.CurrentInstance.Style); };
                        SetInstanceDelegate <IEdgeStyle> styleSetter = delegate(IEdgeStyle newInstance) {
                            IGraph graph       = context.Lookup(typeof(IGraph)) as IGraph;
                            IEdge  currentEdge = context.CurrentInstance;
                            if (graph != null)
                            {
                                graph.SetStyle(currentEdge, newInstance);
                            }
                        };
                        propertyBuilder.BuildPropertyMap(context.CreateChildContext(DefaultEdgeOptionBuilder.StylePropertyName, styleGetter, styleSetter, styleAssignmentPolicy));
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Method that <see cref="IPropertyBuildContext{TSubject}.AddEntry(string,IValueGetter,Demo.yFiles.Option.DataBinding.IValueSetter)">adds entries</see>
        /// for the <see cref="INode.Layout"/> of a node.
        /// </summary>
        /// <remarks>
        /// This implementation create a <see cref="IPropertyBuildContext{TSubject}.CreateChildContext{TChild}">child context</see>
        /// and adds properties for x,y,width, and height.
        /// </remarks>
        /// <param name="context">The context to use.</param>
        protected virtual void BuildLayoutProperties(IPropertyBuildContext <INode> context)
        {
            IPropertyBuildContext <IMutableRectangle> childContext = context.CreateChildContext <IMutableRectangle>(LayoutPropertyName,
                                                                                                                    delegate {
                return((IMutableRectangle)context.CurrentInstance.Lookup(typeof(IMutableRectangle)));
            },
                                                                                                                    delegate {
                //we work directly on the mutable rectangle
            }, AssignmentPolicy.ModifyInstance);

            childContext.AddEntry <double>(LayoutXName, delegate { return(childContext.CurrentInstance.X); },
                                           delegate(double value) {
                childContext.CurrentInstance.X = value;
            });
            childContext.AddEntry <double>(LayoutYName, delegate { return(childContext.CurrentInstance.Y); },
                                           delegate(double value) {
                childContext.CurrentInstance.Y = value;
            });
            childContext.AddEntry <double>(LayoutWidthName, delegate { return(childContext.CurrentInstance.Width); },
                                           delegate(double value) {
                childContext.CurrentInstance.Width = value;
            });
            childContext.AddEntry <double>(LayoutHeightName, delegate { return(childContext.CurrentInstance.Height); },
                                           delegate(double value) {
                childContext.CurrentInstance.Height = value;
            });
        }
예제 #4
0
        /// <summary>
        /// Builds the properties for the labels's <see cref="ILabel.LayoutParameter"/>
        /// and <see cref="ILabelModel"/>.
        /// </summary>
        protected virtual void BuildLabelModelParameterProperties(IPropertyBuildContext <ILabel> context, ILabelModelParameter layoutParameter)
        {
            IPropertyMapBuilder modelBuilder = GetLabelModelPropertyMapBuilder(context, layoutParameter.Model);

            if (modelBuilder != null)
            {
                modelBuilder.BuildPropertyMap(context.CreateChildContext <ILabelModel>("Model",
                                                                                       delegate {
                    return(context.CurrentInstance.LayoutParameter.Model);
                }, delegate(ILabelModel newInstance) {
                    return;
                }, AssignmentPolicy.ModifyInstance));
            }
        }
        /// <summary>
        /// Method that populates the <see cref="IPropertyMap"/> for edge styles in a given context.
        /// </summary>
        /// <remarks>
        /// This implementation uses <see cref="GetStylePropertyMapBuilder"/> to retrieve the builder for the style.
        /// </remarks>
        /// <param name="context">The context to use for queries.</param>
        protected virtual void BuildStyleProperties(IPropertyBuildContext <INode> context)
        {
            INode node = context.CurrentInstance;

            if (node != null)
            {
                INodeStyle style = node.Style;
                if (style != null)
                {
                    GetInstanceDelegate <INodeStyle> styleGetter = delegate { return(context.CurrentInstance.Style); };
                    SetInstanceDelegate <INodeStyle> styleSetter = delegate(INodeStyle newValue) {
                        IGraph graph       = context.Lookup(typeof(IGraph)) as IGraph;
                        INode  currentNode = context.CurrentInstance;
                        if (graph != null)
                        {
                            graph.SetStyle(currentNode, newValue);
                            var foldingView = graph.Lookup(typeof(IFoldingView)) as IFoldingView;
                            if (foldingView != null)
                            {
                                var masterNode = foldingView.GetMasterItem(currentNode);
                                if (foldingView.IsInFoldingState(currentNode))
                                {
                                    // update non-dummy node
                                    foldingView.Manager.MasterGraph.SetStyle(masterNode, newValue);
                                }
                                else if (foldingView.IsExpanded(currentNode))
                                {
                                    // update dummy node
                                    if (foldingView.Manager.HasFolderNodeState(masterNode))
                                    {
                                        foldingView.Manager.GetFolderNodeState(masterNode).Style = newValue;
                                    }
                                }
                            }
                        }
                    };
                    IPropertyBuildContext <INodeStyle> styleContext =
                        context.CreateChildContext(StylePropertyName, styleGetter, styleSetter, styleAssignmentPolicy);

                    IPropertyMapBuilder propertyBuilder = GetStylePropertyMapBuilder(context, style);
                    if (propertyBuilder != null)
                    {
                        GetInstanceDelegate <INodeStyle> innerStyleGetter = delegate { return(styleContext.CurrentInstance); };
                        SetInstanceDelegate <INodeStyle> innerStyleSetter = delegate(INodeStyle newValue) { styleContext.SetNewInstance(newValue); };
                        propertyBuilder.BuildPropertyMap(styleContext.CreateChildContext(string.Empty, innerStyleGetter, innerStyleSetter, styleAssignmentPolicy));
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Method that populates the <see cref="IPropertyMap"/> for labels in a given context.
        /// </summary>
        /// <remarks>
        /// This implementation uses <see cref="GetLabelPropertyMapBuilder{T}"/> to retrieve the builder for the label.
        /// </remarks>
        /// <param name="context">The context to use for queries.</param>
        protected virtual void BuildLabelProperties <T>(IPropertyBuildContext <T> context) where T : class, ILabelOwner
        {
            IPropertyBuildContext <ILabel> childContext = context.CreateChildContext <ILabel>(LabelPropertyName,
                                                                                              delegate() {
                T item = context.CurrentInstance;
                return(item.Labels.Count > 0 ? item.Labels[0] : null);
            },
                                                                                              delegate(ILabel newInstance) { }, AssignmentPolicy.ModifyInstance);

            if (context.CurrentInstance.Labels.Count > 0)
            {
                IPropertyMapBuilder builder = GetLabelPropertyMapBuilder(context, context.CurrentInstance.Labels[0]);
                if (builder != null)
                {
                    builder.BuildPropertyMap(childContext);
                }
            }
        }
예제 #7
0
 /// <summary>
 /// Builds the properties for the port's <see cref="IPort.Style"/>
 /// </summary>
 protected virtual void BuildStyleProperties(IPropertyBuildContext <IPort> context, IPortStyle style)
 {
     //style group...
     //retrieve current style...
     if (style != null)
     {
         IPropertyMapBuilder propertyBuilder = GetStyleBuilder(context, style);
         if (propertyBuilder != null)
         {
             propertyBuilder.BuildPropertyMap(context.CreateChildContext <IPortStyle>(StyleProperty,
                                                                                      delegate { return(context.CurrentInstance.Style); },
                                                                                      delegate(IPortStyle newInstance) {
                 IGraph graph = context.Lookup(typeof(IGraph)) as IGraph;
                 if (graph != null)
                 {
                     graph.SetStyle(context.CurrentInstance, newInstance);
                 }
             }, styleAssignmentPolicy));
         }
     }
 }
 public IPropertyBuildContext <TInnerChild> CreateChildContext <TInnerChild>(string name, GetInstanceDelegate <TInnerChild> getHandler, SetInstanceDelegate <TInnerChild> setHandler, AssignmentPolicy policy) where TInnerChild : class
 {
     return(new OuterWrappingBuildContext <T1, T2, TInnerChild>(wrapper, childContext.CreateChildContext(name, getHandler, setHandler, policy)));
 }
예제 #9
0
        /// <summary>
        /// Method that populates the <see cref="IPropertyMap"/> for edge styles in a given context.
        /// </summary>
        /// <remarks>
        /// This implementation uses <see cref="GetStylePropertyMapBuilder"/> to retrieve the builder for the style.
        /// </remarks>
        /// <param name="context">The context to use for queries.</param>
        protected virtual void BuildStyleProperties(IPropertyBuildContext <INode> context)
        {
            INode node = context.CurrentInstance;

            if (node != null)
            {
                INodeStyle style = node.Style;
                if (style != null)
                {
                    GetInstanceDelegate <INodeStyle> styleGetter = delegate { return(context.CurrentInstance.Style); };
                    SetInstanceDelegate <INodeStyle> styleSetter = delegate(INodeStyle newValue) {
                        IGraph graph       = context.Lookup(typeof(IGraph)) as IGraph;
                        INode  currentNode = context.CurrentInstance;
                        if (graph != null)
                        {
                            graph.SetStyle(currentNode, newValue);
                            var foldingView = graph.Lookup(typeof(IFoldingView)) as IFoldingView;
                            if (foldingView != null)
                            {
                                var masterNode = foldingView.GetMasterItem(currentNode);
                                if (foldingView.IsInFoldingState(currentNode))
                                {
                                    // update non-dummy node
                                    foldingView.Manager.MasterGraph.SetStyle(masterNode, newValue);
                                }
                                else if (foldingView.IsExpanded(currentNode))
                                {
                                    // update dummy node
                                    if (foldingView.Manager.HasFolderNodeState(masterNode))
                                    {
                                        foldingView.Manager.GetFolderNodeState(masterNode).Style = newValue;
                                    }
                                }
                            }
                        }
                    };
                    IPropertyBuildContext <INodeStyle> styleContext =
                        context.CreateChildContext(StylePropertyName, styleGetter, styleSetter, styleAssignmentPolicy);
                    styleContext.AddEntry("Shadow",
                                          new DelegateGetter <bool>(
                                              delegate { return(context.CurrentInstance.Style is ShadowNodeStyleDecorator); },
                                              delegate {
                        //show item only for !PanelNodeStyle...
                        return(!(context.CurrentInstance.Style is PanelNodeStyle));
                    }),
                                          new DelegateSetter <bool>(delegate(bool isShadow) {
                        INodeStyle currentStyle = context.CurrentInstance.Style;
                        if (isShadow && !(currentStyle is ShadowNodeStyleDecorator))
                        {
                            //don't decorate if already decorated...
                            INodeStyle newStyle =
                                new ShadowNodeStyleDecorator(currentStyle);
                            styleContext.SetNewInstance(newStyle);
                        }
                        else
                        {
                            if (!isShadow && currentStyle is ShadowNodeStyleDecorator)
                            {
                                //remove decoration
                                styleContext.SetNewInstance(
                                    ((ShadowNodeStyleDecorator)currentStyle).Wrapped);
                            }
                        }
                    },
                                                                    delegate { return(!(context.CurrentInstance.Style is PanelNodeStyle)); }
                                                                    ));

                    IPropertyMapBuilder propertyBuilder = GetStylePropertyMapBuilder(context, style);
                    if (propertyBuilder != null)
                    {
                        GetInstanceDelegate <INodeStyle> innerStyleGetter = delegate { return(styleContext.CurrentInstance); };
                        SetInstanceDelegate <INodeStyle> innerStyleSetter = delegate(INodeStyle newValue) { styleContext.SetNewInstance(newValue); };
                        propertyBuilder.BuildPropertyMap(styleContext.CreateChildContext(string.Empty, innerStyleGetter, innerStyleSetter, styleAssignmentPolicy));
                    }
                }
            }
        }
예제 #10
0
        protected override void BuildPropertyMapImpl(IPropertyBuildContext <Pen> context)
        {
            Brush b = context.CurrentInstance == null ? null : context.CurrentInstance.Brush;
            IPropertyMapBuilder brushBuilder;

            if (b == null)
            {
                brushBuilder = context.GetPropertyMapBuilder(typeof(Brush), b);
            }
            else
            {
                brushBuilder = context.GetPropertyMapBuilder(b);
            }

            if (brushBuilder != null)
            {
                brushBuilder.BuildPropertyMap(context.CreateChildContext <Brush>("",
                                                                                 delegate() {
                    Pen p = context.CurrentInstance;
                    return(p == null ? null:context.CurrentInstance.Brush);
                },
                                                                                 delegate(Brush newInstance) {
                    Pen p = context.CurrentInstance;
                    if (newInstance == null)
                    {
                        context.SetNewInstance(null);
                        return;
                    }
                    if (p == null)
                    {
                        context.SetNewInstance(new Pen(newInstance));
                    }
                    else
                    {
                        Pen clone   = (Pen)p.Clone();
                        clone.Brush = newInstance;
                        context.SetNewInstance(clone);
                    }
                }, AssignmentPolicy.CreateNewInstance));
            }

            context.AddEntry <float>(Width,
                                     delegate {
                Pen pen = context.CurrentInstance;
                return(pen == null ? 0 : pen.Width);
            },
                                     delegate(float value) {
                Pen pen   = context.CurrentInstance;
                Pen clone = pen.Clone() as Pen;
                if (clone != null)
                {
                    clone.Width = value;
                    context.SetNewInstance(clone);
                }
            });
            context.AddEntry(DashStyle,
                             new DelegateGetter <object>(
                                 delegate() {
                Pen pen = context.CurrentInstance;
                return(pen == null ? OptionItem.VALUE_UNDEFINED : pen.DashStyle);
            }),
                             new DelegateSetter <DashStyle>(delegate(DashStyle value) {
                Pen pen   = context.CurrentInstance;
                Pen clone = pen.Clone() as Pen;
                if (clone != null)
                {
                    clone.DashStyle = value;
                    context.SetNewInstance(clone);
                }
            }));
        }