Multiple Main Window

I would like to configure the web client such that if a specific user logs in, I want to use one Main Window (like an Admin screen), otherwise they will get a default Main Window. The default Main Window does NOT have a work area as I need the whole screen for my app but the Admin screen will be a typical Cuba screen with the menu and work area. Can this be done and if so, how do I configure this ?

CK

1 Like

Wouldn’t it be easier to use a tab which is presented to the user.
One tab showing for admin an one for normal users?

You may also create a grid or something which is visible
Based on Spesific permissions.
You can use Secure.isSpesificPermission to control user access from Roles
Role can be assigned to users.

OK. I understand. Looks like I CANNOT have 2 Main Windows in CUBA but I can manipulate the single Main Window to show/hide or enable/disable the AppMenu and Main Workarea and my customized screens.

Thanks

CK

Hi,

You can use multiple main windows in CUBA 6.3.RC2+, but support for this feature in Studio is limited. You cannot create multiple main windows from Studio, but it can be done manually from an IDE.

Steps to implement multiple main windows:

  1. Create App class in web module package “com.company.demo.web” (for example) if you project does not have it.

  2. Register App class in web-spring.xml


<bean id="cuba_App" class="com.company.demo.web.App" scope="prototype"/>
  1. App class should extend DefaultApp class from CUBA. Here we override CUBA 6.3 method “routeTopLevelWindowId”. It returns id of main window that should be shown for currently logged in user.

For instance, here I check user session attribute “main-window” and show two different windows: “mainWindow” and “mainWindow2”.


public class App extends DefaultApp {

    @Inject
    private UserSessionSource userSessionSource;

    @Override
    protected String routeTopLevelWindowId() {
        if (connection.isAuthenticated() && userSessionSource.checkCurrentUserSession()) {
            UserSession session = userSessionSource.getUserSession();
            String mainWindowAttribute = session.getAttribute("main-window");
            if ("manager".equals(mainWindowAttribute)) {
                return "mainWindow";
            } else {
                return "mainWindow2";
            }
        }

        return super.routeTopLevelWindowId();
    }
}
  1. Copy your mainWindow xml and java files created from Studio to another package, say “com.company.demo.web.mainWindow2”.

  2. Register you copy of “mainWindow” as “mainWindow2” in “web-screens.xml” file:


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<screen-config xmlns="http://schemas.haulmont.com/cuba/screens.xsd">
    <include file="com/company/demo/screens.xml"/>

    <screen id="mainWindow"
            template="com/company/demo/web/mainwindow/ext-mainwindow.xml"/>

    <screen id="mainWindow2"
            template="com/company/demo/web/mainwindow_2/ext-mainwindow-2.xml"/>
</screen-config>

Now, if I add security attribute to Company group with name “main-window” and value “manager” then users in this group will see “mainWindow” otherwise “mainWindow2”.

I’ve added sample project; you can try this approach in action. Note: this functionality is not yet documented and available only in 6.3 versions.

multiple-main-win.zip (26.9K)