MagicDraw 18.3 Documentation

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

With this example, we will create a plugin that displays a message on the program startup. To create the plugin, you need to write a plugin descriptor.


Step #1: Create your plugin folder in a plugins folder

Create a myplugin folder in the plugins folder in the installation directory of the modeling tool.


Step #2: Write a plugin code

The plugin must contain at least one class derived from the com.nomagic.magicdraw.plugins.Plugin class.

package myplugin;
import com.nomagic.magicdraw.plugins.Plugin;
import javax.swing.*;
public class MyPlugin extends Plugin
{
    @Override
    public void init()
    {
        JOptionPane.showMessageDialog(null, "My Plugin init");
    }
    @Override
    public boolean close()
    {
        JOptionPane.showMessageDialog( null, "My Plugin close"); 
        return true;
    }
    @Override
    public boolean isSupported()
    {
        //plugin can check here for specific conditions
        //if false is returned plugin is not loaded.
        return true;
    }
}

This plugin shows the one message when it is initialized, and another message when it is closed.

Step #3: Compile and pack the plugin to a .jar file 

For more information on the classpath specification details, see Claspath.

The compiled code must be packed to a .jar file.

To create a .jar file, use a jar command in the plugins directory:

 jar -cf myplugin\myplugin.jar myplugin*.class

Step #4: Write a plugin descriptor

The plugin descriptor is a file named plugin.xml. This file should be placed in the myplugin folder.

<?xml version="1.0" encoding="UTF-8"?>
<plugin id="my.first.plugin" name="My First Plugin" version="1.0" provider-name="Coder" class="myplugin.MyPlugin"> 
    <requires>
        <api version="1.0"/>
    </requires> 
    <runtime>
        <library name="myplugin.jar"/>
    </runtime>
</plugin>

For detailed information about the plugin descriptor, see Plugin descriptor.

  • No labels