Ejemplo n.º 1
0
        private void InternalAddDocument(IPanelModel document)
        {
            IPanelFactory   factory = PluginFactory.FindPanelFactory(document);
            IPanelViewModel vm      = factory.CreateViewModel(this, document);

            this.Documents.Add(vm);
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.dialogNavigationService      = new Mock <IDialogNavigationService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.filterStringService          = new Mock <IFilterStringService>();

            this.describeMetaData = new Mock <INameMetaData>();
            this.describeMetaData.Setup(x => x.Name).Returns("MockedPanelDecorated");

            this.panelView       = new Test(true);
            this.panelViewModel  = new TestViewModel();
            this.panelViewModel2 = new TestViewModel("data source");

            this.viewList = new List <IPanelView>();
            this.viewList.Add(this.panelView);
            this.viewList.Add(new TestGrid());

            this.viewModelDecoratedList = new List <Lazy <IPanelViewModel, INameMetaData> >();
            this.viewModelDecoratedList.Add(new Lazy <IPanelViewModel, INameMetaData>(() => this.panelViewModel2, this.describeMetaData.Object));

            this.viewModelList = new List <IPanelViewModel>();
            this.viewModelList.Add(this.panelViewModel);
            this.viewModelList.Add(new TestGridViewModel());

            this.dockLayoutViewModel = new DockLayoutViewModel(dialogNavigationService.Object);

            this.NavigationService = new PanelNavigationService(this.viewList, this.viewModelList, this.viewModelDecoratedList, this.dockLayoutViewModel, this.filterStringService.Object);

            this.session           = new Mock <ISession>();
            this.permissionService = new Mock <IPermissionService>();
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
        }
 /// <summary>
 /// Closes the view associated with the <see cref="IPanelViewModel"/> in the AddIn
 /// </summary>
 /// <param name="viewModel">The <see cref="IPanelViewModel"/> to close</param>
 public void CloseInAddIn(IPanelViewModel viewModel)
 {
     if (this.AddInViewModelViewPairs.TryGetValue(viewModel, out var view))
     {
         this.CleanUpPanelsAndSendCloseEvent(viewModel, view);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Opens the view associated to the provided view-model
        /// </summary>
        /// <param name="viewModel">
        /// The <see cref="IPanelViewModel"/> for which the associated view needs to be opened
        /// </param>
        /// <param name="useRegionManager">
        /// A value indicating whether handling the opening of the view shall be handled by the region manager. In case this region manager does not handle
        /// this it will be event-based using the <see cref="CDPMessageBus"/>.
        /// </param>
        /// <remarks>
        /// The data context of the view is the <see cref="IPanelViewModel"/>
        /// </remarks>
        public void Open(IPanelViewModel viewModel, bool useRegionManager)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel), "The IPanelViewModel may not be null");
            }

            if (useRegionManager)
            {
                this.Open(viewModel);
            }
            else
            {
                IPanelView view;
                this.ViewModelViewPairs.TryGetValue(viewModel, out view);

                string regionName = string.Empty;

                if (view == null)
                {
                    var lazyView = this.GetViewType(viewModel);
                    regionName = lazyView.Metadata.Region;

                    var parameters = new object[] { true };
                    view             = Activator.CreateInstance(lazyView.Value.GetType(), parameters) as IPanelView;
                    view.DataContext = viewModel;
                    this.ViewModelViewPairs.Add(viewModel, view);
                }

                var openPanelEvent = new NavigationPanelEvent(viewModel, view, PanelStatus.Open, regionName);
                CDPMessageBus.Current.SendMessage(openPanelEvent);
            }
        }
        public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            var             itemAsLayoutContent = item as LayoutContent;
            IPanelViewModel vm      = item as IPanelViewModel;
            IPanelFactory   factory = vm?.ParentFactory;

            if (factory != null)
            {
                var template = new DataTemplate();
                FrameworkElementFactory spFactory = new FrameworkElementFactory(factory.ViewType);

                spFactory.SetValue(Control.DataContextProperty, vm);
                template.VisualTree = spFactory;
                return(template);
            }

            if (item is MarkerPaneViewModel)
            {
                return(MarkersPaneTemplate);
            }

            if (item is ProjectPaneViewModel)
            {
                return(ProjectPaneTemplate);
            }

            return(base.SelectTemplate(item, container));
        }
