Create sample Plug-ins

This section shows how to make a plug-in that adds a menu to Astah.

section divider

Creating a new project

First, create a new project. Move to the directory where you want to create the plug-in project and run the command for your product:

If you are using Astah Professional or Astah UML:

> astah-generate-project

If you are using Astah SysML:

> astah-sysml-generate-project

If you are using Astah System Safety:

> astah-safety-generate-project

Next, specify the group ID, artifact ID, version and so on.

Generate Project

A new folder for the Plug-in project will be generated in a name you specified in the artifact id.

Generating a new project

The generated project consists of the files below.

File NameDescription
pom.xmlThis includes maven setting such as project build information and dependencies.
Activator.javaThis describes the initialization and finalization for Astah Plug-in and will be called when the Plug-in is started or stopped.
plugin.xmlDescribe extension point ex. menu, view etc. This chapter uses menu extension point of Astah, details will be explained below.
plugin.propertiesInternationalize labels to show UI on Astah.
plugin_ja.propertiesJapanese labels. plugin.properties is used by default; plugin_ja.properties is used when Astah runs in a Japanese environment.
section divider

Launch Astah with the Plug-in

To launch Astah with the plug-in you are developing, first build the project. Move to the plug-in project directory and run this command:

> astah-build
Astah build in command prompt

NOTE: If you update the Astah Plug-in SDK (ASDK) to a newer version, open pom.xml in a text editor and make sure the version of astah-maven-plugin matches the one included with the ASDK. You can find it in astah-plugin-SDK-x.x\repository\com\change_vision\astah\astah-maven-plugin.

When it’s built successfully, a new folder “target” is created containing the plug-in file, [artifact id]-[version].jar. Now launch Astah with the plug-in by running this command:

> astah-launch

Then Astah should launch with this Plug-in.

Launching Astah

You will see a menu that is added by this Plug-in under [Tools] menu.

Adding a Template Group menu
section divider

Import the Plug-in project to IDE

Astah Plug-in SDK is based on Maven, however, if you would like to use IDE like Eclipse or IntelliJ IDEA to develop Plug-ins instead of using Astah’s Plug-in SDK only, you can do that too. Here’s how you can import the Plug-in project to Eclipse and IntelliJ.

section divider

Eclipse

You can run maven commands in Eclipse by using m2e. However, you are not able to set the classpath to JAR while using m2e. So to set the classpath, you need to use astah-mvn command instead of using m2e’s Dependency Management.

1. Installation of Eclipse and m2e

First, install Eclipse and m2e from Eclipse. The Eclipse IDE for Java Developers package includes m2e.

The installation of this package should not affect anything in your development environment. Therefore we recommend you to use this package. However, if you have Eclipse installed already, you can install m2e from m2e.

2. Configure Astah Plug-in to MAVEN_HOME on Eclipse

Run Eclipse, choose a workspace, and set the Astah Plug-in SDK as MAVEN_HOME: open [Window] – [Preferences], select [Maven] – [Installations], and add the Astah Plug-in SDK installation directory (ASDK_HOME), as shown below.

Configuring Astah Plugin to Maven

3. Generate config to load classpath for Eclipse

Now, before importing the plug-in project to Eclipse, move to the working directory of Plug-in Project, set the environment variables of M2_HOME to ASDK_HOME and then run the command below.:

> astah-mvn eclipse:eclipse

Now all is ready for you to import the Plug-in project into Eclipse.

section divider

IntelliJ IDEA

IntelliJ IDEA has Maven Integration. Please download IntelliJ IDEA from IntelliJ site. When you first run IntelliJ IDEA, a [New Project Wizard] appears for the set up. If you already use IntelliJ IDEA, go to step 2 and then import the project.

1. Import a Plug-in project to IntelliJ IDEA

Please refer to IntelliJ’s resource for how to import projects. However, you need to set the Astah Plug-in SDK on IntelliJ before you import the Plug-in project.

2. Configure MAVEN_HOME to Astah Plug-in on IntelliJ IDEA

Let’s set Astah Plug-in SDK to MAVEN_HOME in IntelliJ IDEA.

Run IntelliJ, and then select [File] – [Settings] – [Maven]. Check the [Override] for Maven home directory and then specify Astah Plug-in SDK install folder(ASDK_HOME) as the figure below.

