/// <summary> /// Generates a list of connector subitems. /// </summary> /// <param name="firstIndex">The first connector subitem found on the node.</param> /// <returns>Returns alist of all connector subitems.</returns> protected List <NodeViewData.SubItemConnector> CollectSubItems(out int firstIndex) { if (!(_connectedChildren.Owner is NodeViewData)) { throw new Exception(Resources.ExceptionIsNotNodeViewData); } List <NodeViewData.SubItemConnector> list = new List <NodeViewData.SubItemConnector>(); firstIndex = -1; NodeViewData nvd = (NodeViewData)_connectedChildren.Owner; // for each subitem... for (int i = 0; i < nvd.SubItems.Count; ++i) { // check if it is a connector subitem NodeViewData.SubItemConnector subconn = nvd.SubItems[i] as NodeViewData.SubItemConnector; if (subconn != null && subconn.Connector == this) { // remember the index of the first connector subitem found if (firstIndex == -1) { firstIndex = i; } // add subitem to list list.Add(subconn); } else { // subitems of a connector must be next to each other if (firstIndex >= 0) { break; } } } // check if we have found any subitems if (list.Count < 1) { throw new Exception(Resources.ExceptionNoSubItemForConnector); } // check that we have found enough of them and not too many Debug.Check(list.Count >= _minCount && list.Count <= _maxCount); return(list); }
/// <summary> /// Removes a connector subitem for a child. /// </summary> /// <param name="child">The child whose connector subitem we want to remove.</param> protected void RemoveSubItem(BaseNode child) { if (!(_connectedChildren.Owner is NodeViewData)) { throw new Exception(Resources.ExceptionIsNotNodeViewData); } int firstIndex; List <NodeViewData.SubItemConnector> subitems = CollectSubItems(out firstIndex); // find the connector subitem for this child... for (int i = 0; i < subitems.Count; ++i) { NodeViewData.SubItemConnector subitem = subitems[i]; // when we found it... if (subitem.Child == child) { // remove the subitem ((NodeViewData)_connectedChildren.Owner).RemoveSubItem(subitem); // if we do not fullfil the minimum count, re add it at the end and clear the child if (subitems.Count - 1 < _minCount) { subitem.Child = null; ((NodeViewData)_connectedChildren.Owner).AddSubItem(subitem, firstIndex + subitems.Count - 1); } // update stored indices on connector subitems RebuildSubItemIndices(); return; } } throw new Exception(Resources.ExceptionSubItemIsNoChild); }