...
Code Block |
---|
class MyWidget extends Composite implements ContextMenuHandler { // thisjust canan be anythingexample, asuse longa asmeaningful it extends widgetWidget here... private Widget base; private PopupPanel contextMenu; public MyWidget() { // initialize base widget, etc... this.contextMenu = new PopupPanel(true); this.contextMenu.add(new HTML("My Context menu!")); this.contextMenu.hide(); initWidet(this.base); // of course it would be better if base would implement HasContextMenuHandlers, but the effect is the same addDomHandler(this, ContextMenuEvent.getType()); } public onContextMenu(ContextMenuEvent event) { // stop the browser from opening the context menu event.preventDefault(); event.stopPropagation(); this.contextMenu.setPopupPosition(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY()); this.contextMenu.show(); } event.stopPropagation(); } |