ContextMenu component

Do you see the folder in WebContent/VAADIN/widgetsets for you custom widgetset and does your web.xml contain a reference to that compiled widgetset?

Yes, I have checked that.

The Folder exists: WebContent —> VAADIN → widgetsets —> to.my.package.widgetset.prototypeWidgetset
with the generated data

web.xml



	<servlet>
		<servlet-name>Prototype</servlet-name>
		<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
		<init-param>
			<description>
			Vaadin application class to start</description>
			<param-name>application</param-name>
			<param-value>to.my.package.Prototype</param-value>
		</init-param>
		<init-param>
			<description>
			Application widgetset</description>
			<param-name>widgetset</param-name>
			<param-value>to.my.package.widgetset.prototypeWidgetset</param-value>
		</init-param>
	</servlet>

the generated widgetset.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module>
	<inherits name="com.vaadin.terminal.gwt.DefaultWidgetSet" />
        <inherits name="org.vaadin.peter.contextmenu.ContextmenuWidgetset" />
</module>

By the way, I am using Liferay…do I have to do some configuration in an other xml?

Ok the contextmenu doesn’t run in Liferay. Liferay needs other coordinates.

Thank you, Peter. Your component is very usefull. Are you going to support the HierarchicalContainer as a data source for your component? Sometime it is usefull to have ability to switch beetween different contexts. Here is small example how I see it:

HierarhicalContainer firstTypeContext = new HierarhicalContainer();
HierarhicalContainer secondTypeContext = new HierarhicalContainer();
...

if( object instanseof FirstType )
    contextMenu.setContainerDataSource(firstTypeContext);
if( object instanseof SecondType )
    contextMenu.setContainerDataSource(secondTypeContext);

Is there any chance to get Icons to be supported?

It would be great if we were able to add a ClickListener on each ContextItemMenu.

I think that the author no longer supports this component

The author is busy with other projects at the moment - maybe he gets back to this later, but I suppose patches here might be useful to others if somebody implements some of these changes.

Context menu is not working in current vaadin version (6.5.4) i compile and it generates these exceptions:

[ERROR]
Errors in ‘jar:file:/C:/Users/1234/workspace/netx/WebContent/WEB-INF/lib/vaadin-6.5.4.jar!/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java’
[ERROR]
Line 175: The method scheduleDeferred(Scheduler.ScheduledCommand) in the type Scheduler is not applicable for the arguments (new Command(){})
[ERROR]
Errors in ‘jar:file:/C:/Users/1234/workspace/netx/WebContent/WEB-INF/lib/vaadin-6.5.4.jar!/com/vaadin/terminal/gwt/client/ui/VScrollTable.java’
[ERROR]
Line 833: The method scheduleDeferred(Scheduler.ScheduledCommand) in the type Scheduler is not applicable for the arguments (new Command(){})
[ERROR]
Line 1531: The method scheduleDeferred(Scheduler.ScheduledCommand) in the type Scheduler is not applicable for the arguments (new Command(){})
[ERROR]
Line 1566: The method scheduleDeferred(Scheduler.ScheduledCommand) in the type Scheduler is not applicable for the arguments (new Command(){})

It seems that your are using old GWT jars. If you are using Eclipse plugin to compile the widgetset, try to change your project’s Vaadin version to an older Vaadin version and then back in project’s properties. This operation should update the version of GWT to correct.

Hey everyone! New version of ContextMenu (3.0) has been released!

I apologize for not being able to provide support or maintenance for the component for almost past nine months. New 3.0 version introduces few new features and also fixes few open bugs:

  • ContextMenu can now be opened next to any component using new show(Component) method
  • Support for icons in menu items has been added
  • Easier theming for menu items, supports addStyleName(String) methods
  • Improved client - server communication
  • Bugfixes for menu not closing properly or reappearing when reloading page

There are still many features that this component does not yet support. Please keep on sending ideas and bug reports, from now on I’ll try to release more frequent updates if needed.

At the moment there is a small limitation opening ContextMenu to “component location” using show(Component) method. Given component must have debugId specified using the setDebugId(String) method. This is because debug id is unique identifier in HTML-dom and client-side implementation uses it to figure out component’s location. This could be easily automated but it appears that there is related Vaadin bug:


http://dev.vaadin.com/ticket/6748

Cheers!

Hi,

Seems like a great component, but I can’t get to try it.
I tried :

menu.show(event.getClientX(), event.getClientY());

on an item of my tree, and I tried :

menu.show(button);

… but both of those tests display nothing on my screen.

Did I do something wrong ?

Hi, maybe you forgot to add context menu to parent vaadin component before using show method

parent.addComponent(menu)

Thank you Boris, that worked !

EDIT : that worked, but strangely the menu appears about 200px up from the click position. Should I bypass this problem by adding those 200px to the Y parameter of my menu.show(X, Y), or is there a better solution ?

EDIT : In fact I noticed that the menu appears above the click position when I scroll down the page. (I am using it inside a Liferay portlet)

I have the same experience with this scrolling (in Liferay).
Something doesn’t realize that user scrolls down.

Tomas

Ugo, you can look at sorce VContextMenu.java, I saw there magic number 200. Maybe it helps you understand

I noticed that when you use ContextMenu for a button, it works well wether you scroll down or not.
I debugged my application and it seems like the event.getClientY() returns a different position when you scroll the page. Maybe that come from the listener, I am having a look at it.

Hello,

is it possible to remove a item?
Thanks.

For those who still try to find out how to get a context menu for a tree, the simplest solution I found is to add an action handler to your tree.

cf.
http://demo.vaadin.com/docs/example-source/com/vaadin/demo/featurebrowser/TreeExample.java.html

Can ContextMenu be used on a Button or Link or just those components that can support child components?

I have a “choice of download options” I’d like to present when someone clicks on a simple Button, though in my case the Button is in a Table. This way, I could avoid having several buttons next to each other.

Or would I be better off without a Button with a ContextMenu attached to it and use something else, like a simple MenuBar? I like the look of a Button more, and a Link may be okay though less obvious to notice.