private void AddItemToRoot(ISolutionItem item)
        {
            var viewModel = new SolutionItemViewModel(itemNameRegistry, item);

            _itemToViewmodel.Add(item, viewModel);
            Root.Add(viewModel);
        }
Exemplo n.º 2
0
        private void AddItem(ISolutionItem item)
        {
            var viewModel = new SolutionItemViewModel(itemNameRegistry, item, this);

            _children.Add(viewModel);
            _itemToViewmodel.Add(item, viewModel);
        }
        public void Drop(IDropInfo dropInfo)
        {
            SolutionItemViewModel sourceItem = dropInfo.Data as SolutionItemViewModel;
            SolutionItemViewModel targetItem = dropInfo.TargetItem as SolutionItemViewModel;

            if (sourceItem == null)
            {
                return;
            }

            var prevPosition = 0;
            var sourceList   = sourceItem.Parent == null ? solutionManager.Items : sourceItem.Parent.Item.Items;
            SolutionItemViewModel destListOwner = dropInfo.DropTargetAdorner == DropTargetAdorners.Highlight
                ? targetItem
                : targetItem?.Parent;
            var destList = destListOwner?.Item?.Items ?? solutionManager.Items;

            while (destListOwner != null)
            {
                if (sourceItem.Item == destListOwner.Item)
                {
                    return;
                }
                destListOwner = destListOwner.Parent;
            }

            prevPosition = sourceList.IndexOf(sourceItem.Item);
            if (prevPosition >= 0)
            {
                sourceList.RemoveAt(prevPosition);
            }

            if (dropInfo.DropTargetAdorner == DropTargetAdorners.Highlight)
            {
                targetItem.AddViewModel(sourceItem);
                targetItem.Item.Items.Add(sourceItem.Item);
            }
            else
            {
                if (targetItem == null || targetItem.Parent == null)
                {
                    itemToViewmodel[sourceItem.Item] = sourceItem;
                }
                else
                {
                    targetItem.Parent.AddViewModel(sourceItem);
                }

                int destPosition = dropInfo.InsertIndex;
                if (destList == sourceList && dropInfo.InsertIndex >= prevPosition)
                {
                    destPosition--;
                }

                destList.Insert(Math.Clamp(destPosition, 0, destList.Count), sourceItem.Item);
            }
        }
        public SolutionExplorerViewModel(IUnityContainer unity, ISolutionManager solutionManager, IEventAggregator ea)
        {
            _unity = unity;
            _solutionManager = solutionManager;
            _ea = ea;

            _firstGeneration = new ObservableCollection<SolutionItemViewModel>();

            foreach (var item in _solutionManager.Items)
            {
                Root.Add(new SolutionItemViewModel(item));
            }

            _solutionManager.Items.CollectionChanged += (sender, args) =>
            {
                foreach (var obj in args.NewItems)
                {
                    Root.Add(new SolutionItemViewModel(obj as ISolutionItem));
                }
            };

            AddItem = new DelegateCommand(() =>
            {
                ISolutionItem item = _unity.Resolve<INewItemService>().GetNewSolutionItem();
                if (item != null)
                {
                    if (_selected == null)
                        unity.Resolve<ISolutionManager>().Items.Add(item);    
                    else
                        _selected.Item.Items.Add(item);
                }
            });

            SelectedItemChangedCommand = new DelegateCommand<SolutionItemViewModel>((ob) =>
            {
                _selected = ob;
            });

            RequestOpenItem = new DelegateCommand<SolutionItemViewModel>((item) =>
            {
                if (!item.IsContainer)
                    _ea.GetEvent<EventRequestOpenItem>().Publish(item.Item);
            });

            GenerateSQL = new DelegateCommand(() =>
            {
                if (_selected != null)
                {
                    MetaSolutionSQL solution = new MetaSolutionSQL(_selected.Item.ExportSql);
                    _ea.GetEvent<EventRequestOpenItem>().Publish(solution);
                }
            });
        }
