internal object GetValue(FunctionalProperty functionalProperty, IFunctionalTreeElement element)
        {
            if (element == null)
                throw new ArgumentNullException("element", "element is null.");
            if (functionalProperty == null)
                throw new ArgumentNullException("functionalProperty", "functionalProperty is null.");
            if (FunctionalPropertyValuesInternal.ContainsKey(functionalProperty) == false)
            {
                return functionalProperty.DefaultMetadata.DefaultValue;
            }

            if(!HasValue(functionalProperty, element))
            {
                //Get inherited Value
                if (functionalProperty.DefaultMetadata.Inherits)
                {
                    IFunctionalTreeElement curParent = FunctionalTreeHelper.GetFunctionalParent(element);
                    while (curParent != null)
                    {
                        if (HasValue(functionalProperty, curParent))
                            return FunctionalPropertyValuesInternal[functionalProperty][curParent];

                        curParent = FunctionalTreeHelper.GetFunctionalParent(curParent);
                    }
                }

                //Return default value
                return functionalProperty.DefaultMetadata.DefaultValue;
            }

            return FunctionalPropertyValuesInternal[functionalProperty][element];
        }
        internal List<FunctionalEventHandlerContainer> GetHandlerList(FunctionalEvent functionalEvent, IFunctionalTreeElement element)
        {
            if (HandlerListInternal.ContainsKey(functionalEvent) && HandlerListInternal[functionalEvent].ContainsKey(element))
                return HandlerListInternal[functionalEvent][element];

            return null;
        }
        public static void AddFunctionalChild(this IFunctionalTreeElement source, IFunctionalTreeElement element)
        {
            if (source == null)
                return;

            FunctionalTreeElement sourceElement = FunctionalTreeHelper.GetFunctionalTree(source).GetFunctionalElement(source);
            sourceElement.AddChild(element);
        }
예제 #4
0
        internal FunctionalTreeElement GetFunctionalElement(IFunctionalTreeElement element)
        {
            if (RootElement == null)
                return null;
            if (RootElement.Element == element)
                return RootElement;

            return GetFunctionalElement(RootElement.Children, element);
        }
        internal FunctionalTreeElement(IFunctionalTreeElement element, FunctionalTreeElement parent)
        {
            if (element == null)
                throw new ArgumentNullException("element", "element is null.");

            Element = element;
            Parent = parent;

            _children = new List<FunctionalTreeElement>();
            Children = new ReadOnlyCollection<FunctionalTreeElement>(_children);
        }
        private int RemoveTreesWithElement(IFunctionalTreeElement element)
        {
            IEnumerable<FunctionalTree> treesToRemove = FunctionalTreeList.Where(cur => cur.IsChild(element));
            int treeCount = treesToRemove.Count();
            foreach (FunctionalTree tree in treesToRemove.ToList())
            {
                tree.FunctionalChildAttachedInternal -= Tree_FunctionalChildAttached;
                tree.FunctionalChildDetachedInternal -= Tree_FunctionalChildDetached;

                FunctionalTreeList.Remove(tree);
            }

            return treeCount;
        }
        internal FunctionalTree GetOrCreateFunctionalTree(IFunctionalTreeElement element)
        {
            if (element == null)
                return null;

            FunctionalTree tree = GetFunctionalTree(element);
            if (tree != null)
                return tree;

            tree = new FunctionalTree(element);
            tree.FunctionalChildAttachedInternal += Tree_FunctionalChildAttached;
            tree.FunctionalChildDetachedInternal += Tree_FunctionalChildDetached;

            FunctionalTreeList.Add(tree);
            return tree;
        }
        internal void AddHandler(FunctionalEvent functionalEvent, IFunctionalTreeElement element, Delegate handler, bool handledEventsToo = false)
        {
            if (functionalEvent == null)
                throw new ArgumentNullException("functionalEvent", "functionalEvent is null.");
            if (element == null)
                throw new ArgumentNullException("element", "element is null.");
            if (handler == null)
                throw new ArgumentNullException("handler", "handler is null.");
            if (handler.GetType() != functionalEvent.HandlerType && handler.GetType() != typeof(FunctionalEventHandler))
                throw new ArgumentException("handler", "Handler type mismatched.");

            if (!HandlerListInternal.ContainsKey(functionalEvent))
            {
                HandlerListInternal[functionalEvent] = new Dictionary<IFunctionalTreeElement, List<FunctionalEventHandlerContainer>>();
            }
            if (!HandlerListInternal[functionalEvent].ContainsKey(element))
            {
                HandlerListInternal[functionalEvent][element] = new List<FunctionalEventHandlerContainer>();
            }

            GetHandlerList(functionalEvent, element).Add(new FunctionalEventHandlerContainer(handler, handledEventsToo));
        }
        public void ClearValue(FunctionalProperty functionalProperty, IFunctionalTreeElement element)
        {
            if (functionalProperty == null)
                throw new ArgumentNullException("functionalProperty", "functionalProperty is null.");
            if (element == null)
                throw new ArgumentNullException("element", "element is null.");

            if (FunctionalPropertyValuesInternal.ContainsKey(functionalProperty) && HasValue(functionalProperty, element))
            {
                object oldValue = FunctionalPropertyValuesInternal[functionalProperty][element];
                FunctionalPropertyValuesInternal[functionalProperty].Remove(element);

                //Fire PropertyChanged
                if (functionalProperty.DefaultMetadata.PropertyChangedCallback != null)
                {
                    functionalProperty.DefaultMetadata.PropertyChangedCallback(element,
                        new FunctionalPropertyChangedEventArgs(functionalProperty, oldValue, functionalProperty.DefaultMetadata.DefaultValue));

                    if (functionalProperty.DefaultMetadata.Inherits)
                        NotifyChildrenAboutInheritedValue(FunctionalTreeHelper.GetFunctionalChildren(element), functionalProperty, oldValue, functionalProperty.DefaultMetadata.DefaultValue);
                }
            }
        }
        private FunctionalElementRoute BuildDescendentsEventRoute(IFunctionalTreeElement element, FunctionalEventArgs eventArgs)
        {
            FunctionalElementRoute route = new FunctionalElementRoute();
            route.AddRange(GetDescendents(element));

            return route;
        }
 private FunctionalElementRoute BuildChildrenEventRoute(IFunctionalTreeElement element, FunctionalEventArgs eventArgs)
 {
     FunctionalElementRoute route = new FunctionalElementRoute();
     route.AddRange(FunctionalTreeHelper.GetFunctionalChildren(element));
     return route;
 }
        private FunctionalElementRoute BuildBubbleEventRoute(IFunctionalTreeElement element, FunctionalEventArgs eventArgs)
        {
            FunctionalElementRoute route = new FunctionalElementRoute();

            IFunctionalTreeElement curElement = element;
            while (curElement != null)
            {
                route.Add(curElement);
                curElement = FunctionalTreeHelper.GetFunctionalParent(curElement);
            }

            return route;
        }
