ContextMenu Addon

Hi,

I am exploring ways to introduce a contextmenu in my application. There’s a screen for which it would enrich the user experience to activate contextual options, rather than clicking on a button panel.

I discovered this address in a quick search which refers to a contextmenu, but I presume it is referred to another logic?

https://docs.jmix.io/api/1.0/ui/io/jmix/ui/widget/addon/contextmenu/ContextMenu.ContextMenuOpenListener.ContextMenuOpenEvent.html

What I am looking for is a way to enable the user right-clicking upon a screen element (mostly a label or image) and display a set of options depending on the element background logic.

I have searched for a contextmenu in the addon marketplace with no luck.

On the other hand I sort of implemented a similar logic with the PopupView widget, however I am not being able to position easily the popup element right beneath the triggering element.

Any ideas?

Many thanks.

Carlos.

Hello!

You can use ContextMenu extension. To apply it for components you should use unwrap() or withUnwrapped() methods. For instance:

@Autowired
private Label<String> label;

@Autowired
private Notifications notifications;

@Subscribe
public void onInit(InitEvent event) {
    label.withUnwrapped(JmixLabel.class, jmixLabel -> {
        ContextMenu contextMenu = new ContextMenu(jmixLabel, true);
        contextMenu.addItem("Item 1", selectedItem -> {
            notifications.create()
                    .withCaption(selectedItem.getText() + "- clicked")
                    .show();
        });
    });
}

image