private bool TargetIsSourceAncestor(TreeNode source, TreeNode dropNode, ref BoundTreeNode replacementeParent, ref BoundTreeNode placeHolder) { if (dropNode.Parent == null) return false; if (source == dropNode.Parent) { placeHolder = dropNode as BoundTreeNode; replacementeParent = source.Parent as BoundTreeNode; return true; } return TargetIsSourceAncestor(source, dropNode.Parent, ref replacementeParent, ref placeHolder); }
private BoundTreeNode CreateNode(int position) { var node = new BoundTreeNode(position); RefreshData(node); return node; }
private void CheckAccess(BoundTreeNode node) { if (_readOnlyMember == null) return; node.SetNodeImages(); }
private void ChangeParentUpTheSameBranch(BoundTreeNode childnode, BoundTreeNode parentNode, BoundTreeNode replacementeParent, BoundTreeNode placeHolder) { var replacementeParentId = _identifierProperty.GetValue(_listManager.List[replacementeParent.Position]); if (replacementeParentId != null) _parentIdentifierProperty.SetValue(_listManager.List[placeHolder.Position], replacementeParentId); var parentId = _identifierProperty.GetValue(_listManager.List[parentNode.Position]); if (parentId != null) { _parentIdentifierProperty.SetValue(_listManager.List[childnode.Position], parentId); _listManager.EndCurrentEdit(); } }
private void RefreshData(BoundTreeNode node) { var position = node.Position; node.NodeId = _identifierProperty.GetValue(_listManager.List[position]); if (_displayProperty != null && _listManager.List.Count > position) { var text = _displayProperty.GetValue(_listManager.List[position]) as string; if (text != null) node.Text = text; } node.ParentNodeId = _parentIdentifierProperty.GetValue(_listManager.List[position]); if (_readOnlyProperty != null) node.ReadOnly = Convert.ToBoolean(_readOnlyProperty.GetValue(_listManager.List[position])); if (_toolTipTextProperty != null) node.ToolTipText = Convert.ToString(_toolTipTextProperty.GetValue(_listManager.List[position])); node.ForeColor = ForeColor; }
private void ChangeParentToRoot(BoundTreeNode childnode) { if (childnode != null) { // ReSharper disable AssignNullToNotNullAttribute _parentIdentifierProperty.SetValue(_listManager.List[childnode.Position], null); // ReSharper restore AssignNullToNotNullAttribute _listManager.EndCurrentEdit(); } }
private void ChangeParentNoAncestor(BoundTreeNode childnode, BoundTreeNode parentNode) { var parentId = _identifierProperty.GetValue(_listManager.List[parentNode.Position]); if (parentId != null) { _parentIdentifierProperty.SetValue(_listManager.List[childnode.Position], parentId); _listManager.EndCurrentEdit(); } }
private bool ModelChangeParent(BoundTreeNode childNode, BoundTreeNode parentNode) { if (parentNode == null) { if (!_allowDropOnRoot) return false; ChangeParentToRoot(childNode); return true; } if (childNode != null) { if (AllowDropOnDescendents) { BoundTreeNode replacementeParent = null; BoundTreeNode placeHolder = null; if (TargetIsSourceAncestor(childNode, parentNode, ref replacementeParent, ref placeHolder)) ChangeParentUpTheSameBranch(childNode, parentNode, replacementeParent, placeHolder); else ChangeParentNoAncestor(childNode, parentNode); } else { if (!TargetIsSourceAncestor(childNode, parentNode)) ChangeParentNoAncestor(childNode, parentNode); } } return true; }
private bool ChangeParent(BoundTreeNode node) { var message = string.Empty; var dataParentId = _parentIdentifierProperty.GetValue(_listManager.List[node.Position]); if (dataParentId == null) { node.Remove(); Nodes.Add(node); return true; } if (node.ParentNodeId == null || node.ParentNodeId.GetHashCode() != dataParentId.GetHashCode()) { if (node.NodeId.GetHashCode() == dataParentId.GetHashCode()) { message = "Node cannot be its own parent."; } else { var newParentNode = _itemsIdentifiers[dataParentId] as BoundTreeNode; if (newParentNode == null) { message = "Item not found or wrong type."; } else { if (IsOwnAncestor(node, newParentNode)) { message = "Node cannot be its own ancestor."; } else { node.Remove(); newParentNode.Nodes.Add(node); CheckAccess(node); SelectedNode = node; if (SelectedNode != null) SelectedNode.EnsureVisible(); return true; } } } } if (message != string.Empty) { Logger.Warn(message); node.NodeError = true; return false; } return true; }
private void AddNode(TreeNodeCollection nodes, BoundTreeNode node) { _itemsPositions.Add(node.Position, node); _itemsIdentifiers.Add(node.NodeId, node); nodes.Add(node); CheckAccess(node); }
private void AddNodeWithError(BoundTreeNode node) { string message; if (_itemsIdentifiers.ContainsKey(node.NodeId)) { node.NodeError = true; // log and ignore node message = string.Format(DuplicatedMessage, node.Text, node.NodeId); Logger.Error(message); MessageBox.Show(message, DuplicatedCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (node.NodeId.Equals(node.ParentNodeId)) message = SelfParent; else if (!_itemsIdentifiers.ContainsKey(node.ParentNodeId)) message = InexistentParent; else message = GeneralNodeError; Logger.Warn(string.Format("Node \"{0}\" - \"{1}\": {2}", node.Text, node.NodeId, message)); node.NodeError = true; node.ForeColor = Color.Red; node.ToolTipText = message + Environment.NewLine + node.ToolTipText; AddNode(Nodes, node); } }
private bool TryAddNode(BoundTreeNode node) { if (!_itemsIdentifiers.ContainsKey(node.NodeId)) { if (IsIdNull(node.ParentNodeId)) { AddNode(Nodes, node); return true; } if (_itemsIdentifiers.ContainsKey(node.ParentNodeId)) { var parentNode = _itemsIdentifiers[node.ParentNodeId] as TreeNode; if (parentNode != null) { AddNode(parentNode.Nodes, node); return true; } } } return false; }