Пример #1
0
        public override void Delete(TreeNode treeNode)
        {
            String path = TreeNodeUtilities.GetFullPath(treeNode);

            m_persistanceManager.RemoveSetting(m_persistencyPath, path);
            treeNode.Remove();
        }
Пример #2
0
        public bool Update(TreeNode node, String newName, String text, T newItem)
        {
            TreeNode parent      = node.Parent;
            String   currentName = node.Name;
            String   sourcePath  = TreeNodeUtilities.GetFullPathJoined(node.Parent, currentName);
            String   targetPath  = TreeNodeUtilities.GetFullPathJoined(node.Parent, newName);

            if (newName != currentName)//name changed, validate overriding
            {
                bool isNameExist = GetParentNodes(parent).ContainsKey(newName);
                if (isNameExist)
                {
                    String       message  = String.Format("The item with name <{0}> already exist. Press Yes to override the existing item.", newName);
                    DialogResult question = MessageBox.Show(message, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (question != DialogResult.Yes)
                    {
                        return(false);
                    }
                }


                m_persistanceManager.MoveSetting(m_persistencyPath, sourcePath, targetPath);
            }

            m_persistanceManager.SaveSetting <T>(m_persistencyPath, newItem, targetPath);
            node.Name = newName;
            node.Tag  = newItem;
            node.Text = text;


            return(true);
        }
 public bool IsLeaf(TreeNode node)
 {
     if (node != null)
     {
         return(TreeNodeUtilities.IsLeaf(node));
     }
     return(false);
 }
Пример #4
0
        public override void Move(TreeNode node, TreeNode newParentNode)
        {
            String sourcePath = TreeNodeUtilities.GetFullPath(node);
            String targetPath = TreeNodeUtilities.GetFullPathJoined(newParentNode, node.Name);

            m_persistanceManager.MoveFolder(m_persistencyPath, sourcePath, targetPath);

            node.Remove();
            GetParentNodes(newParentNode).Add(node);
        }
Пример #5
0
        public TreeNode AddNew(TreeNode parent)
        {
            String   newName = FindAvailableName(parent, "Unnamed folder");
            TreeNode node    = AddNode(parent, newName);

            String path = TreeNodeUtilities.GetFullPathJoined(node.Parent, newName);

            m_persistanceManager.CreateFolder(m_persistencyPath, path);
            return(node);
        }
Пример #6
0
        public TreeNode AddNew(TreeNode parent)
        {
            String   newName = FindAvailableName(parent, "Unnamed");
            T        newItem = (T)Activator.CreateInstance <T>();
            TreeNode node    = AddNode(parent, newName, newItem);

            String path = TreeNodeUtilities.GetFullPathJoined(node.Parent, newName);

            m_persistanceManager.SaveSetting <T>(m_persistencyPath, newItem, path);

            return(node);
        }
Пример #7
0
        public TreeNode Duplicate(TreeNode node)
        {
            String duplicatedName = FindAvailableName(node.Parent, node.Name);

            T entity = (T)Activator.CreateInstance <T>();

            entity.SetProperties(((T)node.Tag).GetProperties());
            TreeNode duplicatedNode = AddNode(node.Parent, duplicatedName, entity);

            String path = TreeNodeUtilities.GetFullPathJoined(duplicatedNode.Parent, duplicatedName);

            m_persistanceManager.SaveSetting <T>(m_persistencyPath, entity, path);

            return(duplicatedNode);
        }
        private TreeNode GetParentForAddMethod(TreeNode node)
        {
            TreeNode parent = null;

            if (node != null)
            {
                if (TreeNodeUtilities.IsFolder(node))
                {
                    parent = node;
                }
                else
                {
                    parent = node.Parent;
                }
            }
            return(parent);
        }
Пример #9
0
        public int Compare(object x, object y)
        {
            TreeNode tx       = (TreeNode)x;
            TreeNode ty       = (TreeNode)y;
            bool     txIsLeaf = TreeNodeUtilities.IsLeaf(tx);
            bool     tyIsLeaf = TreeNodeUtilities.IsLeaf(ty);
            int      value    = 0;

            if (txIsLeaf == tyIsLeaf)
            {
                value = tx.Text.CompareTo(ty.Text);
            }
            else
            {
                value = txIsLeaf ? 1 : -1;
            }
            return(value);
        }
Пример #10
0
        public bool Update(TreeNode node, String name)
        {
            TreeNode parent      = node.Parent;
            String   currentName = node.Name;

            if (name == currentName)
            {
                return(true);
            }
            String sourcePath = TreeNodeUtilities.GetFullPathJoined(node.Parent, currentName);
            String targetPath = TreeNodeUtilities.GetFullPathJoined(node.Parent, name);

            m_persistanceManager.MoveFolder(m_persistencyPath, sourcePath, targetPath);

            node.Name = name;
            node.Text = name;

            return(true);
        }