Source: xxe/control/InteractiveRemoteCommand.js

/**
 * The base class of all <em>interactive</em>, 
 * {@linkplain RemoteCommand remote commands}.
 */
export class InteractiveRemoteCommand extends RemoteCommand {
    constructor(commandName) {
        super(commandName);
    }
    
    execute(mode, docView, params, event=null) {
        if (mode === EXECUTE_TEST) {
            return super.execute(mode, docView, params, event);
        }

        // This kind of command (e.g. EditPITargetCmd) does not have to check
        // on the client-side whether the not being acted upon is
        // editable. This will be done by the remote command executed on the
        // server-side.
        
        Command.consumeEvent(event);
        
        return docView.sendExecuteCommand(mode, this.commandName, params)
            .then((result) => {
                if (result !== null &&
                    result.status === COMMAND_RESULT_STOPPED &&
                    result.value !== null) {
                    return new Promise((resolve, reject) => {
                        this.resumeExecution(mode, docView, params,
                                             result.value, resolve, reject);
                    });
                } else {
                    return this.commandExecuted(mode, docView, params, result);
                }
            });
            // No need to catch errors here. At worst, sendExecuteCommand will
            // return a null Promise.
    }

    /**
     * Invoked when the command execution has been stopped and 
     * some information has been returned by the command. 
     * <p>This information is typically used to display a dialog box 
     * letting the user choose something in order to actually execute 
     * the command (this time without being stopped for lack 
     * of sufficient input).
     * <p>Default implementation is transparent and simply causes the command 
     * to return its original {@link CommandResult CommandResult.STOPPED} 
     * result.
     */
    resumeExecution(mode, docView, params,
                    stoppedCommandInfo, resolve, reject) {
        resolve(new CommandResult(COMMAND_RESULT_STOPPED, stoppedCommandInfo));
    }
}