ContextMenu component

Hello,

I’m currently testing with Vaadin 6.7.10 and add-on version 3.10. Didn’t tried the Vaadin 7 version yet.

Regular browser shortcut to access contextual menu is Shift-F10, but when I use it, I get the browser contextual menu instead of the one I’ve defined. Is there a way to get the right menu when using this shortcut?

Also is there a way to attach a shortcut to a ContextMenuItem?

Thanks,
Nicolas.

Have you tried using ContextMenuOpenedListener.TableListener for instance? With this listener you will be notified about item and property on which you clicked on a table. This way you can modify the content inside the menu before opening it. For tree there is ContextMenuOpenedListener.TreeListener. Other components can use ContextMenuOpenedListener.ComponentListener which will for example tell the coordinates of the clicked position.

Shortcuts are unfortunately not supported with context menu currently. That’s another good idea for future versions.

Hey Peter. Does this addon work with TreeTables? I assume it should since a TreeTable is a table. But when I try to add it, I get the openListeners firing correctly, but no ContextMenu is displayed. I’ve stolen your code from your test:


ContextMenu tableContextMenu = new ContextMenu();
tableContextMenu.addContextMenuTableListener(openListener);
tableContextMenu.addItem("Table test item #1");
tableContextMenu.setAsTableContextMenu(treeTable);

And the listener just prints out that it was called.

Any reason why this would not work in a tree table that you know of?

I have the exact same problem, I have tried several diffenrent approaches and the result is always the same. Events are fired but no Context Menu. I am using ContextMenu 4.2.0 and Vaadin 7.0.5. As far as I understand I have compiled the widgetset too :wink:

Okay (edited), The problem was the widgetset…

Janne - thanks. This pointed me in the right direction and I can see a context menu now. Just had to add the widgetset.

Hey,
I want to hide some items, depending on the event. Removing and adding them makes it reload the images every time again. Is it possible to really disable them so they wont be added to the dom?

Thanks

Edit.:

Hi, I have exactly same issue as Janne. Events are fired, correct item selected is show in notification, but no Context Menu. “Show” is not defined in Context menu, “AddComponent” to layout is depricated, expecting Component respectively, not ContextMenu.
Any suggestion? Thanks.

I have this add-on does not work with FilteringTable. How to win?

It works with FilteringTable, check the following code.


        final ContextMenu contextMenu = new ContextMenu();

        contextMenu.addItemClickListener(new ContextMenu.ContextMenuItemClickListener()
        {
            @Override
            public void contextMenuItemClicked(ContextMenu.ContextMenuItemClickEvent contextMenuItemClickEvent)
            {
                ContextMenu.ContextMenuItem clickedItem = (ContextMenu.ContextMenuItem) contextMenuItemClickEvent.getSource();
                if(clickedItem.getData() != null) performContextMenuAction((ContextValue) clickedItem.getData());
            }
        });

        contextMenu.setAsContextMenuOf(table);
        contextMenu.setOpenAutomatically(false);

        table.addItemClickListener(new ItemClickEvent.ItemClickListener()
        {
            public void itemClick(ItemClickEvent event)
            {
                if (event.getButton() == MouseEventDetails.MouseButton.RIGHT)
                {
                    contextMenu.removeAllItems();
                    String userID=table.getItem(event.getItemId()).getItemProperty("loginName").toString();

                    ContextMenu.ContextMenuItem addUserItem =contextMenu.addItem(AdminContextMenu.Add_User.toString());
                    addUserItem.setData(new ContextValue(AdminContextMenu.Add_User, userID));
                    addUserItem.setIcon(new ThemeResource("img/users/list-add-user.png"));
                    addUserItem.setSeparatorVisible(true);
                    ContextMenu.ContextMenuItem editUserItem =contextMenu.addItem(AdminContextMenu.Edit_User.toString());
                    editUserItem.setData(new ContextValue(AdminContextMenu.Edit_User, userID));
                    editUserItem.setIcon(new ThemeResource("img/users/user-properties.png"));
                    ContextMenu.ContextMenuItem changePassItem =contextMenu.addItem(AdminContextMenu.Change_User_Password.toString());
                    changePassItem.setData(new ContextValue(AdminContextMenu.Change_User_Password, userID));
                    changePassItem.setIcon(new ThemeResource("img/users/preferences-desktop-user-password.png"));
                    ContextMenu.ContextMenuItem deleteUserItem =contextMenu.addItem(AdminContextMenu.Delete_User.toString());
                    deleteUserItem.setData(new ContextValue(AdminContextMenu.Delete_User, userID));
                    deleteUserItem.setIcon(new ThemeResource("img/users/list-remove-user.png"));

                    contextMenu.open(event.getClientX(), event.getClientY());
                }
            }
        });

