Beispiel #1
0
        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);
        }
Beispiel #2
0
 private BoundTreeNode CreateNode(int position)
 {
     var node = new BoundTreeNode(position);
     RefreshData(node);
     return node;
 }
Beispiel #3
0
        private void CheckAccess(BoundTreeNode node)
        {
            if (_readOnlyMember == null)
                return;

            node.SetNodeImages();
        }
Beispiel #4
0
        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();
            }
        }
Beispiel #5
0
 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;
 }
Beispiel #6
0
 private void ChangeParentToRoot(BoundTreeNode childnode)
 {
     if (childnode != null)
     {
         // ReSharper disable AssignNullToNotNullAttribute
         _parentIdentifierProperty.SetValue(_listManager.List[childnode.Position], null);
         // ReSharper restore AssignNullToNotNullAttribute
         _listManager.EndCurrentEdit();
     }
 }
Beispiel #7
0
 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();
     }
 }
Beispiel #8
0
        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;
        }
Beispiel #9
0
        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;
        }
Beispiel #10
0
 private void AddNode(TreeNodeCollection nodes, BoundTreeNode node)
 {
     _itemsPositions.Add(node.Position, node);
     _itemsIdentifiers.Add(node.NodeId, node);
     nodes.Add(node);
     CheckAccess(node);
 }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
 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;
 }