예제 #13
0
 private void OnDockingContentClosedInternal(IFunctionalTreeElement sender, FunctionalEventArgs e)
 {
     Debug.Assert(e.Source is DockingBase, "Source is not an DockingBase.");
     if (e.Source is DockingBase)
         OnDockingDescendentClosed((DockingBase)e.Source);
 }
        private IEnumerable<IFunctionalTreeElement> GetDescendents(IFunctionalTreeElement element)
        {
            List<IFunctionalTreeElement> descendents = new List<IFunctionalTreeElement>();
            foreach (IFunctionalTreeElement item in FunctionalTreeHelper.GetFunctionalChildren(element))
            {
                descendents.Add(item);
                descendents.AddRange(GetDescendents(item));
            }

            return descendents;
        }
        private FunctionalElementRoute BuildSpreadEventRoute(IFunctionalTreeElement element, FunctionalEventArgs eventArgs)
        {
            FunctionalElementRoute route = new FunctionalElementRoute();

            IFunctionalTreeElement treeRoot = FunctionalTreeHelper.GetFunctionalTree(element).Root;
            route.Add(treeRoot);
            route.AddRange(GetDescendents(treeRoot));

            return route;
        }
 private void TestHandler(IFunctionalTreeElement sender, FunctionalEventArgs e)
 {
     string senderString = (sender is Foo ? ((Foo)sender).Header : "Root");
     string sourceString = (e.Source is Foo ? ((Foo)e.Source).Header : "Root");
     Debug.WriteLine(String.Format("{0} | Id: {1} | sender: {2} | e.Source: {3}", Header, Id, senderString, sourceString));
 }
 private static object HeaderCoerce(IFunctionalTreeElement element, object baseValue)
 {
     return baseValue;
 }
 private static void HeaderChanged(IFunctionalTreeElement element, FunctionalPropertyChangedEventArgs e)
 {
 }
 private void TestHandler(IFunctionalTreeElement sender, FunctionalEventArgs e)
 {
     Debug.WriteLine(String.Format("{0} | Id: {1} | NoFoo", Header, Id));
 }
