UI for 1 to 1 association similar to 1 to many composition

Hi,

I am facing following issues and need your help.

Please refer the diagram attached for ease of clarity. I have entity named “Cases”. This entity has 1 to 1 composition relationship with entity "CaseDetail"s and “AwardPublicationDetails”.

As Cuba platform does not support 1 to 1 composition, I have used 1 to 1 association for the above entities.

I am having problems in creating entity “Cases” editor screen. I would like to create the UI for 1 to 1 association which would be similar to 1 to many composition created by Cuba Studio.

It should not allow to create more than one row (object) of CaseDetail and AwardPublicationDetails

Let me know how to achieve it using Cuba studio.

Thanks

EntitiyCasesUI

UI Issues

Hi Asif,

Please see an example of handling one-to-one association in UI here: GitHub - cuba-labs/one-to-one

Here we have Customer entity and CustomerDetails entity which is a one-to-one association with Customer. Basically, all the code is around actions of the PickerField component which displays CustomerDetails in the Customer editor:


public class CustomerEdit extends AbstractEditor<Customer> {

    @Named("fieldGroup.details")
    private PickerField detailsField;

    @Inject
    private Metadata metadata;

    @Inject
    private DataManager dataManager;

    @Override
    protected void postInit() {
        Customer customer = getItem();

        detailsField.removeAllActions();
        
        detailsField.addAction(new BaseAction("create") {
            @Override
            public void actionPerform(Component component) {
                CustomerDetails details = metadata.create(CustomerDetails.class);
                openEditor(details, WindowManager.OpenType.THIS_TAB).addCloseWithCommitListener(() -> {
                    customer.setDetails(details);
                });
            }

            @Override
            public String getIcon() {
                return "icons/add.png";
            }
        });

        detailsField.addOpenAction();

        detailsField.addAction(new PickerField.ClearAction(detailsField) {
            @Override
            public void actionPerform(Component component) {
                if (customer.getDetails() != null)
                    dataManager.remove(customer.getDetails());

                super.actionPerform(component);
            }
        });
    }
}

Hi Konstantin,

Thanks a lot for the example. I hope it would be useful to other newbies just the way it was useful to me.

Thanks