Composite Editor screen with parameter and listener from Parent editor controller

I have following scenario that i have done in legacy platform v 6.x:

    @Subscribe("scheduleMeetBtn")
    public void onScheduleMeetBtnClick(Button.ClickEvent event) {

        if(PersistenceHelper.isNew(getEditedEntity())){
            notifications.create(Notifications.NotificationType.HUMANIZED)
                    .withCaption("SELECT")
                    .withDescription("Please Save the Sales Opportunity before setting a meeting")
                    .show();

        }else {
            CalendarTaskEvent calendarTaskEvent = metadata.create(CalendarTaskEvent.class);
            calendarTaskEvent.setEventGroup(EventGroup.CRM);
            calendarTaskEvent.setEventCategory(EventCategory.MEETING);
            calendarTaskEvent.setTaskStatus(TaskStatus.PLAN);
            if(getEditedEntity().getLeadFrom().equals(LeadFrom.CUSTOMER)) {
                calendarTaskEvent.setCustomer(getEditedEntity().getCustomerProfile().getName());
                calendarTaskEvent.setCustomerProfile(getEditedEntity().getCustomerProfile());
            }else{
                calendarTaskEvent.setCustomer(getEditedEntity().getProspect().getName());
                calendarTaskEvent.setProspect(getEditedEntity().getProspect());

            }
            calendarTaskEvent.setSalesOpportunity(getEditedEntity());
 
            openEditor(calendarTaskEvent, WindowManager.OpenType.DIALOG, ParamsMap.of("hideEventGroup", "yes")).addCloseWithCommitListener(() -> salesOpportunityDs.refresh());
        }
    }

As you may have noticed “openEditor(…” has -
(1) Parameter sent which is not any Entity element rather just a simple parameter value sent to the editor screen to control the behavior of the editor screen
(2) .addCloseWithCommitListener(() : that refreshes the screen data aftert the editor has committed the entry

In Platform V7.x I tried in the following way:

 screenBuilders.editor(calendarTaskEventsGrid)
                    .newEntity()
                    .withInitializer(task -> {          // lambda to initialize new instance
                        task.setName("New customer");
                    })
                    .withScreenClass(CalendarTaskEventEdit.class)    // specific editor screen
                    .withLaunchMode(OpenMode.DIALOG)        // open as modal dialog
                    .build()
                    .show();

But “task.setName(“New customer”);” seems not appropriate to use (desn’t recognize). More importantly, what is right way to use ".addCloseWithCommitListener(()?

How can we do the #1 & #2 in V7 as mentioned above?

Hi mkhan,
Maybe you can find some solutions of your problems in the link below:
https://doc.cuba-platform.com/manual-7.1/opening_screens.html

See an example from the docs section suggested in the reply above:

.withAfterCloseListener(afterCloseEvent -> {
    if (afterCloseEvent.getCloseAction().equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {
        // 
    }
})
1 Like

Hi @knstvk
Thank you. To understand well, I see there are options calling screens

a) Will this work for Editor Screen? If I want to use .newEntity() or .editEntity(calendarTaskEvent) then I can’t use the recommended code snippet you provided but of course no issue with the following.

 screenBuilders.screen(this)
                    .withScreenClass(CalendarTaskEventEdit.class)
                    .withAfterCloseListener(afterCloseEvent -> {
                        if (afterCloseEvent.getCloseAction().equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {
                            // do refresh
                        }
                    })
                    .build()
                    .show();

And any suggestion with regards to the first question i.e. sending static (string) parameter?

Hi @knstvk
I have explored user guide but didn’t find any example or relevant documentation for the suggested use of the .withAfterCloseListener for Editor screen. Please see below that it is not recognized when used with editor screen:

image

Thanks for your help.

Hi Mortoza,

The withAfterCloseListener() method is available only for the builder if you specify the screen class like this:

screenBuilders.editor(Material.class, this)
        .editEntity(material)
        .withScreenClass(MaterialEdit.class)
        .withAfterCloseListener(afterCloseEvent -> {
            //
        })
        .build()
        .show();

If you don’t know the concrete screen class, first build the screen, then add the listener and show the screen:

Screen screen = screenBuilders.editor(Material.class, this)
        .editEntity(material)
        .build();
screen.addAfterCloseListener(afterCloseEvent -> {
    //
});
screen.show();

Thank you @knstvk