public void SelectComponent(ParameterStructure.Component.Component _comp) { if (_comp == null) { return; } // deselect all this.DeselectAllNodes(); // starts w top-level parent and ends with _comp List <ParameterStructure.Component.Component> parent_chain = this.CompFactory.GetParentComponentChain(_comp); List <long> parent_id_chain = parent_chain.Select(x => x.ID).ToList(); if (parent_id_chain.Count < 1) { return; } foreach (object child in this.Children) { ComponentVisualization cv = child as ComponentVisualization; if (cv == null) { continue; } if (cv.VisID == parent_id_chain[0]) { cv.SelectChild(parent_id_chain); break; } } }
// the id_chain starts with the parent on a higher hierarchy level and ends with the child to be selected internal void SelectChild(List <long> _id_chain) { if (_id_chain == null) { return; } if (_id_chain.Count < 1) { return; } long current_id = _id_chain[0]; if (this.VisID != current_id) { return; } long target_id = _id_chain[_id_chain.Count - 1]; if (!this.IsUserManipulatable) { this.IsUserManipulatable = true; } // recursion end if (this.VisID == target_id) { this.to_be_expanded_chain = null; this.VisState |= NodeVisHighlight.Selected; this.BringIntoView(); return; } // go deeper List <long> id_chain_rest = new List <long>(_id_chain); id_chain_rest.Remove(current_id); if (id_chain_rest.Count < 1) { return; } if (this.IsExpanded) { foreach (NodeVisualization nv in this.node_children) { ComponentVisualization cv = nv as ComponentVisualization; if (cv == null) { continue; } cv.SelectChild(id_chain_rest); } } else { this.IsExpanded = true; foreach (NodeVisualization nv in this.node_children) { ComponentVisualization cv = nv as ComponentVisualization; if (cv == null) { continue; } if (cv.VisID == id_chain_rest[0]) { cv.to_be_expanded_chain = id_chain_rest; } // the logic is completed and called recursively in the Loaded event handler // because expansion/selection can only be completed after the respective node has been loaded } } }