Сделал комбинированное отображение сущности (список + редактор), в редакторе сделал 2 таблицы (dataGrid) со связанными сущностями. Проблема в том, что кнопки “Создать” остаются активными даже когда основная сущность не выбрана (по нажатию получаем естественно NullPointerException).
Можно ли как-то условно прятать эти кнопки, если сущность не выбрана?
Красным обведена такая кнопка:
XML:
<window xmlns="http://jmix.io/schema/ui/window"
xmlns:c="http://jmix.io/schema/ui/jpql-condition"
caption="msg://organizationBrowse.caption"
focusComponent="table">
<data>
<collection id="organizationsDc"
class="ru.rsmu.intd.entity.Organization">
<fetchPlan extends="_base">
<property name="bases" fetchPlan="_base"/>
<property name="employees" fetchPlan="_base"/>
</fetchPlan>
<loader id="organizationsDl">
<query>
<![CDATA[select e from IntD_Organization e]]>
</query>
</loader>
</collection>
<instance id="organizationDc"
class="ru.rsmu.intd.entity.Organization">
<fetchPlan extends="_base">
<property name="bases" fetchPlan="_base"/>
<property name="employees" fetchPlan="_base"/>
</fetchPlan>
<loader/>
<collection id="basesDc" property="bases"/>
<collection id="employeesDc" property="employees"/>
</instance>
</data>
<facets>
<dataLoadCoordinator auto="true"/>
<screenSettings id="settingsFacet" auto="true"/>
</facets>
<actions>
<action id="save" icon="OK" caption="msg:///actions.Ok" shortcut="CTRL-ENTER"/>
<action id="cancel" icon="CANCEL" caption="msg:///actions.Cancel" description="Esc"/>
</actions>
<dialogMode height="600" width="800"/>
<layout>
<split id="split" height="100%" orientation="horizontal" reversePosition="true" width="100%">
<vbox id="lookupBox" expand="table" height="100%" margin="false,true,false,false" spacing="true">
<filter id="filter" dataLoader="organizationsDl">
<properties include=".*"/>
</filter>
<dataGrid id="table"
width="100%"
dataContainer="organizationsDc">
<actions>
<action id="create" type="create"/>
<action id="edit" type="edit"/>
<action id="bases" type="related" caption="msg://ru.rsmu.intd.screen.organization/organizationBrowse.bases">
<properties>
<property name="property" value="bases"/>
<property name="openMode" value="DIALOG"/>
</properties>
</action>
<action id="remove" type="remove"/>
</actions>
<columns>
<column id="title" property="title"/>
<column id="shortTitle" property="shortTitle"/>
<column id="address" property="address"/>
</columns>
<simplePagination/>
<buttonsPanel id="buttonsPanel"
alwaysVisible="true">
<button id="createBtn" action="table.create"/>
<button id="editBtn" action="table.edit"/>
<button id="relatedBtn" action="table.bases"/>
<button id="removeBtn" action="table.remove"/>
</buttonsPanel>
</dataGrid>
<hbox id="lookupActions" spacing="true" visible="false">
<button action="lookupSelectAction"/>
<button action="lookupCancelAction"/>
</hbox>
</vbox>
<vbox id="editBox" height="100%" margin="false,false,false,true" expand="fieldGroupBox" spacing="true">
<scrollBox id="fieldGroupBox">
<form id="form" dataContainer="organizationDc">
<column width="350px">
<textField id="titleField" property="title" required="true"/>
<textField id="shortTitleField" property="shortTitle" required="true"/>
<textField id="addressField" property="address" required="true"/>
</column>
</form>
<hbox id="actionsPane" spacing="true" margin="true,false,true,false">
<button id="saveBtn" stylename="primary" action="save"/>
<button id="cancelBtn" action="cancel"/>
</hbox>
<vbox margin="true,false,true,false">
<vbox margin="false,false,true,false">
<label stylename="h2" value="msg://organizationBrowse.bases"/>
</vbox>
<dataGrid id="basesTable"
width="100%"
dataContainer="basesDc">
<actions>
<action id="create" type="create"/>
<action id="edit" type="edit"/>
<action id="remove" type="remove"/>
</actions>
<columns>
<column id="title" property="title"/>
<column id="address" property="address"/>
</columns>
<simplePagination/>
<buttonsPanel id="basesButtonsPanel"
alwaysVisible="true">
<button id="basesCreateBtn" action="basesTable.create"/>
<button id="basesEditBtn" action="basesTable.edit"/>
<button id="basesRemoveBtn" action="basesTable.remove"/>
</buttonsPanel>
</dataGrid>
</vbox>
<vbox margin="true,false,true,false">
<vbox margin="false,false,true,false">
<label stylename="h2" value="msg://organizationBrowse.employees"/>
</vbox>
<dataGrid id="employeesTable"
width="100%"
dataContainer="employeesDc">
<actions>
<action id="create" type="create"/>
<action id="edit" type="edit"/>
<action id="remove" type="remove"/>
</actions>
<columns>
<column id="person" property="person"/>
<column id="position" property="position"/>
</columns>
<simplePagination/>
<buttonsPanel id="employeesButtonsPanel"
alwaysVisible="true">
<button id="employeesCreateBtn" action="employeesTable.create"/>
<button id="employeesEditBtn" action="employeesTable.edit"/>
<button id="employeesRemoveBtn" action="employeesTable.remove"/>
</buttonsPanel>
</dataGrid>
</vbox>
</scrollBox>
</vbox>
</split>
</layout>
</window>
В целом не удалось пока нагуглить, можно ли условно отображать части интерфейса… Только напрямую указать visible, но оно не может меняться в зависимости от каких-либо условий. В идеальной ситуации вообще как-то скрыть обе таблицы в правом блоке, если основной объект не выбран.