Beispiel #1
0
        /// <summary>
        /// Handles the UltraTree's MouseUp event
        /// </summary>
        private void locationsTree_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            UltraTree     ultraTree    = sender as UltraTree;
            Point         pointClicked = new Point(e.X, e.Y);
            UltraTreeNode nodeAtPoint  = ultraTree.GetNodeFromPoint(pointClicked);

            if (nodeAtPoint != null && nodeAtPoint.Expanded == false)
            {
                Infragistics.Win.UltraWinTree.ExpansionIndicatorUIElement expansionIndicatorElement = null;
                expansionIndicatorElement = ultraTree.UIElement.ElementFromPoint(pointClicked) as Infragistics.Win.UltraWinTree.ExpansionIndicatorUIElement;
                if (expansionIndicatorElement == null)
                {
                    nodeAtPoint.Expanded = true;
                }
            }
        }
        void mUltraTree_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                //right button을 누려면 context menu실행....
                if (e.Button == MouseButtons.Right)
                {
                    return;
                }

                //mouse left를 누르고 Control Key를 누르지 않을 경우
                //모든 selction을 없앤다...
                if (e.Button == MouseButtons.Left && (Control.ModifierKeys != Keys.Control && Control.ModifierKeys != Keys.Shift))
                {
                    ClearSelection();
                    mFirstSelected = null;
                    return;
                }

                //rev2 multi
                if (mSelect == SelectMode.Single)
                {
                    return;
                }



                if (e.Button != MouseButtons.Left || (Control.ModifierKeys != Keys.Control && Control.ModifierKeys != Keys.Shift))
                {
                    if (mSelectedElements != null && mSelectedElements.Count > 0)
                    {
                        mSelectedElements.ForEach(RestoreBackColor);
                    }

                    mFirstSelected = null;
                    return;
                }

                //get TreeNode from clikc location
                var expTreeNode = mUltraTree.GetNodeFromPoint(e.Location) as ExplorerTreeNode;
                if (expTreeNode == null)
                {
                    return;
                }

                if (Control.ModifierKeys == Keys.Control)
                {
                    if (!mSelectedElements.Contains(prev_node))
                    {
                        SetBackColor(prev_node);
                        mSelectedElements.Add(prev_node);
                    }
                    //선택된 것이 다시 선택 된다면 삭제하고 backcolor는 원상태로 복귀...
                    if (mSelectedElements.Contains(expTreeNode))
                    {
                        RestoreBackColor(expTreeNode);
                        mSelectedElements.Remove(expTreeNode);
                    }
                    else
                    {
                        //change the back color...
                        SetBackColor(expTreeNode);
                        mSelectedElements.Add(expTreeNode);
                    }

                    mFirstSelected = null;
                }

                else if (Control.ModifierKeys == Keys.Shift)
                {
                    ClearSelection();


                    if (mFirstSelected == null)
                    {
                        mFirstSelected = expTreeNode;
                    }

                    else
                    {
                        try
                        {
                            var sEndSelected = mUltraTree.GetNodeFromPoint(e.Location) as ExplorerTreeNode;

                            //모든 범위가 정해 질 경우...
                            if (sEndSelected != null)
                            {
                                mSelectedElements.Clear();

                                //같은 level을 가진 elements을 선택 할 경우....
                                if (mFirstSelected.Parent == sEndSelected.Parent)
                                {
                                    var parent = mFirstSelected.Parent;


                                    //첫번째 선택한 node가 위에 있을 경우..
                                    if (mFirstSelected.Index < sEndSelected.Index)
                                    {
                                        for (int i = mFirstSelected.Index; i <= sEndSelected.Index; i++)
                                        {
                                            var ultraTreeNode = parent.Nodes[i];
                                            if (!ultraTreeNode.Visible)
                                            {
                                                continue;
                                            }

                                            mSelectedElements.Add(ultraTreeNode);
                                        }

                                        //Only visiable...의 색깔을 넣기 위해....
                                        UltraTreeNode nextNd = mFirstSelected;
                                        while (nextNd != sEndSelected)
                                        {
                                            nextNd = nextNd.NextVisibleNode;
                                            if (nextNd.Level <= mFirstSelected.Level)
                                            {
                                                continue;
                                            }

                                            mSelectedElements.Add(nextNd);
                                            mExcludedNodes.Add(nextNd);
                                        }
                                    }

                                    //같을 경우.
                                    else if (mFirstSelected.Index == sEndSelected.Index)
                                    {
                                        mSelectedElements.Add(mFirstSelected);
                                    }

                                    //첫번째 선택한 node가 밑에 있을 경우....
                                    else
                                    {
                                        for (int i = sEndSelected.Index; i <= mFirstSelected.Index; i++)
                                        {
                                            var ultraTreeNode = parent.Nodes[i];
                                            if (!ultraTreeNode.Visible)
                                            {
                                                continue;
                                            }

                                            mSelectedElements.Add(ultraTreeNode);
                                        }


                                        //only visiable...
                                        UltraTreeNode nextNd = mFirstSelected;
                                        while (nextNd != sEndSelected)
                                        {
                                            nextNd = nextNd.PrevVisibleNode;
                                            if (nextNd.Level <= sEndSelected.Level)
                                            {
                                                continue;
                                            }

                                            mSelectedElements.Add(nextNd);
                                            mExcludedNodes.Add(nextNd);
                                        }
                                    }
                                }//end 같은 parents를 가질 경우...


                                //parenet가 서로 다를경우...
                                else
                                {
                                    int ownerLevel = Math.Min(mFirstSelected.Level, sEndSelected.Level);

                                    UltraTreeNode sStParent = mFirstSelected;
                                    UltraTreeNode sEdParent = sEndSelected;


                                    //start parent를 찾는다....
                                    while (sStParent.Level > ownerLevel)
                                    {
                                        sStParent = sStParent.Parent;
                                    }

                                    //end parent를 찾는다...
                                    while (sEdParent.Level > ownerLevel)
                                    {
                                        sEdParent = sEdParent.Parent;
                                    }

                                    while (sStParent.Parent != sEdParent.Parent)
                                    {
                                        sStParent = sStParent.Parent;
                                        sEdParent = sEdParent.Parent;
                                    }



                                    //select owner...


                                    if (mFirstSelected.Level > sStParent.Level)
                                    {
                                        UltraTreeNode curNd = mFirstSelected;
                                        while (curNd.Level != sStParent.Level)
                                        {
                                            curNd = curNd.PrevVisibleNode;
                                            if (curNd.Level == sStParent.Level)
                                            {
                                                break;
                                            }
                                            mSelectedElements.Add(curNd);
                                        }

                                        GetExcludeNodes(mFirstSelected, sStParent.Level);
                                    }

                                    if (sEndSelected.Level > sEdParent.Level)
                                    {
                                        UltraTreeNode curNd = sEndSelected;
                                        while (true)
                                        {
                                            curNd = curNd.PrevVisibleNode;
                                            if (curNd.Level == sEdParent.Level)
                                            {
                                                break;
                                            }

                                            mSelectedElements.Add(curNd);
                                        }

                                        GetExcludeNodes(sEndSelected, sEdParent.Level);
                                    }


                                    //첫번째 선택한 node가 위에 있을 경우..
                                    if (sStParent.Index < sEdParent.Index)
                                    {
                                        for (int i = sStParent.Index; i <= sEdParent.Index; i++)
                                        {
                                            var ultraTreeNode = sStParent.Parent.Nodes[i];
                                            if (!ultraTreeNode.Visible)
                                            {
                                                continue;
                                            }

                                            mSelectedElements.Add(ultraTreeNode);
                                        }

                                        //Only visiable...의 색깔을 넣기 위해....
                                        UltraTreeNode nextNd = mFirstSelected;
                                        while (nextNd != sEndSelected)
                                        {
                                            nextNd = nextNd.NextVisibleNode;
                                            if (nextNd.Level <= mFirstSelected.Level)
                                            {
                                                continue;
                                            }

                                            if (mSelectedElements.Contains(nextNd))
                                            {
                                                continue;
                                            }

                                            mSelectedElements.Add(nextNd);
                                            mExcludedNodes.Add(nextNd);
                                        }
                                    }

                                    //같을 경우.
                                    else if (sStParent.Index == sEdParent.Index)
                                    {
                                        mSelectedElements.Add(mFirstSelected);
                                    }

                                    //첫번째 선택한 node가 밑에 있을 경우....
                                    else
                                    {
                                        for (int i = sEdParent.Index; i <= sStParent.Index; i++)
                                        {
                                            var ultraTreeNode = sStParent.Parent.Nodes[i];
                                            if (!ultraTreeNode.Visible)
                                            {
                                                continue;
                                            }

                                            mSelectedElements.Add(ultraTreeNode);
                                        }


                                        //only visiable...
                                        UltraTreeNode nextNd = mFirstSelected;
                                        while (nextNd != sEndSelected)
                                        {
                                            nextNd = nextNd.PrevVisibleNode;
                                            if (nextNd.Level <= sEndSelected.Level)
                                            {
                                                continue;
                                            }

                                            if (mSelectedElements.Contains(nextNd))
                                            {
                                                continue;
                                            }

                                            mSelectedElements.Add(nextNd);
                                            mExcludedNodes.Add(nextNd);
                                        }
                                    }

                                    if (!mSelectedElements.Contains(mFirstSelected))
                                    {
                                        mSelectedElements.Add(mFirstSelected);
                                    }

                                    if (!mSelectedElements.Contains(sEndSelected))
                                    {
                                        mSelectedElements.Add(sEndSelected);
                                    }
                                }//end parent가 다를 경우.. selec parent level elements....
                            }

                            mFirstSelected = null;
                            UpdateColor();

                            //exclude redundant parent....
                            foreach (var node in mExcludedNodes.Where(node => mSelectedElements.Contains(node)))
                            {
                                mSelectedElements.Remove(node);
                            }
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception);
                            ClearSelection();
                        }
                    }
                }

                Selection.CurrentSelection.Members =
                    mSelectedElements.Cast <ExplorerTreeNode>().Select(x => x.Element).ToArray();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                if (mSelectedElements != null)
                {
                    mSelectedElements.ForEach(RestoreBackColor);
                    mSelectedElements.Clear();
                }
            }
        }