Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
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.
Code Block | ||
---|---|---|
| ||
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
Info |
---|
For more information on the classpath specification details, see Classpath. |
The compiled code must be packed to a .jar file.
To create a .jar file, use a jar command in the plugins directory:
Code Block | ||
---|---|---|
| ||
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.
Code Block | ||
---|---|---|
| ||
<?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.