/// <summary> /// Populates this control with exchange items. /// </summary> /// <param name="exchangeItems">Exchange items.</param> /// <param name="showCheckboxes">Determines whether to show check-boxes in the tree.</param> public void PopulateExchangeItemTree(IExchangeItem[] exchangeItems, bool showCheckboxes) { _checkedQuantity = null; _checkedElementSet = null; _checkedDataOperations = new ArrayList(); _filterDimension = null; _filterElementSet = null; _blockAfterCheckEventHandler = false; _exchangeItems = new ArrayList(exchangeItems); ExchangeItemsComparer comparer = new ExchangeItemsComparer(); _exchangeItems.Sort(comparer); // fill _exchangeItemsSearcher _exchangeItemsSearcher = new Hashtable(); foreach (IExchangeItem exchangeItem in _exchangeItems) { if (exchangeItem.ElementSet == null || exchangeItem.Quantity == null) { throw(new Exception("Exchange item cannot have ElementSet or Quantity null.")); } string key = CreateExchangeItemID(exchangeItem.Quantity, exchangeItem.ElementSet); object entry = _exchangeItemsSearcher[key]; if (entry == null) { // first usage of this key _exchangeItemsSearcher[key] = exchangeItem; } else if (entry is IExchangeItem) { // this key already used once => create ArrayList of exchange items with this key ArrayList list = new ArrayList(); list.Add(entry); list.Add(exchangeItem); _exchangeItemsSearcher[key] = list; } else { // key used more times ((ArrayList)entry).Add(exchangeItem); } } treeView1.CheckBoxes = showCheckboxes; CreateTree(); }
/// <summary> /// Creates the tree based on element sets and quantities in exchange items /// passed with <see cref="PopulateExchangeItemTree">PopulateExchangeItemTree</see> method. /// </summary> public void TreeCreate(UIExchangeItem toCheck) { _nodes.Clear(); if (_items == null) { treeView.BeginUpdate(); treeView.Nodes.Clear(); treeView.EndUpdate(); return; } ExchangeItemsComparer comparer = new ExchangeItemsComparer(); _items.Sort(comparer); treeView.BeginUpdate(); treeView.Nodes.Clear(); treeView.CheckBoxes = _treeOptions.ShowCheckboxs; // Top Level Dictionary <string, TreeNode> quantities = new Dictionary <string, TreeNode>(); TreeNode node; foreach (UIExchangeItem item in _items) { if (item.ValueDefinition == null) { throw new InvalidOperationException("IValueDefinition == null"); } if (!quantities.ContainsKey(item.ValueDefinition.Caption)) { node = treeView.Nodes.Add(item.ValueDefinition.Caption); node.Tag = null; quantities.Add(item.ValueDefinition.Caption, node); } } // Second level Stack <TreeNode> kids = new Stack <TreeNode>(_items.Count); foreach (UIExchangeItem item in _items) { node = new TreeNode(item.ToString()); node.ImageIndex = node.SelectedImageIndex = ImageIndex(item.ElementSet.ElementType); node.Tag = item; if (item is UIOutputItem && ((UIOutputItem)item).Parent != null) { kids.Push(node); } else { quantities[item.ValueDefinition.Caption].Nodes.Add(node); _nodes.Add(item.ExchangeItem, node); } } // Lower levels if (kids.Count > 0) { Stack <TreeNode> unassigned; UIExchangeItem iParent, iNode; int added; do { added = 0; unassigned = new Stack <TreeNode>(kids.Count); while (kids.Count > 0) { node = kids.Pop(); iNode = (UIExchangeItem)node.Tag; iParent = ((UIOutputItem)iNode).Parent; if (_nodes.ContainsKey(iParent.ExchangeItem)) { _nodes[iParent.ExchangeItem].Nodes.Add(node); _nodes.Add(iNode.ExchangeItem, node); ++added; } else { unassigned.Push(node); } } if (added == 0 && unassigned.Count > 0) { Debug.Assert(false); // cant assign kids break; } kids = unassigned; }while (unassigned.Count > 0); } treeView.ExpandAll(); treeView.EndUpdate(); if (toCheck != null && _nodes.ContainsKey(toCheck.ExchangeItem)) { CheckNode(_nodes[toCheck.ExchangeItem], true); } treeView.Invalidate(); }
/// <summary> /// Populates this control with exchange items. /// </summary> /// <param name="exchangeItems">Exchange items.</param> /// <param name="showCheckboxes">Determines whether to show check-boxes in the tree.</param> public void PopulateExchangeItemTree( IExchangeItem[] exchangeItems, bool showCheckboxes ) { _checkedQuantity = null; _checkedElementSet = null; _checkedDataOperations = new ArrayList(); _filterDimension = null; _filterElementSet = null; _blockAfterCheckEventHandler = false; _exchangeItems = new ArrayList( exchangeItems ); ExchangeItemsComparer comparer = new ExchangeItemsComparer(); _exchangeItems.Sort( comparer ); // fill _exchangeItemsSearcher _exchangeItemsSearcher = new Hashtable(); foreach( IExchangeItem exchangeItem in _exchangeItems ) { if( exchangeItem.ElementSet==null || exchangeItem.Quantity==null ) throw( new Exception("Exchange item cannot have ElementSet or Quantity null.") ); string key = CreateExchangeItemID(exchangeItem.Quantity, exchangeItem.ElementSet); object entry = _exchangeItemsSearcher[ key ]; if( entry == null ) { // first usage of this key _exchangeItemsSearcher[key] = exchangeItem; } else if( entry is IExchangeItem ) { // this key already used once => create ArrayList of exchange items with this key ArrayList list = new ArrayList(); list.Add( entry ); list.Add( exchangeItem ); _exchangeItemsSearcher[key] = list; } else { // key used more times ((ArrayList)entry).Add( exchangeItem ); } } treeView1.CheckBoxes = showCheckboxes; CreateTree(); }