ContextMenu component

If I understood your use-case correctly,
PopupButton
might be worth of checking out.

Thanks. I’ll give that a try. I am using a one-item MenuBar now, and it works, but this looks promising for me.

I have the same issue:
https://bitbucket.org/peterl1084/vaadin-contextmenu/issue/3/show-with-scrollbar

Hello,

ContextMenu has issue tracker in BitBucket. I’m currently quite busy with other work again so please file all the issues to the tracker. I’m unfortunately very much aware of the positioning issue related to scrolling. I’ll try to find time this week to fix this issue.

Meanwhile you might want to check out the issue tracker here:
https://bitbucket.org/peterl1084/vaadin-contextmenu/issues?status=new&status=open
there is also at least one very good suggestion about separators in the menu. I’ll be looking into that later on too.

Thanks for your patience once again.

My menu does not show up - if I add the menu to the parent (see post above), it messes up my layout - any ideas to fix this?

I’ve tried using Panel, VerticalLayout and GridLayout…


			final ContextMenu menu = new ContextMenu();
			VerticalLayout p = new VerticalLayout();
			p.setSizeFull();
			p.addComponent(tblMsgList);
			p.addComponent(menu);
			
			ContextMenuItem reloadError = menu.addItem("Reload");
			menu.addListener(new ContextMenu.ClickListener() {
				public void contextItemClick(org.vaadin.peter.contextmenu.ContextMenu.ClickEvent event) {
					System.out.println("clicked c-item");
				}
			});

			layout.addComponent(p); // layout is a VerticalSplitPanel

Open the menu using menu.show(int x, int y) or menu.show(Component) methods. Menu should be added to the root layout of the window in which you’re using them menu, in many cases this is the root layout of the main window.


Window mainWindow = new Window();
setMainWindow(mainWindow);

ContextMenu menu = new ContextMenu();
mainWindow.addComponent(menu);

menu.show(x,y); // get these from layout click event for example.

ContextMenu in it self does not add anything to the layout except for invisible stub div which is caused be the requirement in GWT to have an HTML-element in each widget. As context menu is a popup widget displayed in Vaadin’s VOverlay component this so called root div is unnecessary.

I’m using the Chameleon theme addon.
I think the ContextMenu should look the same as the menu bar menu items.
How can I theme the ContextMenu addon?

Just started using the add-on and it’s really great. Where does one post bug notices? One smallish issue I’ve found is that the separator for a ContextMenuItem is the length of that particular item. All the separators should be the length of the longest item.

Jonathan

I am seeing the same issue. When I added the context menu to the top layout, it changed it. I am wondering if you have found the solution for this issue.

ok, I kind of walked around this issue. I set the expand ratio of the context menu to 0 in the horizontal layout, so the context menu doesn’t occupy space in the layout but can still be showed. Don’t know if it’s the right way to use the context menu but it achieved what I want.

Please post all the issues and problems as well as suggestions to issue tracker at: https://bitbucket.org/peterl1084/vaadin-contextmenu/issues/

There will be a new bugfix version shortly fixing all sorts of small problems.

There is an ongoing process at the moment for components like Table and Tree to support alternative context menus from the core Vaadin’s one. This is achieved with little modification in the Table and Tree UI code so that the right click events will be round tripped through server. In server side we can listen for these new events and react to them by displaying context menu with what ever menu items we want.

At the moment this technique requires modifying Table and Tree components but there are hopes and wishes that in the future it would be possible to attach different context menu implementations to these components. Having context menus in ListSelects and TwinColSelects would also be awesome so let’s keep our thumbs up!

I’ve not used Chameleon theme but how I see it is that you cannot directly theme any addons with it. One way would be to do theming with Chameleon theme and then copy appropriate content from the theme to addons.

You can theme context menu using following css-classes:


.v-ctxmenu 

.v-ctxmenu .ctxmenu-menu-item 

.v-ctxmenu .ctxmenu-menu-item .ctxmenu-icon-holder 

.v-ctxmenu .ctxmenu-menu-item .ctxmenu-icon 

.v-ctxmenu .ctxmenu-menu-item .ctxmenu-name 

.v-ctxmenu .ctxmenu-menu-item.separator .ctxmenu-name 

.v-ctxmenu .ctxmenu-menu-item:hover 

.v-ctxmenu .ctxmenu-submenu 

.v-ctxmenu .ctxmenu-submenu:hover

here .v-ctxmenu represents the whole menu component, inside it .ctxmenu-menu-item represents single menu item.
.ctxmenu-icon-holder and .ctxmenu-icon define the icon positioning.

.v-ctxmenu .ctxmenu-submenu and .v-ctxmenu .ctxmenu-submenu:hover are for menus having submenus. Default implementation has the small arrow graphics to make it clear that this item has other items underneath it.

Context menu width is calculated dynamically but height is static 26px per item. I’d advice that themes wouldn’t attempt to change this. Also the menu item icons should always be 16x16 pixels.

re:Tables - should we cross our fingers for built in support, or just use what you have made?

As well, if I use your context menu, would you have any suggestions how to accomplish the following:

I would like the context menu for a table directly under the header whenever someone clicks on the header.
ie. I don’t want the menu to appear where the user clicks in the header, but always have it pop up directly underneath the header, starting from where the header column starts.

Thanks,

Mark

Hello?

Quick question - most of my menus don’t have icons in them, is there a way to turn off the icon section of the context menu?

Thanks,

Mark

Hi,

Couple of more things - I was going to subclass ContextMenuItem to add in commands on a per menu item basis, but cannot as it has a private constructor. Can this be updated to be public? As well, there is an addItem(String) method and a removeItem(ContextMenuItem), but I would also need a addItem(ContextMenuItem) if I’m going to do anything substantial…

Thanks!

Mark

This is a must! I don’t know how the other people handles this but for me is a real mess. I need to have references to all added items and then I compare those against the source of the event and decide the action based on that. really messy.

Replying for few of the previous questions.

  1. ContextMenuItem should have a public constructor to allow inheritance
  2. It should be possible to add item specific listener to clear up the code.
  3. ContextMenu should be openable from the Table and Tree but currently it’s not because ‘Action framework’ is default implementation in Vaadin and at least current 6.x verions don’t allow changing this behavior.
  4. Currently you cannot turn off the icon section. That’s a good idea and I might implement it in the next version.

re:
3. So ContextMenu addon is not supposed to work with table? i.e: right clicking an item in table to open a custom context menu.

I’ tring to connect The ContextMenu object to my Tree.
When I click the right mouse button and I try to attach the ContextMenu I get an error :
Given component must have debug id specified.
What does it mean?
How can I solve it ?
Tks
Tullio