Search code examples
cuba-platform

CUBA platform : invalid window height for editor opened as dialog from a table action


I have a screen with a table handling a many-to-many relationship towards an entity (simple, 2 fields) for which 1 single record is defined yet.

I created standard browser screen for the associated entity and defined openType = DIALOG for the action table "add" of the previous screen.

Then the dialog window is too much compacted in height (see screenshot below), I suppose this is because there is not enough entities to display so the height calculation is wrong.

dialog height wrong

If I do "analyse layout" on the dialog window I get the following warning :

[WARN] Nested component 'contactEmailsTable'
Nested component has relative height 100.0% inside window with undefined height

As a workaround, I tried to set manually table height in studio, no chance.

Did not see in studio where to set manually window height so I tried to redefined it through overriding of init method (see below), no chance.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    int unit = getHeightUnits();
    float height = getHeight();
    switch(unit) {
        case UNITS_PIXELS:
            setHeight(""+height * 1.10f+"px");
        case UNITS_PERCENTAGE:
            setHeight(""+Math.min(100, height + 0.10f)+"%");
    }
}

Hereunder the xml of the said dialog.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
    caption="msg://browseCaption"
    class="com.busy.busyapp.gui.contactemail.ContactEmailBrowse"
    focusComponent="contactEmailsTable"
    lookupComponent="contactEmailsTable"
    messagesPack="com.busy.busyapp.gui.contactemail">
<dsContext>
    <collectionDatasource id="contactEmailsDs"
                          class="com.busy.busyapp.entity.ContactEmail"
                          view="_local">
        <query>
            <![CDATA[select e from busyapp$ContactEmail e]]>
        </query>
    </collectionDatasource>
</dsContext>
<layout expand="contactEmailsTable"
        spacing="true">
    <filter id="filter"
            applyTo="contactEmailsTable"
            datasource="contactEmailsDs">
        <properties include=".*"/>
    </filter>
    <table id="contactEmailsTable"
           presentations="true"
           width="100%">
        <actions>
            <action id="create"/>
            <action id="edit"/>
            <action id="remove"/>
            <action id="excel"/>
        </actions>
        <columns>
            <column id="label"/>
            <column id="email"/>
        </columns>
        <rows datasource="contactEmailsDs"/>
        <rowsCount/>
        <buttonsPanel id="buttonsPanel"
                      alwaysVisible="true">
            <button id="createBtn"
                    action="contactEmailsTable.create"/>
            <button id="editBtn"
                    action="contactEmailsTable.edit"/>
            <button id="removeBtn"
                    action="contactEmailsTable.remove"/>
            <button id="excelBtn"
                    action="contactEmailsTable.excel"/>
        </buttonsPanel>
    </table>
</layout>


Solution

  • The following examples show how to manage dialog window dimensions.

    Open a screen as a dialog with defined width and height:

    openEditor(entity, OpenType.DIALOG.width(480).height(320));
    

    Set the width and height of a screen in its controller:

    @Override
    public void init(Map<String, Object> params) {
        getDialogOptions().setWidth(480).setHeight(320);
    }
    

    The same in XML descriptor:

    <dsContext/>
    <dialogMode width="480" height="320"/>
    <layout/>
    

    Specify that the screen should be always opened as a dialog:

    @Override
    public void init(Map<String, Object> params) {
        getDialogOptions().setForceDialog(true);
    }
    

    The same in XML descriptor:

    <dsContext/>
    <dialogMode forceDialog="true"/>
    <layout/>