Table context menu and multi selection

Hi all,
as in another post with the same title (https://vaadin.com/forum/-/message_boards/view_message/245995) i’m tryng to get different context menu on single item and multiple items selection.
I found also this: http://stackoverflow.com/questions/5514223/vaadin-using-multiple-context-menus

firstly i’ve tried this:


    static final Action ACTION_NEW = new Action("Nuovo");
    static final Action ACTION_EDIT = new Action("Modifica");
    static final Action ACTION_DELETE = new Action("Elimina");
    static final Action[] ITEM_ACTIONS = new Action[]
 { ACTION_EDIT, ACTION_NEW, ACTION_DELETE };
    static final Action[] MULTI_ITEM_ACTIONS = new Action[]
 { ACTION_DELETE, ACTION_NEW };
    static final Action[] NO_ITEM_ACTIONS = new Action[]
 { ACTION_NEW };
	
    Action[] action = NO_ITEM_ACTIONS;  
    
	public TestApplication() {		
		
		final Table table = new Table();
		table.setSelectable(true);
		table.setMultiSelect(true);
		table.setImmediate(true);

                table.addListener(new Property.ValueChangeListener() {
			
			@Override
			public void valueChange(ValueChangeEvent event) {
				Collection value = (Collection) event.getProperty().getValue();
				if(value.size() == 0){
					action = NO_ITEM_ACTIONS;
				}else if(value.size() == 1){
					action = ITEM_ACTIONS;
				}else{
					action = MULTI_ITEM_ACTIONS;
				}
				
				table.requestRepaint();
			}
		});
		table.addActionHandler(new Handler() {			
			@Override
			public void handleAction(Action action, Object sender, Object target) {
				System.out.println("action" + action.getCaption());
			}			
			@Override
			public Action[] getActions(Object target, Object sender) {
				if(action == NO_ITEM_ACTIONS){
					System.out.println("NO_ITEM_ACTIONS");
				}else if(action == ITEM_ACTIONS){
					System.out.println("ITEM_ACTIONS");
				}else{
					System.out.println("MULTI_ITEM_ACTIONS");
				}
				return action;
			}
		});

the method getActions is called at each right click and it return the rught Action but the UI didn’t seem to care and still use the NO_ITEM_ACTIONS (the first setted)

then i have tryed this:

table.addListener(new Property.ValueChangeListener() {
			
			@Override
			public void valueChange(ValueChangeEvent event) {
				Collection value = (Collection) event.getProperty().getValue();
				if(value.size() == 0){
					action = NO_ITEM_ACTIONS;
				}else if(value.size() == 1){
					action = ITEM_ACTIONS;
				}else{
					action = MULTI_ITEM_ACTIONS;
				}
				
				table.removeAllActionHandlers();
				table.addActionHandler(new Handler() {			
					@Override
					public void handleAction(Action action, Object sender, Object target) {
						System.out.println("action" + action.getCaption());
					}			
					@Override
					public Action[] getActions(Object target, Object sender) {
						if(action == NO_ITEM_ACTIONS){
							System.out.println("NO_ITEM_ACTIONS");
						}else if(action == ITEM_ACTIONS){
							System.out.println("ITEM_ACTIONS");
						}else{
							System.out.println("MULTI_ITEM_ACTIONS");
						}
						return action;
					}
				});
				table.requestRepaint();
			}
		});

it work, but i lost the no-selection contextual menu and to get the menu i must select one or more items,
so, i add this:

table.addActionHandler(new Handler() {			
			@Override
			public void handleAction(Action action, Object sender, Object target) {
				System.out.println("action" + action.getCaption());
			}			
			@Override
			public Action[] getActions(Object target, Object sender) {
				if(action == NO_ITEM_ACTIONS){
					System.out.println("NO_ITEM_ACTIONS");
				}else if(action == ITEM_ACTIONS){
					System.out.println("ITEM_ACTIONS");
				}else{
					System.out.println("MULTI_ITEM_ACTIONS");
				}
				return action;
			}
		});

now i get the no-item contextual menu, but also a very strange UI behaviour: the UI menu keep the initial menu lenght, so: if the NO_ITEM_ACTIONS has 1 Action i only see the first action on the other menues, or if the first menu has 3 items and the others only 2, i get the correct 2 items but the third of the previous menu.
(this seem to me a graphic bug, since clicking the third item give no callback)

How can i solve this ? Any workaround ?

Does anyone has news about this bug? because it’s still there in vaadin 6.8.4! (6.8.5 doesn’t seem to fix any issue for this)
When I debug into the vaadin code and inspect what ajax call returns, it seems that everything is ok on the server side.
The actions are not correctly repainted on the client side (browser).

Maybe this issue will be obsolete in vaadin7…???

The reality is that “if there is no ticket, there is no problem” - i.e. whatever is only on the forum disappears in the mists of history within a week.
If there is a ticket, there is at least a possibility that the development team will find the issue and maybe fix it.
Please
create a bug report
with a test case and maybe also a link to this thread.

That said, the Action mechanism is in need of a complete redesign, which unfortunately did not happen for Vaadin 7.

For the use cases that it covers, you might prefer the
ContextMenu add-on
.

Thanks Henri for your suggestions.

We already used “ContextMenu add-on” in our project.
So as a workaround, I will use it for my use case.