Programmatically Meta Information about active screens

Hi,

I’ve two little questions around the general screen API. Probably i just did not found the right method in the API so perhaps you can guide me in the right direction.

First thing is that i want to add a Listener if the active screen changes. This might either be, because another tab is opened or because within a tab the user moves from the browse to the edit screen e.g. In case i get information about the now opened tab (screen id e.g.) through the listener the second question is obsolete.

Otherwise here’s the second question:
How do i can ask the system what screen is currently open. I found WindowManager.getOpenWindows() but I’m, not how to get the information which one is the currently active one.

Any help would be appreciated!

Bye,
Mario

1 Like

Hi Mario,

Currently, we don’t have public API for controlling opened windows. It can be useful to manage opened windows programmatically in applied logic, and we are planning to include this feature to the roadmap, but now I cannot certainly say when it will be available.

Hi Yuriy,

can you elaborate a little bit on what you mean by “controlling opened windows”? I thought WindowManager.getOpenWindows() does exactly this, or is just an internal method? Even if CUBA does not have a public API for this, it should be possible to get a tab change event directly from Vaadin, right? Do you have any glue about a starting point where i can take a look in the CUBA sources and the Vaadin bindings that are responsible for creating the tabs?

bye,
Mario

WindowManager.getOpenWindows() returns all opened windows without separation by tabs and breadcrumbs stacks, so you cannot use it for applied logic. It is the internal method and should be replaced with normal Window management API in the future.

You can start your investigations on tabs management from AppWorkArea component and WebWindowManager class that encapsulates window initialization logic, but please note, that this API can be completely changed in the next releases.

Hi Yuiry,

thanks i will take a look at these classes. AppWorkArea seems not to be a Spring Bean, is that correct? How can i get access to this instance? Unfortunately the classes are a little bit overwhelming for me.

When you talk about “next releases”, do you mean that you will introduce a API for Main Tab State changes in a 6.3.x release or will it not be covered until 6.4 at the earliest?

Bye
Mario

Our UI components are not Spring Beans, you can replace them only by registering new classes in WebComponentsFactory. WebWindowManager in version 6.3 is Spring Bean with scope=prototype, so it can be easily replaced using web-spring.xml configuration.

I think convenient API for Window management will not be included in 6.4, currently it is not included in out roadmap.

Hi Mario,

As I needed something like this today desperately (I have realized that the tinyMCE will crash upon changing tabs), I have found a way to get the caption of the active tabsheet. I know that it is not elegant or “proper”, but it works for me now.
I have created a timer on the form where I have the problematic tinyMCE editors, and then requested the AppUI, from that the WebAppWorkArea, finally from that the tabsheet. From this I have saved the tab’s caption, and compared it with the “previous” state of it. So if it has changed I could re-init the tinyMCEs and now the whole thing works.


 Timer tinyTimer = componentsFactory.createTimer()
        addTimer(tinyTimer)

        tinyTimer.setDelay(200)
        tinyTimer.setRepeating(true)

        tinyTimer.addActionListener({ timer ->
            try {
                AppUI ui = AppUI.getCurrent()
                WebAppWorkArea wa = ((Window.MainWindow) ui.getTopLevelWindow()).getWorkArea()
                CubaTabSheet ct = wa.getTabbedWindowContainer()
                String currentTabName = ((ct.selectedTab.components[0]) as WindowBreadCrumbs).label.getValue()
                tabHasChanged |= (currentTabName != 'Questions browser')

                if (tabHasChanged) {
                    // reinit tinymce and refresh
                }

            } catch (Exception e) {
                showNotification(e.message, Frame.NotificationType.HUMANIZED)
            }
        })

        tinyTimer.start()

Maybe this helps to solve your problem.

Cheers
Gabor