MagicDraw 18.3 Documentation

Skip to end of metadata
Go to start of metadata

You need to extend the Eclipse main menu with a Plugin command. Conventionally you do not need to write any additional code so that the main menu of a program was extended with some specific commands brought by a plugin after the plugin is installed. However, this is necessary when the same plugin is installed on a modeling tool which is integrated with Eclipse. 

If an additional command should appear on the main menu or an additional button should be placed on the main toolbar in a modeling tool after the plugin installation, you need to create an Eclipse bundle that tells Eclipse where the command or the button should be placed. 

Example: Extending the Eclipse main menu with an additional command brought by a program plugin 

Let's say you have already created a plugin for your modeling tool, that is MagicDraw in this example, that extends the main menu of a program with a command whose id, for example, is "CUSTOM_ACTION_ID". 

To extend the Eclipse main menu with this command


  1. Create a class for an Eclipse bundle to extend the com.nomagic.magicdraw.integrations.eclipse.rcp.actions.MDEclipseActionWrapper class. 

This is an example of an Eclipse bundle class that connects to a MagicDraw command by its id "CUSTOM_ACTION_ID":

public class MyCustomActionWrapper extends MDEclipseActionWrapper
{
    public MyCustomActionWrapper()
    {
        super(CUSTOM_ACTION_ID);
    }
} 

This is a general way of connecting to an Eclipse the command org.eclipse.ui.actions.ActionDelegate that should be placed on the Eclipse main menu. 


    2. Create a descriptor (a plugin.xml file) for the Eclipse bundle to place the command on the Eclipse main menu. 

This is an example of a descriptor that should place the command with id "CUSTOM_ACTION_ID" under the Diagrams > Diagram Wizards menu:

<!-- Define command and attach to category -->
<extension point="org.eclipse.ui.commands">
<command id="MyCustomActionWrapper.cmd"
name= "Command name"
categoryId="MagicDraw"/> 


<!-- Attach command (action) to menu -->
<extension point="org.eclipse.ui.actionSets">
    <actionSet id="Custom action set"
        label="Custom action label"
        visible="false"> 
        <action class= "org.my.path.MyCustomActionWrapper" label= "Custom action label"
        id= "Custom_action_id"
        menubarPath= "Diagrams/Diagram Wizards/group"
        definitionId="MyCustomActionWrapper.cmd"/>
    </actionSet>
</extension> 


<!-- Attach to specific MagicDraw view and editor part -->
<extension name="Diagram or View Active"
    point="org.eclipse.ui.actionSetPartAssociations">
    <actionSetPartAssociation targetID="Custom_Action_Part">
        <part id="com.nomagic.magicdraw.integrations.eclipse.rcp.editors.DiagramEditor"/>
        <part id="CONTAINMENT_TREE"/>
        <part id="INHERITANCE_TREE"/>
        <part id="DIAGRAMS_TREE"/>
        <part id="EXTENSIONS_TREE"/>
        <part id="SEARCH_RESULTS_TREE"/>
        <part id="DOCUMENTATION"/>
        <part id="PROPERTIES"/>
        <part id="MESSAGES_WINDOW"/>
    </actionSetPartAssociation>
</extension> 

This is a general way of adding a command to the Eclipse main menu.

 

    3. Pack the command class with the Eclipse bundle descriptor to an Eclipse bundle (a .jar file) and save the file in <MagicDraw installation directory>\plugins\eclipse\plugins.

    4. Integrate your modeling tool with Eclipse.

    5. Start Eclipse.  The new command appears on the Eclipse main menu. 

<MagicDraw installation directory>\plugins\eclipse\plugins contains MagicDraw plugins that have commands to appear on the Eclipse main menu. Their plugin.xml files can be used as examples too. Accordingly it is the same with other modeling tools developed by No Magic Inc.