1. #1
    Sencha User
    Join Date
    Jun 2010
    Location
    Germany near cologne
    Posts
    21
    Vote Rating
    0
    Mebel is on a distinguished road

      0  

    Default Dynamic Context in Tree. How to Prevent show after Event ?

    Dynamic Context in Tree. How to Prevent show after Event ?


    Hello,

    i have a dynamic context menu on each node. Sometime its to possible to get a context menu without any items. Sadly the context menu show a clear rect on the screen.


    How its possible to prevent this ?

    Here my Code:
    Code:
     Menu contextMenu = new Menu();
           tree.addListener(Events.ContextMenu, new Listener<ComponentEvent>() {
                public void handleEvent(ComponentEvent be) {
                    Object selectedObject = tree.getSelectionModel().getSelectedItem();
    
                    Menu contextMenu = cfactory.createContextMenuselectedObject);
                    addNewEntriesMenu(contextMenu,selectedObject);
    
                    if (contextMenu.getItemCount()==0) {
                        //tree.setContextMenu(null); // cant set to null cause no more events fired.
                        // add usefull thing here to prevent show contextmenu 
                    }
                    tree.setContextMenu(contextMenu);
                }
            });
            tree.setContextMenu(contextMenu);

  2. #2
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    You can simple cancel the Events.ContenxtMenu event if you dont want to open the menu.

  3. #3
    Sencha User
    Join Date
    Jun 2010
    Location
    Germany near cologne
    Posts
    21
    Vote Rating
    0
    Mebel is on a distinguished road

      0  

    Default


    Hello Sven,

    fast reply thx.
    this code doesnt work. Any idea.

    Code:
    if (contextMenu.getItemCount()==0) {
        be.stopEvent();
        be.getEvent().stopPropagation();
        return;
    }
    regards
    me
    Last edited by Mebel; 21 Apr 2011 at 1:15 AM. Reason: Format Problems. Preview pos doesnt work ?

  4. #4
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    because you have not cancelled it. None of the methods you called contain the word cancelled

    what about
    Code:
    be.setCancelled(true);

  5. #5
    Sencha User
    Join Date
    Jun 2010
    Location
    Germany near cologne
    Posts
    21
    Vote Rating
    0
    Mebel is on a distinguished road

      0  

    Default


    yes looks like a self created easter egg.

    Work well now. thx.

    Happy Easter
    me

Similar Threads

  1. How to show Context Menu without triggering a Selection event
    By gbegley in forum Ext GWT: Discussion
    Replies: 1
    Last Post: 27 Oct 2010, 2:08 PM
  2. How to dynamic change context menu after tree node init.
    By qgj2046 in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 14 Sep 2009, 6:09 PM
  3. Dynamic context menu on tree not allowed?
    By sgolla in forum Ext GWT: Discussion
    Replies: 5
    Last Post: 11 Jul 2009, 1:27 AM
  4. tree context menu event acting on tree
    By garyrgi in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 21 May 2007, 11:15 PM

Thread Participants: 1