Example #1
0
 public void SetActive(object data)
 {
     if (data is IModelSystemStructure)
     {
         // If we are here then we were called from the parent level
         this.CurrentModule = data as IModelSystemStructure;
         this.Context       = new ModelSystemPageContext();
         var project = this.XTMF.CurrentProject;
         this.Context.Project     = project;
         this.Context.ModelSystem = data as IModelSystemStructure;
         this.Context.CurrentNode = data as IModelSystemStructure;
         this.Delete.IsEnabled    = true;
         this.ParentNodes.Clear();
         var index = project.ModelSystemStructure.IndexOf(CurrentModule);
         if (index >= 0)
         {
             bool   editMode = false;
             string value;
             if (this.XTMF.XTMF.Configuration.AdditionalSettings.TryGetValue("EditProjects", out value))
             {
                 bool.TryParse(value, out editMode);
             }
             this.ModelSystemInterface.LoadProject(project, index, editMode);
             this.ColourKey.EditMode = editMode;
         }
         this.Run.IsEnabled = true;
     }
     else if (data is ModelSystemPageContext)
     {
         var context = data as ModelSystemPageContext;
         this.Context          = context;
         this.CurrentModule    = context.CurrentNode;
         this.Delete.IsEnabled = context.CurrentNode == context.ModelSystem;
     }
     else if (data is QuestionResult)
     {
         var result = data as QuestionResult;
         if (result.Success == true)
         {
             if (result.Data == null || result.Data is IModelSystemStructure)
             {
                 var module = result.Data as IModelSystemStructure;
                 if (module != null)
                 {
                     this.ModelSystemInterface.AddCommand(new ModuleRenameCommand(module, result.Result));
                     this.ModuleNameLabel.Text = this.CurrentModule.Name;
                     this.ModelSystemInterface.Refresh(module);
                 }
                 else
                 {
                     this.ModelSystemInterface.AddCommand(new ModuleRenameCommand(CurrentModule, result.Result));
                     this.ModuleNameLabel.Text = this.CurrentModule.Name;
                     this.ModelSystemInterface.Refresh(this.CurrentModule);
                 }
                 this.ModuleNameLabel.ToolTip        = this.ModuleNameLabel.Text;
                 this.XTMF.CheckToSave               = true;
                 this.XTMF.CurrentProject.HasChanged = true;
                 this.XTMF.Reload = true;
             }
             else if (result.Data is IModelSystem)
             {
                 IModelSystem baseMS = result.Data as IModelSystem;
                 string       error  = null;
                 var          lp     = this.Context.Project.LinkedParameters[this.Context.Project.ModelSystemStructure.IndexOf(this.Context.ModelSystem)];
                 var          ms     = this.XTMF.CreateCopy(this.Context.ModelSystem, lp, baseMS.Name, this.Context.ModelSystem.Description);
                 if (!ms.Save(ref error))
                 {
                     MessageBox.Show("Unable to save Model System!\r\n" + error, "Unable to save!", MessageBoxButton.OK, MessageBoxImage.Error);
                 }
             }
             if (result.Data is string)
             {
                 var    ms         = this.ModelSystemInterface.ModelSystem;
                 var    dataString = result.Data as string;
                 string error      = null;
                 if (dataString == "Rename LinkedParameter")
                 {
                     this.ModelSystemInterface.AddCommand(new XTMF.Commands.Editing.RenameLinkedParameter(this.LastLinkedParameterRequest, result.Result), ref error);
                     this.ModelSystemInterface.RefreshLinkedParameters();
                 }
             }
             return;
         }
     }
     this.ModuleIndirection.Clear();
 }
Example #2
0
 public void SetActive(object data)
 {
     if ( data is IModelSystemStructure )
     {
         // If we are here then we were called from the parent level
         this.CurrentModule = data as IModelSystemStructure;
         this.Context = new ModelSystemPageContext();
         var project = this.XTMF.CurrentProject;
         this.Context.Project = project;
         this.Context.ModelSystem = data as IModelSystemStructure;
         this.Context.CurrentNode = data as IModelSystemStructure;
         this.Delete.IsEnabled = true;
         this.ParentNodes.Clear();
         var index = project.ModelSystemStructure.IndexOf( CurrentModule );
         if ( index >= 0 )
         {
             bool editMode = false;
             string value;
             if ( this.XTMF.XTMF.Configuration.AdditionalSettings.TryGetValue( "EditProjects", out value ) )
             {
                 bool.TryParse( value, out editMode );
             }
             this.ModelSystemInterface.LoadProject( project, index, editMode );
             this.ColourKey.EditMode = editMode;
         }
         this.Run.IsEnabled = true;
     }
     else if ( data is ModelSystemPageContext )
     {
         var context = data as ModelSystemPageContext;
         this.Context = context;
         this.CurrentModule = context.CurrentNode;
         this.Delete.IsEnabled = context.CurrentNode == context.ModelSystem;
     }
     else if ( data is QuestionResult )
     {
         var result = data as QuestionResult;
         if ( result.Success == true )
         {
             if ( result.Data == null || result.Data is IModelSystemStructure )
             {
                 var module = result.Data as IModelSystemStructure;
                 if ( module != null )
                 {
                     this.ModelSystemInterface.AddCommand( new ModuleRenameCommand( module, result.Result ) );
                     this.ModuleNameLabel.Text = this.CurrentModule.Name;
                     this.ModelSystemInterface.Refresh( module );
                 }
                 else
                 {
                     this.ModelSystemInterface.AddCommand( new ModuleRenameCommand( CurrentModule, result.Result ) );
                     this.ModuleNameLabel.Text = this.CurrentModule.Name;
                     this.ModelSystemInterface.Refresh( this.CurrentModule );
                 }
                 this.ModuleNameLabel.ToolTip = this.ModuleNameLabel.Text;
                 this.XTMF.CheckToSave = true;
                 this.XTMF.CurrentProject.HasChanged = true;
                 this.XTMF.Reload = true;
             }
             else if ( result.Data is IModelSystem )
             {
                 IModelSystem baseMS = result.Data as IModelSystem;
                 string error = null;
                 var lp = this.Context.Project.LinkedParameters[this.Context.Project.ModelSystemStructure.IndexOf( this.Context.ModelSystem )];
                 var ms = this.XTMF.CreateCopy( this.Context.ModelSystem, lp, baseMS.Name, this.Context.ModelSystem.Description );
                 if ( !ms.Save( ref error ) )
                 {
                     MessageBox.Show( "Unable to save Model System!\r\n" + error, "Unable to save!", MessageBoxButton.OK, MessageBoxImage.Error );
                 }
             }
             if ( result.Data is string )
             {
                 var ms = this.ModelSystemInterface.ModelSystem;
                 var dataString = result.Data as string;
                 string error = null;
                 if ( dataString == "Rename LinkedParameter" )
                 {
                     this.ModelSystemInterface.AddCommand( new XTMF.Commands.Editing.RenameLinkedParameter( this.LastLinkedParameterRequest, result.Result ), ref error );
                     this.ModelSystemInterface.RefreshLinkedParameters();
                 }
             }
             return;
         }
     }
     this.ModuleIndirection.Clear();
 }