Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Can't Show Default TreeGrid Context Menu

    If I set up a default context menu for a TreeGrid using setContextMenu() and also set up a TreeNode context menu using addNodeContextClickHandler(), I cannot get the default context menu to display if there's a TreeNode selected, even if I right-mouse click on an area in the TreeGrid that isn't on the TreeNode itself (e.g. white space below the TreeGrid). Is there any way to get around this?

    #2
    Here's a solution that will allow the proper display of a context menu based on whether the right mouse was clicked on a TreeNode or not within a TreeGrid canvas:

    Code:
        public MyTreeGrid()
        {
            addRightMouseDownHandler(new RightMouseDownHandler()
            {
                public void onRightMouseDown(RightMouseDownEvent event)
                {
                    if (MyTreeGrid.this.getEventRow() >= 0)
                    {
                        if (event.getSource() instanceof MyTreeGrid)
                        {
                            MyTreeGrid treeGrid = (MyTreeGrid) event.getSource();
                            
                            ListGridRecord selectedRecord = treeGrid.getSelectedRecord();
                            
                            if (selectedRecord instanceof MyTreeNode)
                            {
                                displayContextMenu((MyTreeNode) selectedRecord);
                            }
                        }
                    }
                    else
                    {
                        displayContextMenu(null);
                    }
                }
            });
        }
        
        protected void displayContextMenu(MyTreeNode treeNode)
        {
            if (treeNode != null)
            {
                if (treeNode.isLeaf())
                {
                    setContextMenu(MyContextMenu.getDefaultLeafMenu(this, treeNode));
                }
                else
                {
                    setContextMenu(MyContextMenu.getDefaultFolderMenu(this, treeNode));
                }
            }
            else
            {
                setContextMenu(MyContextMenu.getDefaultRootMenu(this));
            }
        }

    Comment

    Working...
    X