The recipe is simple and straightforward:
Extend abstract class CommandBase
. Do not implement interface Command
. Example:
public class WrapElementCmd extends CommandBase {
The command must have a constructor which invokes the CommandBase
constructor. Example:
public WrapElementCmd() { super(/*repeatable*/ false, /*recordable*/ true); }
The “execute method” to be implemented is doExecute
:
public CommandResult doExecute(DocumentView docView, String parameter, int x, int y) { ... }
The parent component of a dialog box is obtained using DocumentView.getDialogParent
. (XXE v9 had DocumentView.getPanel
.)
Optional step. If the command is invoked by xxeserver, the server side part of XMLmind XML Editor Web Edition (XXEW), which is designed to run on computers having no display, then docView.getDialogParent()
returns null
. Therefore if you intend to run your command not only in XXE, the desktop app, but also in XXEW, the Web Edition, you'll have to add this test at the beginning of your command:
if (docView.getDialogParent() == null) {
return CommandResult.STOPPED
;
}
The doExecute
method always returns a CommandResult
. Therefore
Replace return EXECUTION_FAILED;
by return CommandResult.FAILED;
(return CommandResult.CANCELED;
after the user clicks in a dialog box).
Replace return null;
by return CommandResult.DONE;
Replace return
by ruseful_result
;eturn CommandResult.done(
useful_result
);
If the command is repeatable, use CommandResult.success
to specify how the command is to be repeated. In practice, replace XXE v9 DocumentView.addToCommandHistory
:
docView.addToCommandHistory(this, "U+" + Integer.toString((char)code, 16), title);
by XXE v10 CommandResult.success
:
CommandResult result = CommandResult.success(null, "U+" + Integer.toString((char)code, 16), title);
Also make sure to take this pitfall into account.