Eidtor window close action default caption is not adequate

Hi

The default message key taken for the localized caption of the windowClose default action for an Editor is not adequate.

It is using “actions.Cancel” while it could/should use “actions.Close” especially when this one exists for dialog actions (see code snippets below).

In our app, all screens open in read-only mode, so the windowClose button does not cancel anything, it closes the window (as per the action name)

Once the editing mode has been set, the “Cancel” caption is confusing : the button will yet cancel editing (with unsaved changes check) but also close the window.

So If i want to add a button to cancel editing without closing the window, I’m stuck because “actions.Cancel” caption has already be taken by windowClose button.

Is there a simple way to change the message key for the windowClose default action ?

com.haulmont.cuba.gui.components.AbstractEditor

        Action closeAction = new BaseAction(WINDOW_CLOSE)
                .withCaption(messages.getMainMessage("actions.Cancel"))
                .withHandler(e ->
                        close(commitActionPerformed ? Window.COMMIT_ACTION_ID : getId())
                );

        getFrame().addAction(closeAction);

com.haulmont.cuba.gui.components.DialogAction

public class DialogAction extends BaseAction {

    public enum Type {
        OK("ok", "actions.Ok", CubaIcon.DIALOG_OK),
        CANCEL("cancel", "actions.Cancel", CubaIcon.DIALOG_CANCEL),
        YES("yes", "actions.Yes", CubaIcon.DIALOG_YES),
        NO("no", "actions.No", CubaIcon.DIALOG_NO),
        CLOSE("close", "actions.Close", CubaIcon.DIALOG_CLOSE);

Hi, Michael!

You can try this way:
create your own class extended AbstractEditor and redeclare closeAction.
Then, make all editors in your app extended your new class.

Regards,
Irina

Hi @i.lovtsova

@AbstractEditor is @Deprecated.

We already extended StandardEditor, so I did the following

   @Override
    protected void initActions(InitEvent event) {
        super.initActions(event);
        //replace closeAction caption with good one
        Window win = getWindow();
        win.removeAction(WINDOW_CLOSE);
        Action closeAction = new BaseAction(WINDOW_CLOSE)
                .withIcon(icons.get(CubaIcon.EDITOR_CANCEL))
                .withCaption(messages.getMainMessage("actions.Close"))
                .withHandler(this::cancel);
        win.addAction(closeAction);
    }

Thank you
Michael

Yeah, AbstractEditor is deprecated, but it is still used for legacy screens. If you have any legacy screens, you can override initCommitActions method in the same way as you did with initActions in StandardEditor.