Beispiel #1
0
        /// <summary>
        /// Adds a view model as a child model of this view model.
        /// </summary>
        /// <param name="viewModel">View model to add to the children collection.</param>
        public void AddAdditionalViewModel(BaseDiagramSurfaceViewModel viewModel)
        {
            this.allDiagramSurfaceModels.Add(viewModel);
            this.additionalDiagramSurfaceModels.Add(viewModel);

            this.MainViewModel.AddViewModel(viewModel);
        }
Beispiel #2
0
 /// <summary>
 /// Show plugin if it was shown before (layout manager stores the information).
 /// </summary>
 /// <param name="viewModel"></param>
 public override void ShowPluginIfShownBefore(BaseDiagramSurfaceViewModel viewModel)
 {
     if (this.LayoutManager != null)
     {
         this.LayoutManager.ShowWindowBasedOnConfiguraion(viewModel);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Close model command executed.
        /// </summary>
        /// <returns></returns>
        protected virtual bool CloseModelCommandExecute()
        {
            if (this.SelectedModelContextViewModel == null)
            {
                return(false);
            }
            if (this.SelectedModelContextViewModel.ModelContext == null)
            {
                return(false);
            }

            if (this.SelectedModelContextViewModel.ModelContext.IsDirty)
            {
                IMessageBoxService  messageBox = this.GlobalServiceProvider.Resolve <IMessageBoxService>();
                CustomDialogResults dlgResult  = messageBox.ShowYesNoCancel("Save changes to the current Model?", CustomDialogIcons.Question);
                if (dlgResult == CustomDialogResults.Cancel)
                {
                    return(false);
                }
                else if (dlgResult == CustomDialogResults.Yes)
                {
                    using (new ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
                    {
                        this.SelectedModelContextViewModel.ModelContext.Save((this.SelectedModelContextViewModel.ModelContext.RootElement as IParentModelElement).DomainFilePath);
                        //this.SelectedModelContextViewModel.ModelContext.Save(this.ViewModelStore.GetDomainModelServices(this.SelectedModelContextViewModel.ModelContext.RootElement).ElementParentProvider.GetDomainModelFilePath(this.SelectedModelContextViewModel.ModelContext.RootElement));
                    }
                }
            }
            using (new ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
            {
                for (int i = this.UnknownOpenedModels.Count - 1; i >= 0; i--)
                {
                    BaseDiagramSurfaceViewModel vm = this.UnknownOpenedModels[i] as BaseDiagramSurfaceViewModel;
                    if (vm == null)
                    {
                        continue;
                    }

                    //foreach (BaseDiagramSurfaceViewModel vm in this.UnknownOpenedModels)
                    if (!vm.IsDisposed)
                    {
                        this.EventManager.GetEvent <CloseViewModelRequestEvent>().Publish(new CloseViewModelRequestEventArgs(vm, true));
                    }
                }

                this.Reset();
                this.ModelData.Reset();
            }

            this.CloseCommand.RaiseCanExecuteChanged();
            this.SaveAsModelCommand.RaiseCanExecuteChanged();
            this.SaveModelCommand.RaiseCanExecuteChanged();

            this.SelectedModelContextViewModel.OnDocumentClosed();

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Adds a view model as a child model of this view model.
        /// </summary>
        /// <param name="viewModel">View model to add to the children collection.</param>
        public void AddPluginViewModel(BaseDiagramSurfaceViewModel viewModel)
        {
            this.allDiagramSurfaceModels.Add(viewModel);
            this.pluginDiagramSurfaceModels.Add(viewModel);

            this.MainViewModel.AddViewModel(viewModel);

            if (this == this.MainViewModel.SelectedModelContextViewModel)
            {
                this.MainViewModel.ShowPluginIfShownBefore(viewModel);
            }

            this.OnPropertyChanged("PluginDiagramSurfaceModels");
            this.OnPropertyChanged("HasPluginDiagramSurfaceModels");
        }
Beispiel #5
0
        /// <summary>
        /// Open model.
        /// </summary>
        /// <param name="fileName">File to open.</param>
        public virtual void OpenModel(string fileName)
        {
            if (this.SelectedModelContextViewModel == null)
            {
                return;
            }
            if (this.SelectedModelContextViewModel.ModelContext == null)
            {
                return;
            }

            if (CloseModelCommandCanExecute())
            {
                if (!CloseModelCommandExecute())
                {
                    return;
                }
            }

            if (this.Ribbon != null)
            {
                this.Ribbon.IsBackstageOpen = false;
            }

            if (!System.IO.File.Exists(fileName))
            {
                IMessageBoxService messageBox = this.GlobalServiceProvider.Resolve <IMessageBoxService>();
                messageBox.ShowError("File does not exists: " + fileName);
                return;
            }

            // LOAD model in background thread
            // in main UI thread, load avalondock
            // --> wait on ui thread for model load to finish...

            /*if (!this.isInitialyInitialized)
             * {
             #region MT-Load
             *  PleaseWaitHelper.Show();
             *
             *  loadingModelEvent.Reset();
             *
             *  this.ViewModelStore.InLoad = true;
             *  this.Reset();
             *
             *  System.ComponentModel.BackgroundWorker loadModel = new System.ComponentModel.BackgroundWorker();
             *  loadModel.DoWork += new System.ComponentModel.DoWorkEventHandler(loadModel_DoWork);
             *  loadModel.RunWorkerAsync(fileName);
             *
             *  this.Initialize();
             *  this.loadingModelEvent.WaitOne();
             *
             *  // add to mru list
             *  this.MRUFilesViewModel.AddMRUEntry(fileName);
             *
             *  // clear current error list
             *  this.EventManager.GetEvent<ErrorListClearItems>().Publish(this);
             *
             *  List<BaseErrorListItemViewModel> items = new List<BaseErrorListItemViewModel>();
             *  if (this.SelectedModelContextViewModel.ModelContext.SerializationResult.Count() > 0)
             *  {
             *      // add serialization result items
             *
             *      foreach (SerializationMessage serializationMessage in this.SelectedModelContextViewModel.ModelContext.SerializationResult)
             *      {
             *          SerializationErrorListItemViewModel item = new SerializationErrorListItemViewModel(this.ViewModelStore, serializationMessage);
             *          items.Add(item);
             *      }
             *  }
             *
             *  if (this.SelectedModelContextViewModel.ModelContext.ValidationResult.Count > 0)
             *  {
             *      foreach (IValidationMessage message in this.SelectedModelContextViewModel.ModelContext.ValidationResult)
             *      {
             *          if (message is ModelValidationMessage)
             *          {
             *              ModelErrorListItemViewModel item = new ModelErrorListItemViewModel(this.ViewModelStore, message as ModelValidationMessage);
             *              items.Add(item);
             *          }
             *          else if (message is ValidationMessage)
             *          {
             *              StringErrorListItemViewModel item = new StringErrorListItemViewModel(this.ViewModelStore, message.MessageId, ModelErrorListItemViewModel.ConvertCategory(message.Type), message.Description);
             *              items.Add(item);
             *          }
             *      }
             *  }
             *
             *  this.ViewModelStore.InLoad = false;
             *
             *  // Open views based on the configuration in the layout manager
             *  if (this.LayoutManager != null)
             *      if (this.LayoutManager.ConfigurationManager != null)
             *          foreach (string paneName in this.LayoutManager.CurrentConfiguration.Configurations.Keys)
             *          {
             *              DockingPaneConfiguration paneConfig = this.LayoutManager.CurrentConfiguration.Configurations[paneName];
             *              if (paneConfig.IsRestorable && paneConfig.RestoreInformation != null && paneConfig.DockingPaneType != null)
             *              {
             *                  if (!this.LayoutManager.HasWindow(paneConfig.PaneName))
             *                  {
             *                      // create new modal window
             *                      BaseDiagramSurfaceViewModel vm = this.ViewModelStore.TopMostStore.Factory.CreateRestorableViewModel(paneConfig.DockingPaneType);
             *                      if (vm != null && vm is IRestorableDockableViewModel)
             *                      {
             *                          if ((vm as IRestorableDockableViewModel).Restore(paneConfig.RestoreInformation))
             *                          {
             *                              OpenViewModelEventArgs args = new OpenViewModelEventArgs(vm);
             *                              args.DockingPaneStyle = PDE.ToolFramework.Modeling.Visualization.ViewModel.DockingPaneStyle.DockedInDocumentPane;
             *                              this.EventManager.GetEvent<OpenViewModelEvent>().Publish(args);
             *                          }
             *                          else
             *                          {
             *                              vm.Dispose();
             *                          }
             *                      }
             *                  }
             *              }
             *
             *
             *              // notify of change
             *              if (items.Count > 0)
             *                  this.EventManager.GetEvent<ErrorListAddItems>().Publish(items);
             *          }
             *
             *  PleaseWaitHelper.Hide();
             #endregion
             * }
             * else
             * {*/
            #region Normal Load
            using (new ToolFramework.Modeling.Visualization.ViewModel.UI.WaitCursor())
            {
                this.ViewModelStore.InLoad = true;

                this.Reset();
                this.SelectedModelContextViewModel.ModelContext.Load(fileName, false);

                // add to mru list
                this.MRUFilesViewModel.AddMRUEntry(fileName);

                // clear current error list
                this.EventManager.GetEvent <ErrorListClearItems>().Publish(this);

                List <BaseErrorListItemViewModel> items = new List <BaseErrorListItemViewModel>();

                if (this.SelectedModelContextViewModel.ModelContext.SerializationResult.Count() > 0)
                {
                    // add serialization result items

                    foreach (SerializationMessage serializationMessage in this.SelectedModelContextViewModel.ModelContext.SerializationResult)
                    {
                        SerializationErrorListItemViewModel item = new SerializationErrorListItemViewModel(this.ViewModelStore, serializationMessage);
                        items.Add(item);
                    }
                }

                if (this.SelectedModelContextViewModel.ModelContext.ValidationResult.Count > 0)
                {
                    foreach (IValidationMessage message in this.SelectedModelContextViewModel.ModelContext.ValidationResult)
                    {
                        if (message is ModelValidationMessage)
                        {
                            ModelErrorListItemViewModel item = new ModelErrorListItemViewModel(this.ViewModelStore, message as ModelValidationMessage);
                            items.Add(item);
                        }
                        else if (message is ValidationMessage)
                        {
                            StringErrorListItemViewModel item = new StringErrorListItemViewModel(this.ViewModelStore, message.MessageId, ModelErrorListItemViewModel.ConvertCategory(message.Type), message.Description);
                            items.Add(item);
                        }
                    }
                }

                this.ViewModelStore.InLoad = false;

                // Open views based on the configuration in the layout manager
                if (this.LayoutManager != null)
                {
                    if (this.LayoutManager.ConfigurationManager != null)
                    {
                        foreach (string paneName in this.LayoutManager.CurrentConfiguration.Configurations.Keys)
                        {
                            DockingPaneConfiguration paneConfig = this.LayoutManager.CurrentConfiguration.Configurations[paneName];
                            if (paneConfig.IsRestorable && paneConfig.RestoreInformation != null && paneConfig.DockingPaneType != null)
                            {
                                if (!this.LayoutManager.HasWindow(paneConfig.PaneName))
                                {
                                    // create new modal window
                                    BaseDiagramSurfaceViewModel vm = this.ViewModelStore.TopMostStore.Factory.CreateRestorableViewModel(paneConfig.DockingPaneType);
                                    if (vm != null && vm is IRestorableDockableViewModel)
                                    {
                                        if ((vm as IRestorableDockableViewModel).Restore(paneConfig.RestoreInformation))
                                        {
                                            OpenViewModelEventArgs args = new OpenViewModelEventArgs(vm);
                                            args.DockingPaneStyle = PDE.ToolFramework.Modeling.Visualization.ViewModel.DockingPaneStyle.DockedInDocumentPane;
                                            this.EventManager.GetEvent <OpenViewModelEvent>().Publish(args);
                                        }
                                        else
                                        {
                                            vm.Dispose();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // notify of change
                if (items.Count > 0)
                {
                    this.EventManager.GetEvent <ErrorListAddItems>().Publish(items);
                }
            }
            #endregion
            //}
        }
 /// <summary>
 /// Show plugin if it was shown before (layout manager stores the information).
 /// </summary>
 /// <param name="viewModel"></param>
 public virtual void ShowPluginIfShownBefore(BaseDiagramSurfaceViewModel viewModel)
 {
 }