Command¶
Overview¶
- By defining a command and associating it with the command handler implemented in the extension, you can call your own processing from the extension point of the ribbon.
- As the valid/invalid condition of the command, you can specify the model selection state, the model class, and the target view definition.
Command details¶
- 
Property Key Description Range Requiredid An ID that uniquely identifies the command. A unique string for all deployed extensions A string that represents the ID Required title Command title 1 Any string - description Command description 1 Any string - group The group to which the command belongs 1 Character string that represents the group name - execFunc Command handler name implemented at the entry point Character string representing function name/method name Required canExecWhen Valid condition of the command. For details, see the subordinate properties Object - canExecWhen.uiState One of the following values that represents the state of the UI. Always: Always enabled (default value when property is omitted).ProjectOpened: Effective when a project is open.ModelSelected: Valid when a model is selected.ModelSelectedInEditor: Effective when a model is selected in the editor."Always", "ProjectOpened", "ModelSelected", "ModelSelectedInEditor" - canExecWhen.profiles Target project profile name Character string that represents the profile name - canExecWhen.metamodels The class name of the selected model or its inheriting class name. If you specify *in the value or omit the property, it is valid in all models. Ignored if the uiState property is notModelSelected,ModelSelectedInEditor."*" or a string that represents the class name. If more than one, specify them with commas. - canExecWhen.viewDefinitions Target view definition names. If you specify *in the value or omit the property, it is valid in all view definitions. Ignored if the uiState property is notModelSelectedInEditor."*" or a character string that represents the view definition name. If more than one, specify them with commas. - 
Command definition example¶
{
    "extensionPoints": {
        "commandGroups":
        [
            {
                "name": "codegen",
                "title": "Generate Source Code"
            }
        ],
        "commands":
        [
            {
                "id": "myExtension.generateCode",
                "title": "generate code",
                "description": "generate code description",
                "group": "codegen",
                "execFunc": "GenerateCode",
                "canExecWhen":
                {
                    "uiState": "ModelSelected",
                    "metamodels": "FunctionalComponent,Component",
                    "viewDefinitions": "*"
                }
            },
            {
                "command": "myExtension.checkError",
                "title": "Check for errors",
                "execFunc": "CheckError",
            }
        ]
    }
}
Command handler implementation example¶
public void GenerateCode(ICommandContext commandContext, ICommandParams commandParams)
{
    //Command handler implementation code
}
Command parameter usage example¶
You can specify parameters when executing the command defined in the manifest extension point from within the extension.
void ExcecSomeCommands()
{
    //generate parameters
    var execParams = App.CreateCommandParams();
    execParams.AddParam("value1"); //Value can be referenced with execParams[0]
    execParams.AddParam("value2"); //Value can be referenced with execParams[1]
    //execParams.AddParamWithName("param1", "value1"); //Value reference is possible with execParams["param1"]
    //execParams.AddParamWithName("param2", "value2"); //Value can be referenced with execParams["param2"]
    //execute the command with parameters
    App.ExecuteCommand("otherExtension.someCommand", execParams);
}