For example, I have a TreeGrid
and I have added a ContextMenu
to the TreeGrid
. Now I want to draw the ContextMenu
only when the user right-click a Leaf Node. My idea is to detect when the ContextMenu
is about to be drawn and check if the right-clicked node is a Leaf node:
ContextMenu
But what event handles the drawing of a component?
UPDATE:
The showContextMenuHandler
would not work. Actually this is a SmartGWT
bug, because if I say contextMenu.show(), I actually get 2 context menus: one from SmartGWT
(the one I made) and the second one of the browser which contains elements such as (next page, previous page, select All, page source, ..). the same goes for LeafContextClickHandler
, ...
This is why I want to add a draw handler for the ContextMenu itself to prevent it from drawing in special cases.
Here is an image explaining the bug:
Your issue with the ShowContextMenuHandler is not a bug, but rather a "feature" of SmartGWT. In any case if you don't want to show the browser's menu, all you have to do is to stop the propagation of the event to the browser. This can be easily achieved with the following code snippet:
addShowContextMenuHandler(new ShowContextMenuHandler() {
@Override
public void onShowContextMenu(ShowContextMenuEvent event) {
//Do not propagate to the browser's menu!
event.cancel();
//Continue with your code ....
}
}