Creating commands

 

Overview of commands

Each Java MDA component selected in a project comes with a set of commands, each represented by a pop-up menu or property page item available for the elements concerned. The selection of one of these menu items activates a method defined in Objecteering MDA Modeler.

Commands are instances which are stereotyped “command”. They have a “label” attribute which defines the label displayed in menus.

 

Commands are created in the “GUI extensions” folder belonging to the J MDA component.

 

To create a command and make it accessible to the end-users of a given MDA component, the following steps must be carried out:

·         Create the command and define its applicability criteria

·         Add the Java code that will carry out the command task

·         Attach the command to the MDA component GUI, in other words, either to a contextual menu or to a property box toolbar or to both

 

To create and define the command, carry out the steps shown in Figure 180 below.

 

Figure 180. Creating a Java command

 

Steps:

1.      Select the "GUI extensions" folder in the explorer.

2.      Click on the  Create a Java command” button command.

 

The following dialog box then appears, in which the attributes of the command can be defined.

 

Figure 181. The "Define a command" window

 

Key:

·         "Name": This field defines the “logical” name of the command. It will not be shown to end user and is only used internally as an identifier for the command.

·         "Menu": This field defines the visible label of the command. It will be shown in menus if the command is attached to a contextual menu or in a toolbar button tooltip if the command is attached to a toolbar.

·         "Icon": This field defines the visible icon of the command. It will be used as the toolbar button icon if the command is attached to a toolbar.  Icons must be in “.bmp” or “.png” format. We recommend that the size of these icons be 16*16 pixels.

·         "Activation": This defines whether or not the command is available for read-only object. Read-only here must be understood  as a combination of:

o     the tool status (in other words, locked because editing is in progress, or not)

o     the selected element status (CMS locked or not, in other words, the presence of the red padlock in the explorer).

The command does not modify the model option means that the command can be executed whatever the element and tool status,  because the command’s contract is to not modify the model in any case.

The command modifies a read/write object, means that the command can be executed only if the tool is not locked and if the selected elements, which the command has to be applied to, are modifiable (no locker, not CMS locked for example)

·         "Metaclasses": This field holds the list of metaclasses whose instances are allowed targets for the commands. The command will not be visible and proposed to the end-user when the selected element is not of the types defined in this field.

·         "Java class to activate": This field defines the Java class that will be activated to perform the command action. This class must properly implement a specific interface to be suitable for command activation.

The user can either drag&drop an existing class from the model with the mandatory conditions that this class inherits from the DefaultMdacContextualCommand class and belongs to the component, or else enter the name of a new class. In this case, the class will be automatically created by MDA Modeler along with default code for its methods.

 

At this stage, the new command is created, configured and ready to run the default code provided by MDA Modeler, which consists in writing a message in the Objecteering console.

 

The only thing left to do now is to implement the actionPerformed method on your class to determine the action to be managed, as demonstrated in the following example:

 

package junit;

 

class DisplayHelloWorld extends DefaultMdacContextualCommand

{

   @Override

public void actionPerformed(

       ObList<ObElement> selectedElements,

       IJavaMdac mdac)

   {

       // Displays "Hello World !"

Objecteering.out.println(“Hello World !”);

   }

}