Quintiq file version 2.0
#parent: #root
Method RetrieveBookmark (
  Bookmark bookmark
) id:Method_FormNavigationPanel_RetrieveBookmark
{
  #keys: '[137818.0.125566862]'
  Body:
  [*
    // Retrieve the selection in bookmark
    //Clear the list selction before retrieve bookmark
    Form.ClearAllNavSelection();
    
    entities := construct( Entitys );
    units := bookmark.GetUnits( MacroPlan );
    stockingpoints := bookmark.GetStockingPoints( MacroPlan );
    products := bookmark.GetProducts( MacroPlan );
    salesSegments := bookmark.GetSalesSegments( MacroPlan );
    entities := entities.Union( units );
    entities := entities.Union( stockingpoints );
    DataHolderOpenedBookmark.Data( bookmark );
    
    // Workaround: List is not checked when collapsed, (-1) to expand all. 
    ListEntity.ExpandAll( -1 );
    ListProduct.ExpandAll( -1 );
    ListSalesSegment.ExpandAll( -1 );
    
    traverse( entities, Elements, entity )
    {
      ListEntity.ExtendCheckByKey( entity.Key() );  
    }
    traverse( products, Elements, product )
    {
      ListProduct.ExtendCheckByKey( product.Key() );
    }
    traverse( salesSegments, Elements, salessegment )
    {
      ListSalesSegment.ExtendCheckByKey( salessegment.Key() );  
    }
    
    // Populate DH with to include leaf descendants of the checked item
    allentities := selectset( entities, Elements, e, true )
                            .Union( selectset( entities, Elements.astype( Unit ).AllChildren.AsChildren, e, true) )
                            .Union( selectset( entities, Elements.astype( Unit ).AllChildren.AsChildren.StockingPoint_MP, e, not e.IsSystem() ) );
    
    allproducts := selectset( products, Elements.AllChildren.AsChildren, product, true );
    allsalessegment := selectset( salesSegments, Elements.AllChildren.AsChildren, ss, true );
    
    // Update dataholders data
    DataHolderCheckedEntities.Data( &allentities );
    DataHolderCheckedProduct.Data( &allproducts );
    DataHolderCheckedSalesSegment.Data( &allsalessegment );
  *]
}
