Example #1
0
        public void TestFindDescendent()
        {
            // Test a deep find
            IList <View> descendents = ViewSupport.FindDescendent(top, child_2_2_1);

            Assert.AreEqual(2, descendents.Count);
            Assert.AreEqual(child_2, descendents[0]);
            Assert.AreEqual(child_2_2, descendents[1]);

            descendents = ViewSupport.FindDescendent(top, child_2_1_1);
            Assert.AreEqual(2, descendents.Count);
            Assert.AreEqual(child_2, descendents[0]);
            Assert.AreEqual(child_2_1, descendents[1]);

            descendents = ViewSupport.FindDescendent(top, child_2_1);
            Assert.AreEqual(1, descendents.Count);
            Assert.AreEqual(child_2, descendents[0]);

            // Test a shallow find
            descendents = ViewSupport.FindDescendent(top, child_2);
            Assert.AreEqual(0, descendents.Count);

            // Test a no find
            descendents = ViewSupport.FindDescendent(top, new SupportSchemaNeutralView());
            Assert.AreEqual(null, descendents);
        }
Example #2
0
        public bool RemoveView(View view)
        {
            int index = ViewSupport.FindViewIndex(_children, view);

            if (index == -1)
            {
                return(false);
            }
            _children   = ViewSupport.RemoveView(_children, index);
            view.Parent = null;
            return(true);
        }
Example #3
0
        public ViewServiceCreateResult CreateViews(
            Viewable eventStreamViewable,
            IList <ViewFactory> viewFactories,
            AgentInstanceViewFactoryChainContext viewFactoryChainContext,
            bool hasPreviousNode)
        {
            // Attempt to find existing views under the stream that match specs.
            // The viewSpecList may have been changed by this method.
            Pair <Viewable, IList <View> > resultPair;

            if (hasPreviousNode)
            {
                resultPair = new Pair <Viewable, IList <View> >(eventStreamViewable, Collections.GetEmptyList <View>());
            }
            else
            {
                resultPair = ViewServiceHelper.MatchExistingViews(eventStreamViewable, viewFactories, viewFactoryChainContext.AgentInstanceContext);
            }

            var parentViewable = resultPair.First;

            if (viewFactories.IsEmpty())
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug(".createView No new views created, dumping stream ... " + eventStreamViewable);
                    ViewSupport.DumpChildViews("EventStream ", eventStreamViewable);
                }

                return(new ViewServiceCreateResult(parentViewable, parentViewable, Collections.GetEmptyList <View>()));   // we know its a view here since the factory list is empty
            }

            // Instantiate remaining chain of views from the remaining factories which didn't match to existing views.
            var views = ViewServiceHelper.InstantiateChain(parentViewable, viewFactories, viewFactoryChainContext);

            // Initialize any views that need initializing after the chain is complete
            foreach (var view in views)
            {
                if (view is InitializableView)
                {
                    var initView = (InitializableView)view;
                    initView.Initialize();
                }
            }

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".createView New views created for stream, all views ... " + eventStreamViewable);
                ViewSupport.DumpChildViews("EventStream ", eventStreamViewable);
            }

            return(new ViewServiceCreateResult(views[views.Count - 1], views[0], views));
        }
Example #4
0
        public void Remove(EventStream eventStream, Viewable viewToRemove)
        {
            // If the viewToRemove to remove has child viewToRemove, don't disconnect - the child ViewToRemove(s) need this
            if (viewToRemove.HasViews)
            {
                return;
            }

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".remove Views before the remove of view " + viewToRemove + ", for event stream " + eventStream);
                ViewSupport.DumpChildViews("EventStream ", eventStream);
            }

            // Remove views in chain leaving only non-empty parent views to the child view to be removed
            ViewServiceHelper.RemoveChainLeafView(eventStream, viewToRemove);

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".remove Views after the remove, for event stream " + eventStream);
                ViewSupport.DumpChildViews("EventStream ", eventStream);
            }
        }
Example #5
0
        /// <summary>
        /// Removes a view from a parent view returning the orphaned parent views in a list.
        /// </summary>
        /// <param name="parentViewable">parent to remove view from</param>
        /// <param name="viewToRemove">view to remove</param>
        /// <returns>
        /// chain of orphaned views
        /// </returns>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="IllegalStateException">
        /// </exception>
        protected internal static IList <View> RemoveChainLeafView(Viewable parentViewable, Viewable viewToRemove)
        {
            IList <View> removedViews = new List <View>();

            // The view to remove must be a leaf node - non-leaf views are just not removed
            if (viewToRemove.HasViews)
            {
                return(removedViews);
            }

            // Find child viewToRemove among descendent views
            IList <View> viewPath = ViewSupport.FindDescendent(parentViewable, viewToRemove);

            if (viewPath == null)
            {
                String message = "Viewable not found when removing view " + viewToRemove;
                throw new ArgumentException(message);
            }

            // The viewToRemove is a direct child view of the stream
            if (viewPath.IsEmpty())
            {
                bool isViewRemoved = parentViewable.RemoveView((View)viewToRemove);

                if (!isViewRemoved)
                {
                    String message = "Failed to remove immediate child view " + viewToRemove;
                    Log.Fatal(".remove " + message);
                    throw new IllegalStateException(message);
                }

                removedViews.Add((View)viewToRemove);
                return(removedViews);
            }

            View[] viewPathArray = viewPath.ToArray();
            View   currentView   = (View)viewToRemove;

            // Remove child from parent views until a parent view has more children,
            // or there are no more parents (index=0).
            for (int index = viewPathArray.Length - 1; index >= 0; index--)
            {
                bool isViewRemoved = viewPathArray[index].RemoveView(currentView);
                removedViews.Add(currentView);

                if (!isViewRemoved)
                {
                    String message = "Failed to remove view " + currentView;
                    Log.Fatal(".remove " + message);
                    throw new IllegalStateException(message);
                }

                // If the parent views has more child views, we are done
                if (viewPathArray[index].HasViews)
                {
                    break;
                }

                // The parent of the top parent is the stream, remove from stream
                if (index == 0)
                {
                    parentViewable.RemoveView(viewPathArray[0]);
                    removedViews.Add(viewPathArray[0]);
                }
                else
                {
                    currentView = viewPathArray[index];
                }
            }

            return(removedViews);
        }
Example #6
0
 public View AddView(View view)
 {
     _children   = ViewSupport.AddView(_children, view);
     view.Parent = this;
     return(view);
 }