Ejemplo n.º 6
0
        private void InternalAddAnchorable(PaneModel pane)
        {
            IPanelFactory   factory = PluginFactory.FindPanelFactory(pane);
            IPanelViewModel vm      = factory.CreateViewModel(this, pane);

            this.Anchorables.Add(vm);
        }
        /// <summary>
        /// Closes the <see cref="IPanelView"/> associated to the <see cref="IPanelViewModel"/>
        /// </summary>
        /// <param name="viewModel">
        /// The view-model that is to be closed.
        /// </param>
        public void CloseInDock(IPanelViewModel viewModel)
        {
            logger.Debug("Starting to Close view-model {0} of type {1}", viewModel.Caption, viewModel);

            this.dockLayoutViewModel.DockPanelViewModels.Remove(viewModel);

            logger.Debug("Closed view-model {0} of type {1}", viewModel.Caption, viewModel);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Unregisters a panel view from all relevant collections.
        /// </summary>
        /// <param name="view">The view to unregister.</param>
        public void UnregisterFromService(IPanelViewModel viewModel)
        {
            if (viewModel is not IPanelFilterableDataGridViewModel panelFilterableDataGridViewModel)
            {
                return;
            }

            this.RemoveView(panelFilterableDataGridViewModel);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// removes the view and view-model from the <see cref="ViewModelViewPairs"/> and send a panel close event
        /// </summary>
        /// <param name="panelViewModel">
        /// The <see cref="IPanelViewModel"/> that needs to be cleaned up
        /// </param>
        /// <param name="panelView">
        /// The <see cref="IPanelView"/> that needs to be cleaned up
        /// </param>
        private void CleanUpPanelsAndSendCloseEvent(IPanelViewModel panelViewModel, IPanelView panelView)
        {
            this.ViewModelViewPairs.Remove(panelViewModel);
            var closePanelEvent = new NavigationPanelEvent(panelViewModel, panelView, PanelStatus.Closed);

            CDPMessageBus.Current.SendMessage(closePanelEvent);
            panelView.DataContext = null;
            panelViewModel.Dispose();
        }
 /// <summary>
 /// Re-opens an exisiting View associated to the provided view-model, or opens a new View
 /// Re-opening is done by sending a <see cref="CDPMessageBus"/> event.
 /// This event can be handled by more specific code,  for example in the addin, where some
 /// ViewModels should not close at all. For those viewmodels visibility is toggled on every
 /// <see cref="NavigationPanelEvent"/> event that has <see cref="PanelStatus.Open"/> set.
 /// </summary>
 /// <param name="viewModel">
 /// The <see cref="IPanelViewModel"/> for which the associated view needs to be opened, or closed
 /// </param>
 public void OpenExistingOrOpenInAddIn(IPanelViewModel viewModel)
 {
     if (this.AddInViewModelViewPairs.TryGetValue(viewModel, out var view))
     {
         var openPanelEvent = new NavigationPanelEvent(viewModel, view, PanelStatus.Open);
         CDPMessageBus.Current.SendMessage(openPanelEvent);
     }
     else
     {
         this.OpenInAddIn(viewModel);
     }
 }
        /// <summary>
        /// Finalizes the <see cref="IPanelViewModel"/> on close
        /// </summary>
        /// <param name="panelViewModel">
        /// The <see cref="IPanelViewModel"/> that needs to be cleaned up
        /// </param>
        private void CleanUpPanelsAndSendCloseEvent(IPanelViewModel panelViewModel)
        {
            var closePanelEvent = new NavigationPanelEvent(panelViewModel, null, PanelStatus.Closed);

            CDPMessageBus.Current.SendMessage(closePanelEvent);

            panelViewModel.Dispose();

            // unregister from filter string service
            this.filterStringService.UnregisterFromService(panelViewModel);

            this.OptimizeMemoryUsage();
        }
        /// <summary>
        /// Gets the fully qualified name of the <see cref="IPanelView"/> associated to the <see cref="IPanelViewModel"/>
        /// </summary>
        /// <remarks>
        /// We assume here that for a <see cref="IPanelViewModel"/> with a fully qualified name xxx.yyy.ViewModels.DialogViewModel, the counterpart view is xxx.yyy.Views.Dialog
        /// </remarks>
        /// <param name="viewModel">The <see cref="IPanelViewModel"/></param>
        /// <returns>The Fully qualified Name</returns>
        private Type GetViewType(IPanelViewModel viewModel)
        {
            var fullyQualifiedName = viewModel.ToString().Replace(".ViewModels.", ".Views.");

            // remove "ViewModel" from the name to get the View Name
            var viewName = Regex.Replace(fullyQualifiedName, "ViewModel$", string.Empty);

            if (!this.PanelViewKinds.TryGetValue(viewName, out var viewInstance))
            {
                throw new ArgumentOutOfRangeException($"The View associated to the viewModel {viewModel} could not be found\nMake sure the view has the proper attributes");
            }

            return(viewInstance.GetType());
        }
Ejemplo n.º 13
0
        /// <summary>
        /// removes the view and view-model from the <see cref="ViewModelViewPairs"/> and send a panel close event
        /// </summary>
        /// <param name="panelViewModel">
        /// The <see cref="IPanelViewModel"/> that needs to be cleaned up
        /// </param>
        /// <param name="panelView">
        /// The <see cref="IPanelView"/> that needs to be cleaned up
        /// </param>
        private void CleanUpPanelsAndSendCloseEvent(IPanelViewModel panelViewModel, IPanelView panelView)
        {
            this.ViewModelViewPairs.Remove(panelViewModel);

            var closePanelEvent = new NavigationPanelEvent(panelViewModel, panelView, PanelStatus.Closed);

            CDPMessageBus.Current.SendMessage(closePanelEvent);

            panelView.DataContext = null;
            panelViewModel.Dispose();

            // unregister from filter string service
            this.filterStringService.UnregisterFromService(panelView);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Closes the <see cref="IPanelView"/> associated to the <see cref="IPanelViewModel"/>
 /// </summary>
 /// <param name="viewModel">
 /// The view-model that is to be closed.
 /// </param>
 /// <param name="useRegionManager">
 /// A value indicating whether handling the opening of the view shall be handled by the region manager. In case this region manager does not handle
 /// this it will be event-based using the <see cref="CDPMessageBus"/>.
 /// </param>
 public void Close(IPanelViewModel viewModel, bool useRegionManager)
 {
     if (useRegionManager)
     {
         this.Close(viewModel);
     }
     else
     {
         if (this.ViewModelViewPairs.TryGetValue(viewModel, out var view))
         {
             this.CleanUpPanelsAndSendCloseEvent(viewModel, view);
         }
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Closes the <see cref="IPanelView"/> associated to the <see cref="IPanelViewModel"/>
        /// </summary>
        /// <param name="viewModel">The <see cref="IPanelViewModel"/></param>
        private void Close(IPanelViewModel viewModel)
        {
            logger.Debug("Starting to Close view-model {0} of type {1}", viewModel.Caption, viewModel);

            IPanelView view;

            if (this.ViewModelViewPairs.TryGetValue(viewModel, out view))
            {
                var viewRegion = this.GetViewType(viewModel).Metadata.Region;
                var region     = this.regionManager.Regions[viewRegion];
                region.Remove(view);

                logger.Debug("Closed view-model {0} of type {1}", viewModel.Caption, viewModel);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets the fully qualified name of the <see cref="IPanelView"/> associated to the <see cref="IPanelViewModel"/>
        /// </summary>
        /// <remarks>
        /// We assume here that for a <see cref="IPanelViewModel"/> with a fully qualified name xxx.yyy.ViewModels.DialogViewModel, the counterpart view is xxx.yyy.Views.Dialog
        /// </remarks>
        /// <param name="viewModel">The <see cref="IPanelViewModel"/></param>
        /// <returns>The Fully qualified Name</returns>
        private Lazy <IPanelView, IRegionMetaData> GetViewType(IPanelViewModel viewModel)
        {
            var fullyQualifiedName = viewModel.ToString().Replace(".ViewModels.", ".Views.");

            // remove "ViewModel" from the name to get the View Name
            var viewName = System.Text.RegularExpressions.Regex.Replace(fullyQualifiedName, "ViewModel$", "");

            if (!this.PanelViewKinds.TryGetValue(viewName, out var returned))
            {
                throw new ArgumentOutOfRangeException(
                          $"The View associated to the viewModel {viewModel} could not be found\nMake sure the view has the proper attributes");
            }

            return(returned);
        }
Ejemplo n.º 17
0
        public void SetViewComponent(IPanelViewModel panelView, ViewBuildersCollection viewBuilders)
        {
            this.BindingContext = panelView;
            var children = panelView.GetChildren();
            int currRow  = 0;

            foreach (var childView in children)
            {
                AddRow();
                AddRow();
                AddLabelView(currRow, childView);
                AddFieldView(currRow, childView, viewBuilders);
                currRow += 2;
            }
        }
        /// <summary>
        /// Opens the view associated to the provided view-model in the dock
        /// </summary>
        /// <param name="viewModel">
        /// The <see cref="IPanelViewModel"/> for which the associated view needs to be opened
        /// </param>
        /// <remarks>
        /// The data context of the view is the <see cref="IPanelViewModel"/>
        /// </remarks>
        public void OpenInDock(IPanelViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel), $"The {nameof(IPanelViewModel)} may not be null");
            }

            var sw = Stopwatch.StartNew();

            this.dockLayoutViewModel.AddDockPanelViewModel(viewModel);

            this.filterStringService.RegisterForService(viewModel);

            logger.Trace("Navigated to Panel {0} in {1} [ms]", viewModel, sw.ElapsedMilliseconds);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Closes the <see cref="IPanelView"/> associated to the <see cref="IPanelViewModel"/>
        /// </summary>
        /// <param name="viewModel">The <see cref="IPanelViewModel"/></param>
        private void Close(IPanelViewModel viewModel)
        {
            logger.Debug("Starting to Close view-model {0} of type {1}", viewModel.Caption, viewModel);

            if (this.ViewModelViewPairs.TryGetValue(viewModel, out var view))
            {
                var regions = this.regionCollectionSearcher.GetRegionsByView(this.regionManager.Regions, view);

                foreach (var region in regions)
                {
                    region.Remove(view);
                }

                logger.Debug("Closed view-model {0} of type {1}", viewModel.Caption, viewModel);
            }
        }
Ejemplo n.º 20
0
        public void SetViewComponent(IPanelViewModel panelView, ViewBuildersCollection viewBuilders)
        {
            this.DataContext = panelView;
            var children = panelView.GetChildren();
            int currRow  = 0;

            foreach (var childView in children)
            {
                AddRow();
                AddRow();
                AddLabelView(currRow, childView);
                PanelHelper.AddFieldViewAsRow(currRow, childView, viewBuilders, ChildrenViewsContainer);
                //AddFieldView(currRow, childView, viewBuilders);
                currRow += 2;
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Opens the <see cref="IPanelView"/> associated to the <see cref="IPanelViewModel"/>
        /// </summary>
        /// <param name="viewModel">The <see cref="IPanelViewModel"/></param>
        private void Open(IPanelViewModel viewModel)
        {
            var lazyView = this.GetViewType(viewModel);

            var parameters = new object[] { true };
            var view       = Activator.CreateInstance(lazyView.Value.GetType(), parameters) as IPanelView;

            view.DataContext = viewModel;

            this.ViewModelViewPairs.Add(viewModel, view);

            var region = this.regionManager.Regions[lazyView.Metadata.Region];

            region.Add(view, view.ToString() + Guid.NewGuid());

            logger.Trace("Navigated to Panel {0}", viewModel);
        }
Ejemplo n.º 22
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.dialogNavigationService      = new Mock <IDialogNavigationService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.filterStringService          = new Mock <IFilterStringService>();

            this.regionManager   = new Mock <IRegionManager>();
            this.region          = new Mock <IRegion>();
            this.metadata        = new Mock <IRegionMetaData>();
            this.viewsCollection = new Mock <IViewsCollection>();

            this.describeMetaData = new Mock <INameMetaData>();
            this.describeMetaData.Setup(x => x.Name).Returns("MockedPanelDecorated");

            this.regionCollectionSearcher = new Mock <IRegionCollectionSearcher>();
            this.regionCollectionSearcher.Setup(x => x.GetRegionsByView(It.IsAny <IRegionCollection>(), It.IsAny <IPanelView>())).Returns(new [] { this.region.Object });
            this.regionManager.Setup(x => x.Regions[It.IsAny <string>()]).Returns(this.region.Object);
            this.region.Setup(x => x.Views).Returns(this.viewsCollection.Object);

            this.panelView       = new Test(true);
            this.panelViewModel  = new TestViewModel();
            this.panelViewModel2 = new TestViewModel("data source");

            this.viewList = new List <Lazy <IPanelView, IRegionMetaData> >();
            this.viewList.Add(new Lazy <IPanelView, IRegionMetaData>(() => this.panelView, this.metadata.Object));
            this.viewList.Add(new Lazy <IPanelView, IRegionMetaData>(() => new PropertyGrid(), this.metadata.Object));

            this.viewModelDecoratedList = new List <Lazy <IPanelViewModel, INameMetaData> >();
            this.viewModelDecoratedList.Add(new Lazy <IPanelViewModel, INameMetaData>(() => this.panelViewModel2, this.describeMetaData.Object));

            this.viewModelList = new List <IPanelViewModel>();
            this.viewModelList.Add(this.panelViewModel);
            this.viewModelList.Add(new PropertyGridViewModel());

            this.NavigationService = new PanelNavigationService(this.viewList, this.viewModelList, this.regionManager.Object, this.viewModelDecoratedList, this.filterStringService.Object, this.regionCollectionSearcher.Object);

            this.session           = new Mock <ISession>();
            this.permissionService = new Mock <IPermissionService>();
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
        }
        /// <summary>
        /// Opens the view associated with the <see cref="IPanelViewModel"/> in the AddIn
        /// </summary>
        /// <param name="viewModel">The <see cref="IPanelViewModel"/> to open</param>
        public void OpenInAddIn(IPanelViewModel viewModel)
        {
            var viewType = this.GetViewType(viewModel);

            var parameters = new object[] { true };
            var view       = Activator.CreateInstance(viewType, parameters) as IPanelView;

            if (view != null)
            {
                view.DataContext = viewModel;
                this.AddInViewModelViewPairs.Add(viewModel, view);

                // register for Filter Service
                this.filterStringService.RegisterForService(viewModel);
            }

            var openPanelEvent = new NavigationPanelEvent(viewModel, view, PanelStatus.Open);

            CDPMessageBus.Current.SendMessage(openPanelEvent);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Registers a filterable panel view and viewmodel combo to this service.
        /// </summary>
        /// <param name="view">The view that is to be registered</param>
        /// <param name="viewModel">The viewmodel that is to be registered</param>
        public void RegisterForService(IPanelViewModel viewModel)
        {
            if (viewModel is not IPanelFilterableDataGridViewModel panelFilterableDataGridViewModel)
            {
                // if not filterable view, do not bother registration
                return;
            }

            if (viewModel is IDeprecatableBrowserViewModel)
            {
                // deprecatable viewmodel
                this.AddDeprecatedControl(panelFilterableDataGridViewModel);
            }

            if (viewModel is IFavoritesBrowserViewModel)
            {
                // favoritable viewmodel
                this.AddFavoritesControl(panelFilterableDataGridViewModel);
            }
        }
        public void SetViewComponent(IPanelViewModel panelView, ViewBuildersCollection viewBuilders)
        {
            this.DataContext = panelView;
            var children = panelView.GetChildren();
            int currCol  = 1;

            AddPadColumn(3);
            foreach (var childView in children)
            {
                if (currCol > 1)
                {
                    AddPadColumn(1);
                }
                AddColumn();
                AddLabelView(currCol, childView);
                PanelHelper.AddFieldViewAsCol(currCol, childView, viewBuilders, ChildrenViewsContainer);
                currCol += 2;
            }
            AddPadColumn(3);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NavigationPanelEvent"/> class
 /// </summary>
 /// <param name="viewModel">
 /// The <see cref="IPanelViewModel"/> associated to the panel
 /// </param>
 /// <param name="view">
 /// The <see cref="IPanelView"/> that is to be opened
 /// </param>
 /// <param name="status">
 /// The status of the panel
 /// </param>
 /// <param name="regionName">
 /// The name of the region in which the panel shall be opened
 /// </param>
 public NavigationPanelEvent(IPanelViewModel viewModel, IPanelView view, PanelStatus status)
 {
     this.ViewModel   = viewModel;
     this.View        = view;
     this.PanelStatus = status;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ViewModelChangeEvent"/> class
 /// </summary>
 /// <param name="viewModel">
 /// The event's <see cref="IPanelViewModel"/>
 /// </param>
 public ViewModelChangeEvent(IPanelViewModel viewModel)
 {
     this.ViewModel = viewModel;
 }
 /// <summary>
 /// Adds a panel to the dock
 /// </summary>
 /// <param name="panelViewModel">The <see cref="IPanelViewModel"/> to add to the dock</param>
 public void AddDockPanelViewModel(IPanelViewModel panelViewModel)
 {
     this.DockPanelViewModels.Add(panelViewModel);
     panelViewModel.IsSelected = true;
 }
Ejemplo n.º 29
0
 public virtual IPanelView CreateView(IPanelViewModel viewModel)
 {
     return(new View());
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NavigationPanelEvent"/> class
 /// </summary>
 /// <param name="viewModel">
 /// The <see cref="IPanelViewModel"/> associated to the panel
 /// </param>
 /// <param name="view">
 /// The <see cref="IPanelView"/> that is to be opened
 /// </param>
 /// <param name="status">
 /// The status of the panel
 /// </param>
 /// <param name="regionName">
 /// The name of the region in which the panel shall be opened
 /// </param>
 public NavigationPanelEvent(IPanelViewModel viewModel, IPanelView view, PanelStatus status, string regionName = "")
 {
     this.ViewModel   = viewModel;
     this.View        = view;
     this.PanelStatus = status;
 }