Adding new diagram types

Adding new diagram types to the modeling tool consists of two steps:

  1. Overriding the abstract com.nomagic.magicdraw.uml.DiagramDescriptor class

  2. Registering a new diagram type

Step #1. Override the abstract com.nomagic.magicdraw.uml.DiagramDescriptor class

Override the abstract class DiagramDescriptor and implement the following abstract methods:

The diagram descriptor example

For the full source code, see the Open API examples in <program installation directory>\openapi\examples.

/**
* Descriptor of a specific diagram.
*/
public class SpecificDiagramDescriptor extends DiagramDescriptor
{
public static final String SPECIFIC_DIAGRAM = "Specific Diagram";
/**
* Let this diagram type be a sub type of a class diagram type.
*/
public String getSuperType()
{
return DiagramType.UML_CLASS_DIAGRAM;
}
/**
* This is a creatable diagram.
*/
public boolean isCreatable()
{
return true;
}
/**
* Actions used in this diagram.
*/
public MDActionsManager getDiagramActions()
{
return SpecificDiagramActions.ACTIONS;
}
/**
* A configurator for a diagram toolbar.
*/
public AMConfigurator getDiagramToolbarConfigurator()
{
return new SpecificDiagramToolbarConfigurator();
}
/**
* A configurator for diagram shortcuts.
*/
public AMConfigurator getDiagramShortcutsConfigurator()
{
return new ClassDiagramShortcutsConfigurator();
}
/**
* A configurator for a diagram shortcut menu.
*/
public DiagramContextAMConfigurator getDiagramContextConfigurator()
{
return new BaseDiagramContextAMConfigurator();
}
/**
* Id of the diagram type.
*/
public String getDiagramTypeId()
{
return SPECIFIC_DIAGRAM;
}
/**
* A diagram type human name.
*/
public String getSingularDiagramTypeHumanName()
{
return "Specific Diagram";
}
/**
* A diagram type human name in a plural form.
*/
public String getPluralDiagramTypeHumanName()
{
return "Specific Diagrams";
}
/**
* Resizable svg icon for diagram.
*/
public ResizableIcon getSVGIcon()
{
ResizableIcon icon = null;
try
{
icon = IconsFactory.getSvgIcon(new File("icons/specificdiagram.svg").toURI().toURL());
}
catch(Exception e){e.printStackTrace();}
return icon;
}
/**
* URL to a small icon for a diagram.
*/
public URL getSmallIconURL()
{
return getClass().getResource("icons/specificdiagram.svg");
}
}

Step #2. Register a new diagram type

The new diagram descriptor should be registered in a modeling tool using the com.nomagic.magicdraw.core.Application.addNewDiagramType(DiagramDescriptor) method of the modeling tool you are using. This method can be invoked when a plugin is initialized.

The diagram descriptor registration example

For the full source code, see the Open API examples in <program installation directory>\openapi\examples\specificdiagram.

class SpecificDiagramPlugin extends Plugin{
/**
* Initializing the plugin.
*/
public void init()
{
// Registering a new diagram type
Application.getInstance().addNewDiagramType(new SpecificDiagramDescriptor());
}
/**
* Always returns true, because this plugin does not have any close specific actions.
*/
public boolean close()
{
return true;
}
/**
* Always returns true, because this plugin does not have any specific suportability conditions.
*/
public boolean isSupported()
{
return true;
}
}