Configuring IntelliJ IDEA

When the setting is complete, the classpath should be set up also.

section divider

Adding a menu to Astah

To create a Plug-in for Astah, an extension point needs to be defined in plugin.xml with the “point” property of <extension> tag. Two extension points are currently provided:

Extension Point NameDescription
com.change_vision.astah.ui.actionSetsAdding a menu on Astah
com.change_vision.astah.ui.view Adding an extended view on Astah

Below is a sample of how you write plugin.xml to add a menu on Astah.

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <extension point="com.change_vision.astah.ui.actionSets">
      <actionSet
            label="%action_set_label"
            visible="true"
            id="com.example.helloworld.actionSet">
         <menu
               id="helloworld"
               label="%menu_group"
               path="tool/helloworld">
         </menu>
         <action
			   label="%menu_label"
               icon="icons/sample.gif"
               class="com.example.actions.HelloWorldAction"
               tooltip="%menu_tooltip"
               menubarPath="tool/helloworld/"
               id="com.example.actions.HelloWorldAction">
         </action>
     </actionSet>
   </extension>
</plugin>

In this sample, <menu> tag is used to add a new menu [Sample Menu] under [Tool]. <action> tag is used to add another menu with Hello World Plug-in under the [Sample Menu]. The location of menu is specified with <action> tag’s menubarPath attribute. The value “tool” is an id of [Tool] menu and it should be specified in the <menu> tag’s path attribute and also <action> tag’s menubarPath attribute. The id of all the menu can be found at Astah Menu ID List. Also <actionSet> tag is used to group all the <action>tags. All the actions when the menu is selected should be specified with <action>’s class attributes.

Here is the summary of the plugin.xml.

Tag NameAttributeRequiredDescription
pluginRequired
extensionRequiredSpecify extension point
pointRequiredSpecify com.change_vision.astah.ui.actionSets
actionSetRequiredSpecify the group of menu to menubar
label(Not available)
visible(Not available)
idSpecify group ID
menuAdd menu group
labelRequiredSpecify label of group menu
idRequiredSpecify id of group menu
pathRequiredSpecify location of path
actionAdd menu
labelRequiredSpecify label of menu
icon(Not available)
classRequiredSpecify the class of push the menu
tooltip(Not available)
menubarPathRequiredSpecify the location of menu
idRequiredSpecify the id of menu

Action classes are explained below.

section divider

Display another language

In this sample, <action> tag’s label is “%menu_label”. This notation is to make the label appear in different languages depending on the environment to run Astah on. The string “menu_label” is the key, and the label text is defined in both plugin.properties and plugin_ja.properties.

plugin.properties:

menu_label=&Hello World

plugin_ja.properties:

menu_label=こんにちは、ワールド(&H)

If Astah runs in a Japanese environment, the label from plugin_ja.properties is shown; otherwise, the English label from plugin.properties is shown.

section divider

Make Action Classes

Now that you have added a menu to Astah’s menu bar, create the action that shows a “Hello World” message. To do so, create a class which implements IPluginActionDelegate interface.

/*
 * Please change this class's package to your genearated Plug-in's package.
 * Plug-in's package namespace => com.example
 *   com.change_vision.astah.extension.plugin => X
 *   com.example                              => O
 *   com.example.internal                     => O
 *   learning                                 => X
 */
package com.example.actions;


import javax.swing.JOptionPane;
import com.change_vision.jude.api.inf.ui.IPluginActionDelegate;
import com.change_vision.jude.api.inf.ui.IWindow;

public class HelloWorldAction implements IPluginActionDelegate {

  public Object run(IWindow window) throws UnExpectedException {
      try {
          JOptionPane.showMessageDialog(window.getParent(), "Hello World");

      } catch (Exception e) {
        JOptionPane.showMessageDialog(window.getParent(), "Exception occured", "Alert", JOptionPane.ERROR_MESSAGE);
          throw new UnExpectedException();
      }
      return null;
  }
}

The run() method of the IPluginActionDelegate interface will be called when the menu is clicked in Astah. In this sample, clicking [Hello World] menu makes a dialog appear with “Hello World” message on. Any exception errors happen during the action’s performance will be thrown as a UnExpectedException, an inner class of the IPluginActionDelegate interface.