In a subclass of Tree:

    /*
     * This sucks.  There has to be a faster way to do this.
     */
    public TreeItem getTreeItemAt(int p_y)
    {
        Iterator<TreeItem> iter = treeItemIterator();
        TreeItem nearest = null;
        TreeItem exact = null;
        // adjust as necessary to return exact or nearest
        // it can be optimized to bail when you have a hit
        while (iter.hasNext())
        {
            TreeItem item = (TreeItem)iter.next();
            int top = item.getAbsoluteTop();
            int height = item.getOffsetHeight();
            if (top >= 0 && height != 0)
            {
                nearest = item;
                if (p_y >= top && p_y < top+height)
                {
                    exact = item;
                }
            }
        }
        return exact;
    }


Event handler:

    public void onMouseDown(MouseDownEvent event)
    {
        if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT)
        {
            // Suppress the browser's default context menu.
            // Opera 10.10 ignores this and shows the context menu
anyway.
            // Opera 10.50 handles this correctly (i.e. like all other
browsers).
            event.preventDefault();

            // Don't propagate to parents
            event.stopPropagation();

            Tree tree = (Tree)event.getSource();
            TreeItem item =
tree.getTreeItemAt(event.getNativeEvent().getClientY());
            // do whatever with the TreeItem...
        }
    }



On Jul 1, 9:25 am, Yaakov <[email protected]> wrote:
> How do you accomplish the "hit test", if you don't mind sharing that
> part.
>
> Thanks,
> Yaakov.
>
> On Jul 1, 11:52 am, Jim Douglas <[email protected]> wrote:
>
>
>
> > I listen for the right-click event on the Tree, then do a hit test of
> > the point to identify the corresponding TreeItem.  And don't forget to
> > call preventDefault() on the event to suppress the browser's default
> > context menu.  (That last part works in Opera 10.5x, but Opera 10.10
> > ignores it and puts up the context menu anyway.)
>
> > On Jul 1, 8:24 am, Yaakov <[email protected]> wrote:
>
> > > Well, TreeItem does not inherit from a Widget, so it doesn't have
> > > onBrowserEvent to override. So, how would you do that then?
>
> > > Thanks,
> > > Yaakov.
>
> > > On Jul 1, 3:20 am, rudolf michael <[email protected]> wrote:
>
> > > > hello,
> > > > you need to override the default behavior of the browser event on the
> > > > treeitem
> > > > @Override
> > > > public void onBrowserEvent(Event event) {
> > > > super.onBrowserEvent(event);
> > > > if(DOM.eventGetType(event)==Event.ONMOUSEDOWN){
> > > > if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT){
> > > >               TreeHandler.onRightClick(this);
> > > >             }else if (DOM.eventGetButton(event) == Event.BUTTON_LEFT){
> > > >               TreeHandler.onLeftClick(this);
> > > >             }}else if(DOM.eventGetType(event)==Event.ONMOUSEOVER){
>
> > > >  TreeHandler.onMouseOver(this);}else 
> > > > if(DOM.eventGetType(event)==Event.ONMOUSEOUT){
>
> > > > TreeHandler.onMouseOut(this);
>
> > > > }
> > > > }
>
> > > > On Thu, Jul 1, 2010 at 8:19 AM, ganesh.shirsat 
> > > > <[email protected]>wrote:
>
> > > > > hi,
>
> > > > > How to get TreeItem on right click in GWT 2.0.3
>
> > > > > please help me
>
> > > > > thanks,
> > > > > Ganesh Shirsat
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google 
> > > > > Groups
> > > > > "Google Web Toolkit" group.
> > > > > To post to this group, send email to 
> > > > > [email protected].
> > > > > To unsubscribe from this group, send email to
> > > > > [email protected]<google-web-toolkit%2Bunsubs
> > > > >  [email protected]>
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/google-web-toolkit?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to