Does ContextMenu have sub-menus?

Hi

Does ContextMenu have sub-menus like a meuBar does.
(A Sub-menu means a menu has a menu such as a folder.)

Now I’ve set a ContextMenu below.

final Action POPUP_MENU = new Action
{ ACTION_A, ACTION_B, ACTION_C};
projectList.addActionHandler(new Action.Handler() {
public Action getActions(Object target, Object sender) {
return POPUP_MENU;
}
public void handleAction(Action action, Object sender, Object target) {

}
});

Thanks.

Yes, I believe it is in the demo code.
My own usage:

      // Generate main level items
      final ContextMenuItem sort = addItem( "Sort" );
      final ContextMenuItem filter = addItem( "Filter..." );
      final ContextMenuItem color = addItem( "Color Coding..." );

      // Generate sub item to sort menu
      final ContextMenuItem ascending = sort.addItem( "Ascending" );
      final ContextMenuItem descending = sort.addItem( "Descending" );

Note how I add items to a context menu item, making a nested sub-menu.

Thank you for your advice Phillippe

But I don’t understand.
What is the ContextMenuItem class? I don’t think it Is in Vaadin library. 6.6.7 is the version of Vaddin I’m using.
And I have another question. Which demo code you’re saying?

I’m sorry if I’m misunderstanding.

thanks

Ah, then I fear we are not talking about the same thing… :smiley:
I thought you were writing about the
ContextMenu Add-on
, but now I suppose you wrote about the context menu in table (and tree?), which I haven’t used, as I wanted something more generic. And perhaps more flexible, then.

Hi

No, I’m writing a Add-on. It is a context menu in a table.

I did not known much about Add-on, but I found ContextMenu in vaadin Add-on. I will try it.

thanks

Hi,

I tried ContextMenu Add-on. It looks useful, but I don’t know how to implement with a table widget.
How can I know when a right mouse button is clicked over the table item?

My current code is below;

final Action POPUP_MENU = new Action
{ ACTION_A, ACTION_B, ACTION_C };
table.addActionHandler(new Action.Handler() {
public Action getActions(Object target, Object sender) {
return POPUP_MENU;
}
public void handleAction(Action action, Object sender, Object target) {
}
}});

Method getActions only Action returns, so ContextMenu can be returned.

Thanks.

Currently, I only manage clicks on the table header:

   private void attachTo( Table table )
   {
      table.addListener( new Table.HeaderClickListener()
      {
         @Override
         public void headerClick( Table.HeaderClickEvent event )
         {
            // Make the context menu to appear on left click,
            // to allow user to keep their regular browser menu
            // (and because the browser can still display it!)
            if ( event.getButton() == MouseEvents.ClickEvent.BUTTON_LEFT )//&& event.isCtrlKey() )
            {
               clickedItem = (ItemClass) event.getPropertyId();
               show( event.getClientX(), event.getClientY() );
            }
         }
      } );
   }

That’s a method of my class extending ContextMenu.
For a context menu in the table itself, I suppose you have to use addListener(ItemClickEvent.ItemClickListener listener) instead.

Hi,

Thank you, Philippe. It’s a great help.
But I ask again.

I got a right mouse click, but the menu does not show.

table.addListener(new ItemClickEvent.ItemClickListener() {
public void itemClick(ItemClickEvent event) {
if (event.getButton() == MouseEvents.ClickEvent.BUTTON_RIGHT) {
ContextMenu menu = new ContextMenu();
ContextMenuItem cost = menu.addItem(“menu01”);
ContextMenuItem est = menu.addItem(“menu02”);
ContextMenuItem browse = menu.addItem(“menu03”);
ContextMenuItem browseCost = browse.addItem(“menu0301”);
menu.show(event.getClientX(), event.getClientY());
}
}
});

I checked with a Button widget like the sample in the add-on page, but the menu does not show.
Am I doing something wrong or misunderstanding?

Thanks.

I suggest to make the context menu a field of your application / page / class, perhaps. It is reusable.
In all cases, you forgot something that might be under documented (I saw it because it is mentioned in the comments of the add-on!): you need to add the menu component to one of the layouts of your page, otherwise it won’t be displayed.
It is usually done with getMainWindow().addComponent(menu); but when I tested your code in the SimpleAddressBook, the main layout is a split panel not accepting other components, so I just added it to a sub-layout: left.addComponent(menu);

Hi

Thanks for your advice, I’ve had the contextMenu seen.
I just added the menu like

getMainWindow().addComponent(menu);

The contextMenu has no problem, but it has changed the layout of widgets.
The layout is not what we want, and we need to do something.

Anyway thank you for your help. It was a great help.