Exemplo n.º 1
0
        public PathViewModel(IEventAggregator eventAggregator, MainViewModel mainViewModel)
        {
            evAgg = eventAggregator;

            this.mainViewModel = mainViewModel;

            SubscriptionTokenPathChanged = evAgg.GetEvent <SelectedInMainChangedEvent>().Subscribe(PathChangedSubscription());

            Root = new SelectedNodePathViewModel(evAgg, mainViewModel.Root, this, mainViewModel, NodeType.Root)
            {
                Token = SubscriptionTokenPathChanged, SubscriptionAction = PathChangedSubscription()
            };
            Excel = new SelectedNodePathViewModel(evAgg, null, this, mainViewModel, NodeType.Excel)
            {
                Parent = root, Token = SubscriptionTokenPathChanged, SubscriptionAction = PathChangedSubscription()
            };
            Tab = new SelectedNodePathViewModel(evAgg, null, this, mainViewModel, NodeType.Sheet)
            {
                Parent = excel, Token = SubscriptionTokenPathChanged, SubscriptionAction = PathChangedSubscription()
            };
            Table = new SelectedNodePathViewModel(evAgg, null, this, mainViewModel, NodeType.Table)
            {
                Parent = tab, Token = SubscriptionTokenPathChanged, SubscriptionAction = PathChangedSubscription()
            };
            Column = new SelectedNodePathViewModel(evAgg, null, this, mainViewModel, NodeType.Column)
            {
                Parent = table, Token = SubscriptionTokenPathChanged, SubscriptionAction = PathChangedSubscription()
            };


            evAgg.GetEvent <PathViewAddedEvent>().Publish();
        }
Exemplo n.º 2
0
        private void SetSelectedNodeProperty(NodeBase node, SelectedNodePathViewModel selectedNode, NodeType nodeType, NodeType nodeItemsType, Guid guid, bool isFromPath = false)
        {
            selectedNode.Node = node;
            var img      = "root";
            var imgItems = "excel|tab|table|column".Split('|');

            switch (nodeType)
            {
            case NodeType.Root: img = "excel"; break;

            case NodeType.Excel: img = "tab"; break;

            case NodeType.Sheet: img = "table"; break;

            case NodeType.Table: img = "column"; break;
                //case NodeType.Column: img = "column"; break;
            }
            selectedNode.ImageSource = string.Format(@"pack://application:,,,/Images/{0}.png", img);
            selectedNode.Name        = node.Name;

            SetSelectedItem(Root.Node as NodeRoot, node, selectedNode, nodeType, nodeItemsType, guid, isFromPath);

            Root.IsVisible = false;
            if (Excel != null)
            {
                Excel.IsVisible = false;
            }
            if (Tab != null)
            {
                Tab.IsVisible = false;
            }
            if (Table != null)
            {
                Table.IsVisible = false;
            }
            if (Column != null)
            {
                Column.IsVisible = false;
            }

            if (selectedNode.Parent != null)
            {
                selectedNode.Parent.IsVisible = true;
                if (selectedNode.Parent.Parent != null)
                {
                    selectedNode.Parent.Parent.IsVisible = true;
                    if (selectedNode.Parent.Parent.Parent != null)
                    {
                        selectedNode.Parent.Parent.Parent.IsVisible = true;
                        if (selectedNode.Parent.Parent.Parent.Parent != null)
                        {
                            selectedNode.Parent.Parent.Parent.Parent.IsVisible = true;
                        }
                    }
                }
            }

            selectedNode.IsVisible = true;
            Column.IsVisible       = false;
        }
Exemplo n.º 3
0
        private void SetSelectedItem(NodeRoot root, NodeBase node, SelectedNodePathViewModel pathItem, NodeType nodeType, NodeType nodeItemsType, Guid guid, bool isFromPath)
        {
            if (nodeType != NodeType.Column)
            {
                pathItem.Items = new ObservableCollection <PathItem>(node.GetNodes().Select(x => new PathItem(x)
                {
                    Guid = (x as NodeBase).Guid,
                    Name = (x as NodeBase).Name
                }));
            }

            if (pathItem.Parent != null)
            {
                pathItem.Parent.Items = new ObservableCollection <PathItem>(node.GetParent().GetNodes().Select(x => new PathItem(x)
                {
                    Guid = (x as NodeBase).Guid,
                    Name = (x as NodeBase).Name
                }));
            }

            if (pathItem.Parent != null && pathItem.Parent.Parent != null)
            {
                pathItem.Parent.Parent.Items = new ObservableCollection <PathItem>(node.GetParent().GetParent().GetNodes().Select(x => new PathItem(x)
                {
                    Guid = (x as NodeBase).Guid,
                    Name = (x as NodeBase).Name
                }));
            }

            if (pathItem.Parent != null && pathItem.Parent.Parent != null && pathItem.Parent.Parent.Parent != null)
            {
                pathItem.Parent.Parent.Parent.Items = new ObservableCollection <PathItem>(node.GetParent().GetParent().GetParent().GetNodes().Select(x => new PathItem(x)
                {
                    Guid = (x as NodeBase).Guid,
                    Name = (x as NodeBase).Name
                }));
            }

            if (pathItem.Parent != null && pathItem.Parent.Parent != null && pathItem.Parent.Parent.Parent != null && pathItem.Parent.Parent.Parent.Parent != null)
            {
                pathItem.Parent.Parent.Parent.Parent.Items = new ObservableCollection <PathItem>(node.GetParent().GetParent().GetParent().GetParent().GetNodes().Select(x => new PathItem(x)
                {
                    Guid = (x as NodeBase).Guid,
                    Name = (x as NodeBase).Name
                }));
            }


            if (nodeType == NodeType.Root)
            {
                //Root
                var excel = pathItem.Items.FirstOrDefault();
                pathItem.SelectedItem = excel;
                //var nodes = pathItem.Node.GetNodes();
                //var excelNode = nodes.First(e => e.Guid.Equals(excel.Guid));
                //countOfCycles = 0;
                //PathChangedSubscription().Invoke(excelNode);
            }

            if (nodeType == NodeType.Excel)
            {
                pathItem.Parent.SelectedItem = pathItem.Parent.Items.FirstOrDefault(x => x.Guid.Equals(guid));
            }

            if (nodeType == NodeType.Sheet)
            {
                // Root ->
                pathItem.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(node.GetParent().Guid));
                // Excel ->
                pathItem.Parent.SelectedItem = pathItem.Parent.Items.FirstOrDefault(x => x.Guid.Equals(guid));
            }

            if (nodeType == NodeType.Table)
            {
                // Root ->
                var excelNode = node.GetParent().GetParent();
                pathItem.Parent.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(excelNode.Guid));
                // Excel ->
                pathItem.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(node.GetParent().Guid));
                // Tab ->
                pathItem.Parent.SelectedItem = pathItem.Parent.Items.FirstOrDefault(x => x.Guid.Equals(guid));
            }

            if (nodeType == NodeType.Column)
            {
                // Root ->
                pathItem.Parent.Parent.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(node.GetParent().GetParent().GetParent().Guid));
                // Excel ->
                pathItem.Parent.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(node.GetParent().GetParent().Guid));
                // Tab ->
                pathItem.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(node.GetParent().Guid));
                // Table ->
                pathItem.Parent.SelectedItem = pathItem.Parent.Items.FirstOrDefault(x => x.Guid.Equals(guid));
            }
        }