Ejemplo n.º 1
0
        /// <summary>
        /// Saves the current configuration under the given name.
        /// </summary>
        /// <param name="name">Configuration name.</param>
        public void SaveConfiguration(string name)
        {
            if (this.configuration == null)
            {
                this.LoadConfigurations();
            }

            DockingLayoutContextConfiguration config;

            if (!this.configuration.Configurations.ContainsKey(name))
            {
                config = new DockingLayoutContextConfiguration(name);
                //config.LayoutPath = "Layout_" + config.ContextName + ".xml";

                this.configuration.AddConfiguration(config);
            }
            else
            {
                config = this.configuration.Configurations[name];
                //if (config.LayoutPath == null)
                //    config.LayoutPath = "Layout_" + config.ContextName + ".xml";
                config.Configurations.Clear();
            }

            string accessKey = this.SelectedShellViewModel.FullFileName;

            if (viewLookup.ContainsKey(accessKey))
            {
                foreach (string paneName in this.viewLookup[accessKey].Keys)
                {
                    IDockableViewModel       vm = this.viewLookup[accessKey][paneName].View;
                    DockingPaneConfiguration c  = new DockingPaneConfiguration(vm.DockingPaneName);
                    c.IsVisible = vm.IsDockingPaneVisible;
                    config.Configurations.Add(c.PaneName, c);

                    if (vm is IRestorableDockableViewModel)
                    {
                        IRestorableDockableViewModel rVm = vm as IRestorableDockableViewModel;

                        c.IsRestorable       = true;
                        c.RestoreInformation = rVm.GetInformationForRestore();
                        c.DockingPaneType    = rVm.GetDockingPaneType();
                    }
                }
            }

            if (viewLookup.ContainsKey(TransientPanesKey))
            {
                foreach (string paneName in this.viewLookup[TransientPanesKey].Keys)
                {
                    IDockableViewModel       vm = this.viewLookup[TransientPanesKey][paneName].View;
                    DockingPaneConfiguration c  = new DockingPaneConfiguration(vm.DockingPaneName);
                    c.IsVisible = vm.IsDockingPaneVisible;
                    config.Configurations.Add(c.PaneName, c);
                }
            }

            // save layout ...
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Called whenever the active pane changes.
 /// </summary>
 /// <param name="paneConfiguration"></param>
 protected void OnRestoreLayoutMissingVMEncountered(DockingPaneConfiguration paneConfiguration)
 {
     if (RestoreLayoutMissingVMEncountered != null)
     {
         RestoreLayoutMissingVMEncountered(this,
                                           new MissingViewModelEventArgs()
         {
             DockingPaneConfiguration = paneConfiguration,
         }
                                           );
     }
 }
Ejemplo n.º 3
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
            //}
        }