Main menu

I See Main Window Layout in the documentation and extended AppMainWindow with my class.

Is there a way to enable or disable the menu item?

How do you want to do it - for some user or during the user session depending on some event?
In the first case, use security permissions in menu.xml. They can also be set for a menu item in Studio.

No, during the user session depending on some event.

It cannot be done?

Hi Francesco,

For now, you cannot change state of menu items at runtime. Only workaround I can suggest you is to use Runnable for your menu item and instead of opening screen to show notification about disabled functionality.

  1. Create runnable class

import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.WindowManager.OpenType;
import com.haulmont.cuba.gui.components.Frame;
import com.haulmont.cuba.gui.config.WindowConfig;

public class ScreenRunnable implements Runnable {
    public void run() {
        // obtain infrastructure interfaces
        UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
        WindowManager wm = App.getInstance().getWindowManager();

        String login = uss.getUserSession().getCurrentOrSubstitutedUser().getLogin();
        // check some business rule
        if ("admin".equals(login)) {
            // show deny notification
            wm.showNotification("Functionality is disabled", Frame.NotificationType.WARNING);
        } else {
            // or open the screen with id "screen"
            WindowConfig wc = AppBeans.get(WindowConfig.NAME);
            wm.openWindow(wc.getWindowInfo("screen"), OpenType.THIS_TAB);
  1. Register class as screen in web-screens.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<screen-config xmlns="">
    <include file="/screens.xml"/>
    <screen id="screen"

    <screen id="screen-runnable"
  1. Add menu item to web-menu.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<menu-config xmlns="">
    <menu id="application" insertBefore="administration">
        <item id="screen-runnable"/>

I’ve prepared sample project with this approach, so you can see it in action.

We are planning to implement API for AppMenu items in one of the next minor releases. (21.8K)

Hi Francesco,

Since the platform version 6.5.0, there is an ability to manage application menu programmatically. See the documentation for details.