Why don't work ContextMenu addon in vaadin 6.8.1

Hi all,

I want use context menu addon in my tree component. The tree component has own context menu but it isn’t flexible. Please let me show my code and I will ask my question.



final ContextMenu menu = new ContextMenu();
ContextMenuItem myitem = menu.addItem( "MyItem" );
ContextMenuItem myitem2 = menu.addItem( "MyItem2" );

menu.addListener( new ContextMenu.ClickListener(){

    @Override
    public void contextItemClick( org.vaadin.peter.contextmenu.ContextMenu.ClickEvent event ){
        logger.info( "Clicked Item: {}", event.getClickedItem().getName() );

    }
} );

treeMenu.setDebugId( "mytreemenu" );

this.addListener( new LayoutEvents.LayoutClickListener(){

    @Override
    public void layoutClick( LayoutClickEvent event ){
        // TODO Auto-generated method stub
        if( LayoutClickEvent.BUTTON_RIGHT == event.getButton() ){
            logger.info( "x, y: {}, {}", event.getClientX(), event.getClientY() );
            logger.info( "Menu: {}", menu );

            menu.setEnabled( true );

            // menu.show( event.getClientX(), event.getClientY() );
            menu.show( treeMenu );
        }
    }
} );

This code must show a context menu but dont working.

Please help meeeeeee…

Greetings

Hello, with Vaadin 6 you’ll have to add the context menu to some layout before using it. Add the context menu for example to your main layout before using it with the tree. In Vaadin 7 you can directly extend a component with context menu.

I made like this. But there is an another problem now.

Widgetset does not contain implementation for org.vaadin.peter.contextmenu.ContextMenu. Check its @ClientWidget mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions. Unrendered UIDL:
-Unrendered UIDL
-org.vaadin.peter.contextmenu.ContextMenu(NO CLIENT IMPLEMENTATION FOUND) id=PID51 show=true component_locator=mytreemenu left=0 top=0
-items
-item id=0 name=MyItem enabled=true style= separator=false
-item id=1 name=MyItem2 enabled=true style= separator=false

:cry:

Have you compiled the widgetset? Widgetset must also be mentioned in the web.xml. Please refer to
instructions
from Book of Vaadin chapter 16.2.2.

Basically what you need to do is introduce the widgetset parameter in the web.xml as your servlet’s init-param with name “widgetset” and have the param-value to point to your compilation of the widgetset, which is the folder under WebContent/VAADIN/widgetsets/

Widgetset you can compile most easily with Vaadin eclipse plugin which you can download from Eclipse Marketplace or directly from the download section of our site.

Hello!

I have the same problem. I created the context menu, which if I give exact x,y coordinates, shows up properly and works fine. But if I want to position the menu to a component (like to a marker - simple Marker which I add to an OpenLayersMap) displays nothing.
Unfortunately event.getClientX() method runs NPE. See: http://code.google.com/p/vopenlayers/issues/detail?id=125
Am I missing something? How can I reach the mouse coordinates to position the context menu?
I’m working with context menu 3.0.1 and vaadin 6.8.11.


     @Override
        public void click(MouseEvents.ClickEvent event) {
            ContextMenu c = createContextMenu(); 
            marker.setDebugId("marker");

            VerticalLayout vl = new VerticalLayout();
            vl.addComponent(c);
            c.setVisible(true);
            c.show(marker);

//          getWindow().addComponent(c);
//          map.addComponent(c);

            map.addComponent(vl);
        }

Tried this way, but didn’t work:


        @Override
        public void click(MouseEvents.ClickEvent event) {
            ContextMenu c = createContextMenu();
            marker.setDebugId("marker");

            c.show(marker);
            map.addComponent(c);
}

Thanks in advance!
Szilvi