Use PopupButton in browse action

Hi

Is there any way to use simple PopupButton as component
in brwser action ?
Now I use ItemTrackingAction class for create custom action in browse.
I’d like to use PopupButton , bacause I have many action which I want to group.

Hi!

You can add your actions to PopupButton using addAction() method. For instance,

@Inject
private PopupButton popupButton;

@Override
public void init(Map<String, Object> params) {
    popupButton.addAction(new ItemTrackingAction("demoAction")
            .withCaption("Demo Caption")
            .withHandler(actionPerformedEvent -> showNotification("Handler is invoked")));
}

Or if you want to use declarative way:

XML:

<popupButton id="popupButton"
             caption="My Actions">
    <actions>
        <action id="firstAction"
                caption="First Action"
                invoke="firstActionHandler"/>
        <action id="secondAction"
                caption="Second Action"
                invoke="secondActionHandler"/>
    </actions>
</popupButton>

Code in controller:

public void firstActionHandler() {
    // do something
}

public void secondActionHandler() {
    // do something
}

You can see live example in our Sampler application: popup sample.
Documentation about PopupButton: https://doc.cuba-platform.com/manual-6.9/gui_PopupButton.html

Thangs

I have other question. Cuba studio crates browse window automagically with buttonsPanel section.
Is there any way to add PopupButton component with empty actions to buttonsPanel while this process ?

You can add PopupButton to buttonsPanel from screen controller class or declaratively in XML.

(Upd.) You can change template in CUBA Studio that generates table in the browse screen. If you use windows you can find template for table in the following path:

dir_with_Studio\resources\app\studio\templates\snippet\screen

Open table.xml

Find buttonsPanel element and put popupButton

<buttonsPanel id="buttonsPanel"
              alwaysVisible="true">
        <%tableActions.each { action ->%>
            <button id="${action}Btn" action="${tableId}.${action}"/>                
        <%}%>
		<popupButton id="popupButton"/>
</buttonsPanel>