Exemplo n.º 1
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));
                    }
                }
            }
        }
Exemplo n.º 2
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));
                    }
                }
            }
        }
 public IPropertyMapBuilder GetPropertyMapBuilder(Type type, object subject)
 {
     if (subject == null)
     {
         IPropertyMapBuilder builder = contextLookup.Lookup(type, typeof(IPropertyMapBuilder)) as IPropertyMapBuilder;
         if (builder != null)
         {
             return(builder);
         }
         return(GetBuilder(type));
     }
     else
     {
         return(GetPropertyMapBuilder(subject));
     }
 }
Exemplo n.º 5
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);
                }
            }
        }
        public IPropertyMapBuilder GetPropertyMapBuilder(object subject)
        {
            IPropertyMapBuilder builder = contextLookup.Lookup(subject, typeof(IPropertyMapBuilder)) as IPropertyMapBuilder;

            if (builder != null)
            {
                return(builder);
            }
            if (subject != null)
            {
                builder = GetBuilder(subject.GetType());
                if (builder != null)
                {
                    return(builder);
                }
            }
            return(subject != null?ReflectionHelper.GetPropertyBuilderFromAttribute(subject.GetType()) : null);
        }
Exemplo n.º 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));
         }
     }
 }
Exemplo n.º 8
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));
                    }
                }
            }
        }