Exemplo n.º 5
0
 private void AddItemToRoot(ISolutionItem item, int index = -1)
 {
     if (!_itemToViewmodel.TryGetValue(item, out var viewModel))
     {
         viewModel = new SolutionItemViewModel(itemNameRegistry, item);
         _itemToViewmodel[item] = viewModel;
     }
     else
     {
         viewModel.Parent = null;
     }
     Root.Insert(index < 0 ? Root.Count : index, viewModel);
 }
        public void DragOver(IDropInfo dropInfo)
        {
            SolutionItemViewModel sourceItem = dropInfo.Data as SolutionItemViewModel;
            SolutionItemViewModel targetItem = dropInfo.TargetItem as SolutionItemViewModel;

            if (sourceItem != null)
            {
                bool highlight = dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter) &&
                                 (targetItem?.IsContainer ?? false);

                dropInfo.DropTargetAdorner = highlight ? DropTargetAdorners.Highlight : DropTargetAdorners.Insert;
                dropInfo.Effects           = DragDropEffects.Move;
            }
        }
        private void DeleteSolutionItem(SolutionItemViewModel item)
        {
            if (item.Parent == null)
            {
                this.solutionManager.Items.Remove(item.Item);
            }
            else
            {
                item.Parent.Item.Items?.Remove(item.Item);
            }

            if (item == SelectedItem)
            {
                SelectedItem = null;
            }
        }
        public SolutionItemViewModel(ISolutionItem item, SolutionItemViewModel parent)
        {
            _item   = item;
            _parent = parent;

            if (item.Items != null)
            {
                _children = new ObservableCollection <SolutionItemViewModel>(
                    (from child in item.Items
                     select new SolutionItemViewModel(child, this))
                    .ToList());

                item.Items.CollectionChanged += (sender, args) =>
                {
                    foreach (object t in args.NewItems)
                    {
                        _children.Add(new SolutionItemViewModel(t as ISolutionItem, this));
                    }
                };
            }
        }
Exemplo n.º 9
0
        public SolutionItemViewModel(ISolutionItemNameRegistry itemNameRegistry, ISolutionItem item, SolutionItemViewModel parent)
        {
            this.itemNameRegistry = itemNameRegistry;
            Item   = item;
            Parent = parent;

            itemToViewmodel = new Dictionary <ISolutionItem, SolutionItemViewModel>();

            if (item.Items != null)
            {
                Children = new ObservableCollection <SolutionItemViewModel>();

                foreach (object obj in item.Items)
                {
                    AddItem(obj as ISolutionItem);
                }

                item.Items.CollectionChanged += (sender, args) =>
                {
                    if (args.NewItems != null)
                    {
                        var i = 0;
                        foreach (object obj in args.NewItems)
                        {
                            AddItem(obj as ISolutionItem, args.NewStartingIndex + i);
                        }
                    }

                    if (args.OldItems != null)
                    {
                        foreach (object obj in args.OldItems)
                        {
                            ISolutionItem solutionItem = obj as ISolutionItem;
                            Children.Remove(itemToViewmodel[solutionItem]);
                            itemToViewmodel.Remove(solutionItem);
                        }
                    }
                };
            }
        }
