private static void VisitAndDocumentChildren(BranchAccessor branchAccessor, BranchContext context, ICollection <LayoutStructureBranch> branches, ICollection <LayoutStructureTabSet> layoutStructureTabSets)
        {
            //figure out the current ID: if there is no context, this is
            //root, otherwise, the parent will have assigned the id
            Guid id;

            if (context == null)
            {
                id = Guid.NewGuid();
            }
            else
            {
                id = context.IsSecond
                    ? context.Parent.ChildSecondBranchId.Value
                    : context.Parent.ChildFirstBranchId.Value;
            }

            //document the current branch
            var layoutStructureBranch = new LayoutStructureBranch(
                id,
                IdOrNull(branchAccessor.FirstItemBranchAccessor),
                IdOrNull(branchAccessor.SecondItemBranchAccessor),
                IdOrNull(branchAccessor.FirstItemTabablzControl),
                IdOrNull(branchAccessor.SecondItemTabablzControl),
                branchAccessor.Branch.Orientation,
                branchAccessor.Branch.GetFirstProportion());

            branches.Add(layoutStructureBranch);

            //run throw the child branches or tab controls
            if (branchAccessor.FirstItemBranchAccessor != null)
            {
                VisitAndDocumentChildren(branchAccessor.FirstItemBranchAccessor, new BranchContext(layoutStructureBranch, false), branches, layoutStructureTabSets);
            }
            else
            {
                DocumentTabSet(layoutStructureBranch.ChildFirstTabSetId.Value, branchAccessor.FirstItemTabablzControl, layoutStructureTabSets);
            }
            if (branchAccessor.SecondItemBranchAccessor != null)
            {
                VisitAndDocumentChildren(branchAccessor.SecondItemBranchAccessor, new BranchContext(layoutStructureBranch, true), branches, layoutStructureTabSets);
            }
            else
            {
                DocumentTabSet(layoutStructureBranch.ChildSecondTabSetId.Value, branchAccessor.SecondItemTabablzControl, layoutStructureTabSets);
            }
        }
Exemplo n.º 2
0
        private static void BranchAccessorVisitor(XElement stateNode, BranchAccessor branchAccessor)
        {
            var proportion   = branchAccessor.Branch.GetFirstProportion();
            var firstBranch  = new XElement(XmlStructure.BranchNode.Branch, new XAttribute(XmlStructure.BranchNode.Proportion, proportion));
            var secondBranch = new XElement(XmlStructure.BranchNode.Branch, new XAttribute(XmlStructure.BranchNode.Proportion, 1 - proportion));

            var branchNode = new XElement(XmlStructure.BranchNode.Branches, new XAttribute(XmlStructure.BranchNode.Orientation, branchAccessor.Branch.Orientation.ToString()));

            branchNode.Add(firstBranch);
            branchNode.Add(secondBranch);

            stateNode.Add(branchNode);

            branchAccessor
            .Visit(firstBranch, BranchItem.First, BranchAccessorVisitor, TabablzControlVisitor)
            .Visit(secondBranch, BranchItem.Second, BranchAccessorVisitor, TabablzControlVisitor);
        }
Exemplo n.º 3
0
        private static void BranchAccessorVisitor(StateNode stateNode, BranchAccessor branchAccessor)
        {
            var branchNode = new StateNode(new BranchNode(branchAccessor.Branch.Orientation.ToString()));

            stateNode.Children.Add(branchNode);

            var proportion = branchAccessor.Branch.GetFirstProportion();

            var firstBranchNode = new StateNode(new BranchNode(proportion));

            branchNode.Children.Add(firstBranchNode);
            var secondBranchNode = new StateNode(new BranchNode(1 - proportion));

            branchNode.Children.Add(secondBranchNode);

            branchAccessor
            .Visit(firstBranchNode, BranchItem.First, BranchAccessorVisitor, TabablzControlVisitor)
            .Visit(secondBranchNode, BranchItem.Second, BranchAccessorVisitor, TabablzControlVisitor);
        }
        private static void BranchAccessorVisitor(TreeNode treeNode, BranchAccessor branchAccessor)
        {
            var branchNode = new TreeNode {
                Content = "Branch " + branchAccessor.Branch.Orientation
            };

            treeNode.Children.Add(branchNode);

            var firstBranchNode = new TreeNode {
                Content = "Branch Item 1. Ratio=" + branchAccessor.Branch.GetFirstProportion()
            };

            branchNode.Children.Add(firstBranchNode);
            var secondBranchNode = new TreeNode {
                Content = "Branch Item 2. Ratio=" + (1 - branchAccessor.Branch.GetFirstProportion())
            };

            branchNode.Children.Add(secondBranchNode);

            branchAccessor
            .Visit(firstBranchNode, BranchItem.First, BranchAccessorVisitor, TabablzControlVisitor)
            .Visit(secondBranchNode, BranchItem.Second, BranchAccessorVisitor, TabablzControlVisitor);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the state of a branch.
        /// </summary>
        /// <typeparam name="TTabModel">The type of tab model</typeparam>
        /// <typeparam name="TTabViewModel">The type of tab view model, currently displayed in the app.</typeparam>
        /// <param name="branchVisitor">The branch to be inspected</param>
        /// <param name="tabContentModelConverter">The converter that transforms tab view models to models</param>
        /// <returns>The read state of the branch</returns>
        private static BranchState <TTabModel> GetBranchState <TTabModel, TTabViewModel> (BranchAccessor branchVisitor, Func <TTabViewModel, TTabModel> tabContentModelConverter)
        {
            var firstState  = (BranchItemState <TTabModel>)null;
            var secondState = (BranchItemState <TTabModel>)null;

            if (branchVisitor.FirstItemBranchAccessor != null)
            {
                firstState = new BranchItemState <TTabModel> (GetBranchState(branchVisitor.FirstItemBranchAccessor, tabContentModelConverter), null);
            }
            else
            {
                firstState = new BranchItemState <TTabModel> (null, GetTabSetState(branchVisitor.FirstItemTabablzControl, tabContentModelConverter));
            }

            if (branchVisitor.SecondItemBranchAccessor != null)
            {
                secondState = new BranchItemState <TTabModel> (GetBranchState(branchVisitor.SecondItemBranchAccessor, tabContentModelConverter), null);
            }
            else
            {
                secondState = new BranchItemState <TTabModel> (null, GetTabSetState(branchVisitor.SecondItemTabablzControl, tabContentModelConverter));
            }

            return(new BranchState <TTabModel> (firstState,
                                                secondState,
                                                branchVisitor.Branch.Orientation,
                                                branchVisitor.Branch.GetFirstProportion( )));
        }