예제 #20
0
 private static void DockManagerChangedHandler(IFunctionalTreeElement element, FunctionalPropertyChangedEventArgs e)
 {
     DockingBase dockingElement = element as DockingBase;
     if (dockingElement != null && e.NewValue != e.OldValue)
         dockingElement.OnDockManagerChanged(e.OldValue as DockManager, e.NewValue as DockManager);
 }
        public static bool RemoveFunctionalChild(this IFunctionalTreeElement source, IFunctionalTreeElement child)
        {
            if (source == null)
                return false;

            FunctionalTreeElement sourceElement = FunctionalTreeHelper.GetFunctionalTree(source).GetFunctionalElement(source);
            return sourceElement.RemoveChild(child);
        }
        private FunctionalElementRoute BuildParentEventRoute(IFunctionalTreeElement element, FunctionalEventArgs eventArgs)
        {
            FunctionalElementRoute route = new FunctionalElementRoute();
            route.Add(FunctionalTreeHelper.GetFunctionalParent(element));

            return route;
        }
        private FunctionalElementRoute BuildSiblingsEventRoute(IFunctionalTreeElement element, FunctionalEventArgs eventArgs)
        {
            FunctionalElementRoute route = new FunctionalElementRoute();

            IFunctionalTreeElement parent = FunctionalTreeHelper.GetFunctionalParent(element);
            if (parent == null)
                return route;

            route.AddRange(FunctionalTreeHelper.GetFunctionalChildren(parent).Where(cur => cur != element));
            return route;
        }
예제 #24
0
 private static object InfoCoercingHandler(IFunctionalTreeElement element, object baseValue)
 {
     MainWindow.Reporter.WriteLine(string.Format("[Property] [Coerced] Info   Element: {0}  BaseValue: {1}", ((TestingElement)element).Name, baseValue));
     return baseValue;
 }
        private FunctionalElementRoute BuildTunnelEventRoute(IFunctionalTreeElement element, FunctionalEventArgs eventArgs)
        {
            FunctionalElementRoute route = BuildBubbleEventRoute(element, eventArgs);
            route.Reverse();

            return route;
        }
예제 #26
0
 private void EventTestHandler(IFunctionalTreeElement sender, FunctionalEventArgs e)
 {
     MainWindow.Reporter.WriteLine(string.Format("[Event] Event: {0}  Sender: {1}  Source: {2}", e.FunctionalEvent.Name, ((TestingElement)sender).Name, ((TestingElement)e.Source).Name));
 }
        private void RaiseEventOnElement(IFunctionalTreeElement element, 
            FunctionalEventArgs eventArgs, 
            FunctionalEventTracingArgs tracingEventArgs, 
            Predicate<IFunctionalTreeElement> predicate = null)
        {
            if (element == null || eventArgs == null || (predicate != null && !predicate(element)))
                return;

            List<FunctionalEventHandlerContainer> eventHandlerList = GetHandlerList(eventArgs.FunctionalEvent, element);
            if (eventHandlerList != null && eventHandlerList.Count() > 0)
            {
                foreach (FunctionalEventHandlerContainer handlerContainer in eventHandlerList)
                {
                    if (!eventArgs.Handled || handlerContainer.HandledEventsToo)
                    {
                        eventArgs.FunctionalEvent.EventTracer.RaiseEventRaising(eventArgs.FunctionalEvent, tracingEventArgs);
                        if (tracingEventArgs.Abort)
                            return;

                        foreach (Delegate handler in handlerContainer.Handler.GetInvocationList())
                            handler.Method.Invoke(element, new object[] { element, eventArgs });

                        eventArgs.FunctionalEvent.EventTracer.RaiseEventRaised(eventArgs.FunctionalEvent, tracingEventArgs);
                        if (tracingEventArgs.Abort)
                            return;
                    }
                }
            }
        }
        internal void RemoveHandler(FunctionalEvent functionalEvent, IFunctionalTreeElement element, Delegate handler)
        {
            if (functionalEvent == null)
                throw new ArgumentNullException("functionalEvent", "functionalEvent is null.");
            if (element == null)
                throw new ArgumentNullException("element", "element is null.");
            if (handler == null)
                throw new ArgumentNullException("handler", "handler is null.");

            List<FunctionalEventHandlerContainer> handlerList = GetHandlerList(functionalEvent, element);
            if (handlerList != null)
                handlerList.RemoveAll(cur => cur.Handler == handler);
        }
예제 #29
0
 private static void InfoChangedHandler(IFunctionalTreeElement element, FunctionalPropertyChangedEventArgs e)
 {
     MainWindow.Reporter.WriteLine(string.Format("[Property] [PropertyChanged] Info   Element: {0}  OldValue: {1}  NewValue: {2}", ((TestingElement)element).Name, e.OldValue, e.NewValue));
 }
예제 #30
0
        private void FunctionalTree_FunctionalChildDetached(IFunctionalTreeElement child, IFunctionalTreeElement parent, FunctionalTree functionalTree)
        {
            if (child == this)
                return;

            IDockingElement dockingChild = child as IDockingElement;
            if (dockingChild != null)
                OnDockingContentDetached(dockingChild);
        }