Exemplo n.º 10
0
        public SolutionExplorerViewModel(ISolutionItemNameRegistry itemNameRegistry,
                                         ISolutionManager solutionManager,
                                         IEventAggregator ea,
                                         INewItemService newItemService,
                                         IStatusBar statusBar,
                                         ISolutionItemSqlGeneratorRegistry sqlGeneratorRegistry)
        {
            this.itemNameRegistry = itemNameRegistry;
            _solutionManager      = solutionManager;
            _ea        = ea;
            _statusBar = statusBar;

            _firstGeneration = new ObservableCollection <SolutionItemViewModel>();
            _itemToViewmodel = new Dictionary <ISolutionItem, SolutionItemViewModel>();

            foreach (var item in _solutionManager.Items)
            {
                AddItemToRoot(item);
            }

            _solutionManager.Items.CollectionChanged += (sender, args) =>
            {
                if (args.NewItems != null)
                {
                    int i = 0;
                    foreach (var obj in args.NewItems)
                    {
                        AddItemToRoot(obj as ISolutionItem, args.NewStartingIndex + i);
                        i++;
                    }
                }

                if (args.OldItems != null)
                {
                    foreach (var obj in args.OldItems)
                    {
                        var solutionItem = obj as ISolutionItem;
                        Root.Remove(_itemToViewmodel[solutionItem]);
                        _itemToViewmodel.Remove(solutionItem);
                    }
                }
            };

            AddItem = new DelegateCommand(() =>
            {
                ISolutionItem item = newItemService.GetNewSolutionItem();
                if (item != null)
                {
                    if (_selected == null)
                    {
                        solutionManager.Items.Add(item);
                    }
                    else
                    {
                        _selected.Item.Items.Add(item);
                    }
                }
            });

            RemoveItem = new DelegateCommand(() =>
            {
                if (_selected != null)
                {
                    if (_selected.Parent == null)
                    {
                        _solutionManager.Items.Remove(_selected.Item);
                    }
                    else
                    {
                        _selected.Parent.Item.Items.Remove(_selected.Item);
                    }
                }
            });

            SelectedItemChangedCommand = new DelegateCommand <SolutionItemViewModel>((ob) =>
            {
                _selected = ob;
            });

            RequestOpenItem = new DelegateCommand <SolutionItemViewModel>((item) =>
            {
                if (item != null && !item.IsContainer)
                {
                    _ea.GetEvent <EventRequestOpenItem>().Publish(item.Item);
                }
            });

            GenerateSQL = new DelegateCommand(() =>
            {
                if (_selected != null)
                {
                    MetaSolutionSQL solution = new MetaSolutionSQL(sqlGeneratorRegistry.GenerateSql(_selected.Item));
                    _ea.GetEvent <EventRequestOpenItem>().Publish(solution);
                }
            });
        }
        public SolutionExplorerViewModel(ISolutionItemNameRegistry itemNameRegistry,
                                         ISolutionManager solutionManager,
                                         IEventAggregator ea,
                                         ISolutionSqlService solutionSqlService,
                                         INewItemService newItemService,
                                         IStatusBar statusBar)
        {
            this.itemNameRegistry = itemNameRegistry;
            this.solutionManager  = solutionManager;
            this.ea        = ea;
            this.statusBar = statusBar;

            Root            = new ObservableCollection <SolutionItemViewModel>();
            itemToViewmodel = new Dictionary <ISolutionItem, SolutionItemViewModel>();

            foreach (ISolutionItem item in this.solutionManager.Items)
            {
                AddItemToRoot(item);
            }

            this.solutionManager.Items.CollectionChanged += (sender, args) =>
            {
                if (args.NewItems != null)
                {
                    var i = 0;
                    foreach (object obj in args.NewItems)
                    {
                        AddItemToRoot(obj as ISolutionItem, args.NewStartingIndex + i);
                        i++;
                    }
                }

                if (args.OldItems != null)
                {
                    foreach (object obj in args.OldItems)
                    {
                        ISolutionItem solutionItem = obj as ISolutionItem;
                        Root.Remove(itemToViewmodel[solutionItem]);
                        itemToViewmodel.Remove(solutionItem);
                    }
                }
            };

            AddItem = new DelegateCommand(async() =>
            {
                ISolutionItem item = await newItemService.GetNewSolutionItem();
                if (item != null)
                {
                    if (selected == null || selected.Item.Items == null)
                    {
                        solutionManager.Items.Add(item);
                    }
                    else
                    {
                        selected.Item.Items.Add(item);
                    }
                }
            });

            RemoveItem = new DelegateCommand(() =>
            {
                if (selected != null)
                {
                    if (selected.Parent == null)
                    {
                        this.solutionManager.Items.Remove(selected.Item);
                    }
                    else
                    {
                        selected.Parent.Item.Items.Remove(selected.Item);
                    }
                }
            });

            SelectedItemChangedCommand = new DelegateCommand <SolutionItemViewModel>(ob => { selected = ob; });

            RequestOpenItem = new DelegateCommand <SolutionItemViewModel>(item =>
            {
                if (item != null && !item.IsContainer)
                {
                    this.ea.GetEvent <EventRequestOpenItem>().Publish(item.Item);
                }
            });

            GenerateSQL = new DelegateCommand(() =>
            {
                if (selected != null)
                {
                    solutionSqlService.OpenDocumentWithSqlFor(selected.Item);
                }
            });
        }