Quintiq file version 2.0
#parent: #root
Method NewScenarioFromDataset (
  internal[GUIComponent] parent,
  shadow[Dataset] dataset
) as Scenario id:Method_ScenarioManager_DialogCreateEditMPScenario_NewScenarioFromDataset
{
  #keys: '[120326.1.1236876853]'
  Body:
  [*
    // New scenario
    this.Title( "New scenario from dataset '" + dataset.Name() + "'" );
    
    RadioButtonGroupStorageState.BoundValue( dataset.State() );
    RadioButtonGroupStorageState.Enabled( false );
    
    EditorScenarioName.Text( dataset.Name() );
    
    result := this.DoModal( parent );
    scenario := null ( Scenario );
    
    if( result > 0 )
    {
      scenarioManager := ScenarioManager;
      
      scenariofolder := select( scenarioManager, ScenarioNode.astype( ScenarioFolder ), folder,
                                folder.Name() = GlobalParameters_MP::GetFolderRoot() );
    
      scenario := scenarioManager.CreateScenarioMPFromDataset( scenariofolder,
                                                               EditorScenarioName.Text(),
                                                               EditorAssumption.Text(),
                                                               EditorComment.Text(),
                                                               '',
                                                               dataset.Name(),
                                                               dataset.DatasetMDSID(),
                                                               dataset.State() );
    
      kbfullid := SelectionKBBranch.Data();
      if ( RadioButtonGroupMode.BoundValue() = GlobalParameters_MP::GetKB_New() )
      {
        this.InstantiateAndSelectKB( scenario );
      }
      else if ( RadioButtonGroupMode.BoundValue() = GlobalParameters_MP::GetKB_CreateCopy() )
      {
        this.CopyAndSelectKB( SelectionKBBranch.Data(), scenario );
      }
      else
      {
        ApplicationLibMacroPlanner.SelectKB( scenario, kbfullid );
      }
      
      // Set user preference on supply chain wizard launch
      scenarioManager.LaunchInitializationWizardAtScenarioCreation( Dialog.CheckBoxLaunchSupplyChainWizard().Checked() );
    }
    
    isselected := ApplicationLibMacroPlanner.SelectScenario( scenario );
    
    if( isselected )
    {
      ApplicationLibMacroPlanner.SelectScenario( scenario, this );
      
      ApplicationLibMacroPlanner.SupplyChainDiagramSetSupplyChainView( MacroPlan );  
      if ( not isnull( DataHolderView.Data() ) )
      {
        feedback := ''
        DataHolderView.Data().RestoreDefaultLayout( feedback );
      }  
    }  
    
    return scenario;
  *]
}
