DataGrid right click

107 views
Skip to first unread message

Daniel Mauricio Patino León

unread,
Mar 5, 2012, 10:56:13 PM3/5/12
to Google Web Toolkit
Iam trying to figure out how to implement a right click to my
DataGrid, here is my code:

@UiField(provided=true) DataGrid<EmployeeProxy> dataGrid = new
DataGrid<EmployeeProxy>(){
protected void onBrowserEvent2(Event event) {
switch (DOM.eventGetType(event)) {
case Event.ONMOUSEDOWN:
if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT) {


event.preventDefault();
event.stopPropagation();


PopupPanel pop = new PopupPanel(true);

MenuBar menuBar = new MenuBar(true);
menuBar.setVisible(true);
menuBar.addItem(new MenuItem("Click me", new Command() {

@Override
public void execute() {
Window.alert("Clicked me!");
}
}));
menuBar.addItem(new MenuItem("Poke me",new Command(){
@Override
public void execute() {
Window.alert("Poked me!");
}
}));

pop.setWidget(menuBar);


pop.setPopupPosition(DOM.eventGetClientX(event) ,DOM.eventGetClientY(event));
pop.show();

} else {
super.onBrowserEvent2(event);
}
break;
default:
super.onBrowserEvent2(event);
break;
}
};
};


This works ok but dont know how to prevent the default browser right
click behavior.


Any help would be nice. Thank you.

Sachin Shekhar R

unread,
Mar 6, 2012, 10:42:44 AM3/6/12
to google-we...@googlegroups.com
In the application html file ensure you have set up body tag like - <body oncontextmenu="return false;">
This suppresses the default browser context menu.

Daniel Mauricio Patino León

unread,
Mar 6, 2012, 4:38:41 PM3/6/12
to google-we...@googlegroups.com
Hey  Sachin  thank you.


Do you know if this property has cross browser support?

2012/3/6 Sachin Shekhar R <sachi...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/fKgliG4HeB4J.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
ISC. Daniel Mauricio Patiño León.
Director ejecutivo
Liondev S.A. de C.V.



Daniel Mauricio Patino León

unread,
Mar 6, 2012, 4:43:16 PM3/6/12
to google-we...@googlegroups.com

                                       event.preventDefault();
                                       event.stopPropagation();

Why these lines doesnt work?

In DataGrid you can overdrive the onBrowserEvent2(){} but it is fired after the onBrowserEvent(){}
and i think is why my code doesnt work.


Is there another w3c validation pass way to do this?


Thank you.

2012/3/6 Daniel Mauricio Patino León <ceo.li...@gmail.com>
Reply all
Reply to author
Forward
0 new messages