Announcement

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

    ContextMenu for Canvas excluding its childrens

    Is there a possibility to apply a ContextMenu for a canvas but excluding its childrens?
    If so, how can I do that?

    #2
    Yes, just check the target of the event when it fires.

    Comment


      #3
      Originally posted by Isomorphic
      Yes, just check the target of the event when it fires.
      It is not totally clear to me on which control I can check an event. Can you please give me an example?

      Comment


        #4
        The event always returns parent as a source

        I've tried to follow the suggestion.
        I've added the right-click handler to the parent and showed the context menu only if the source is the parent:
        Code:
        m_mainViewPort.addRightMouseDownHandler(new RightMouseDownHandler() {
            public void onRightMouseDown(RightMouseDownEvent event) {
                if (event.getSource() == m_mainViewPort) {
                    popup.showContextMenu();
                } else {
                    event.cancel();
                }  
            }
        });
        But the problem is that the source of the event is ALWAYS the parent irrespective to whether the click was made on the parent or some of its children

        So the questions regarding what event (and target of it) should be checked is still opened.

        As a workaround I managed to not allow context menus on a certain child (like the main menu in the example below):
        Code:
        menuBar.addRightMouseDownHandler(new RightMouseDownHandler() {
            public void onRightMouseDown(RightMouseDownEvent event) {
                final String mid = this.getClass().getName()
                    + ".onRightMouseDown():  ";
                Log.debug(mid + "Right click on the main menu");
        				
                event.cancel();
                Log.debug(mid + "The event has been cancelled");
            }
        });
        Last edited by iurii; 20 Aug 2009, 13:44.

        Comment


          #5
          You're using something inherited from Gwt, which has a different notion of events and targets. Use EventHandler.getTarget().

          Comment


            #6
            It works now

            I've used your suggestion (the example is in the code below) and I worked.
            Thank you for your help.

            Code:
            m_mainViewPort.addRightMouseDownHandler(new RightMouseDownHandler() {
                public void onRightMouseDown(RightMouseDownEvent event) {
                    final String mid = this.getClass().getName()
                        + ".onRightMouseDown():  ";
                    Log.debug(mid + "is called");
            				
                    Canvas eventTarget = EventHandler.getTarget();
                    if (eventTarget == m_mainViewPort) {
                        Log.debug(mid							    + "The user did a right-click on the main panel");
            				
                        popup.showContextMenu();
                        Log.debug(mid + "The popup has been shown");
                    } else {
                        Log.debug(mid + "The user right-clicked on the child widget");
            					
                        event.cancel();
                        Log.debug(mid + "The event has been canceled");
                    }
                }
            });

            Comment

            Working...
            X