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
.)
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.