Quintiq file version 2.0
#parent: #root
Method PanelSearchProducts () id:Method_ApplicationLibMacroPlanner_PanelSearchProducts
{
  #keys: '[113694.2.1027230159]'
  Body:
  [*
    // Search products by string, highlight & select the instances in the list.
    if( not isnull( MacroPlan ) )
    { 
      ApplicationLibMacroPlanner.SetFilters(); // to retain the checkbox filters 
      filter := GUIDataSetLevelProducts.FixedFilter();
      
      if( EditorSearchProduct.Text() <> '' )
      {
        products := MacroPlan.GetProductsByName( EditorSearchProduct.Text() );
        
        if( products.Size() < 1000 ) // Performance cap
        {
          DataHolderProducts.Data( products.Copy() );
          
          // Using recursive IsParentin filter is very expensive, so we add the parent to the dataholder and do a simpel exists filter
          productswithparents := Product_MP::GetAllParents( products );
          productswithparents := productswithparents.Union( products );           
          DataHolderSearchProduct.Data( productswithparents.Copy() );
              
          filter := filter + ' and exists( dataholdersearchproduct, Elements, e, e = object ) '; // to retain the checkbox filters     
        }      
      }
      GUIDataSetLevelProducts.FixedFilter( filter );
    }
  *]
}