Thx for this nice add-on which is really must-have to switch out project to Vaadin. However, I would like to ask some questions:

  1. When an item has a sub menu, it does not show separator even when it is set visible. Is that a bug?
  2. Why is addStyleName(String) method missing? (According to this forum it was in previous versions and i really need texts of some items to be bold)

Thanks

Peter,

You mentioned earlier that currently we cannot turn off the icon section and that’s a good idea and you might implement it in the next version. Was it implemented yet?
If yes, how to do it?

Thanks,
Jennifer.

Hello,

I wanted to use ContextMenu with TabSheet, but with no success.
When showing contextmenu, I need to know for which tab to show context menu, that is where user did hisr ‘Right click’. This is different to selected tab.

  1. Menu items can be different for each tab
  2. When performing context menu item action, I need to know some tab/context information.

One can user layoutClickListener for tabsheet component, but then need to find out based on mouse point coordinates, which tab’s rectangle contains this point. Can this be done on server ui ?
Any other idea/solution here.
Thx a lot
Roman

I have some instances of context menus overlapping tooltips.
My desired outcome is that when the context menu pops-up the tooltip will disappear, but I don’t manage to achieve that, so I am getting a bit of both.
I wonder if someone can suggest how to get the tooltip to go away upon displaying the context menu.
Thanks
13285.png

Hello,

i used this amazing add-on.
But: i set the Context to a VerticalLayout with "
setAsContextMenuOf(layout);"
where layout is the VerticalLayout.
The ContextMenu appears, but i get this Error :

"Could not determine ApplicationConnection for Overlay. Overlay will be attached directly to the root panel
"in the JavaScript Console.
Any Idea how to stop this?

Thx a lot,
Oliver

I’m tying to migrate ContextMenu from 3 to 4 version (I migrate to Vaadin 7.1.8).
I used the method setAsContextMenuOf to apply the contextMenu to my VerticalLayout.
I run and then I right click in any point of the layout but I don’t see any menu.
What’s wrong ?
What I missed ?
Tks
Tullio

Hey Peter,

I’m using this cool add-on in my project. I am facing a strange issue. I have attached the add-on to a treetable.The add-on throws out exception when I do multiple right clicks(even after the menu opens). i’m getting the below exception:

com.vaadin.server.ServerRpcManager$RpcInvocationException: Unable to invoke method itemClicked in org.vaadin.peter.contextmenu.client.ContextMenuServerRpc
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:170)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
at com.vaadin.server.AbstractCommunicationManager.handleBurst(AbstractCommunicationManager.java:1680)
at com.vaadin.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1566)
at com.vaadin.server.AbstractCommunicationManager.handleUidlRequest(AbstractCommunicationManager.java:582)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:315)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:201)
at org.vaadin.artur.icepush.ICEPushServlet.service(ICEPushServlet.java:72)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:200)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168)
… 24 more
Caused by: java.lang.NullPointerException
at org.vaadin.peter.contextmenu.ContextMenu$1.itemClicked(ContextMenu.java:46)
… 28 more

Can someone please guide me in this? It is popping out red error screen on the browser and annoying?

I’m using vaadin 7.0.5 and Contectmenu 4.2.1.

Context menu is not working for me in Mozilla Firefox but its working fine in chrome and even in IE (WTF???). Do we have any fix for it?

for complete understanding I am posting my code block here.

I have included these files,
import org.vaadin.peter.contextmenu.ContextMenu;
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItem;
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickEvent;
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickListener;
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuOpenedListener;
import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuOpenedOnTreeItemEvent;

and below is my code, which shows context menu,

final ContextMenu contextMenu = new ContextMenu();
contextMenu.setAsContextMenuOf(root);
contextMenu.addContextMenuTreeListener(treeItemListener);
contextMenu.addItemClickListener(itemClickListener);

where “root” is an object of vaadin.ui.Tree , treeItemListener is object of ContextMenuOpenedListener.TreeListener and itemClickListener is object of ContextMenuItemClickListener.

Any help would be appreciated.
Thanks in Advance.
YJS

I have TextField and planned to show ContextMenu when user keyin some entry ?
I have keylisterner, and don’t hava idea how to trigger ContextMenu to open.

the method to open the ContectMenu only opex(int x, int y), while keylisterner doesn’t have the x & y.
in contextmenu 3.x there is method show(component).

how to do it in contextmenu 4.x ? i am using vaadin 7.1.8 insted.

merry christmas guys

Is there some way to make all menu items the same width ? At least the separators need to be full width.
I checked and there is no ticket about it, so there must be some way to do it (seems like an important feature).