MenuID
Filefile
Editedit
Diagramdiagram
Alignmentalignment
Viewview
Tooltool
Windowwindow
Plug-inplugin
Helphelp
Diagram/Class Diagramdiagram/class_diagram
Diagram/UseCase Diagramdiagram/usecase_diagram
Diagram/Statemachine Diagramdiagram/state_chart_diagram
Diagram/Activity Diagramdiagram/activity_diagram
Diagram/Sequence Diagramdiagram/sequence_diagram
Diagram/Communication Diagramdiagram/collaboration_diagram
Diagram/Component Diagramdiagram/component_diagram
Diagram/Deployment Diagramdiagram/deployment_diagram
Diagram/Composite Structure Diagramdiagram/compositestructure_diagram
Diagram/Flowchartdiagram/flow_chart_diagram
Diagram/Data Flow Diagramdiagram/data_flow_diagram
Diagram/ER Diagramdiagram/er_diagram
Diagram/CRUDdiagram/crud_diagram
Diagram/Mindmapdiagram/mind_map_diagram
Diagram/Requirement Diagramdiagram/requirement_diagram
Diagram/Requirement Tablediagram/requirement_table
Tool/ER Diagramtool/er
Tool/CRUDtool/crud
Tool/Requirementtool/requirement
Tool/Traceabilitytool/traceability
section divider

Menu ID List for Astah SysML

MenuID
Filefile
Editedit
Diagramdiagram
SysML Requirement Diagramdiagram/sysml_requirement_diagram
SysML Requirement Tablediagram/sysml_requirement_table
SysML Block Definition Diagramdiagram/blockdefinition_diagram
SysML Internal Block Diagramdiagram/internalblock_diagram
SysML Parametric Diagramdiagram/sysml_parametric_diagram
SysML UseCase Diagramdiagram/sysml_usecase_diagram
SysML Statemachine Diagramdiagram/sysml_statemachine_diagram
SysML Activity Diagramdiagram/sysml_activity_diagram
SysML Sequence Diagramdiagram/sysml_sequence_diagram
Mindmapdiagram/mind_map_diagram
Alignmentalignment
Viewview
Tooltool
Mindmaptool/mindmap
Correct Modeltool/correct_model
System Propertiestool/system_property
Windowwindow
Pluginplugin
Helphelp
section divider

Menu ID List for Astah System Safety

MenuID
Filefile
Editedit
Diagramdiagram
SysML Requirement Diagramdiagram/sysml_requirement_diagram
SysML Requirement Tablediagram/sysml_requirement_table
SysML Block Definition Diagramdiagram/sysml_block_definition_diagram
SysML Internal Block Diagramdiagram/sysml_internal_block_diagram
SysML Parametric Diagramdiagram/sysml_parametric_diagram
SysML UseCase Diagramdiagram/sysml_usecase_diagram
SysML Statemachine Diagramdiagram/sysml_statemachine_diagram
SysML Activity Diagramdiagram/sysml_activity_diagram
SysML Sequence Diagramdiagram/sysml_sequence_diagram
ASAM SCDL/Safety Concept Diagramdiagram/scdl_safety_concept_diagram
STAMP/STPA Precondition Tablediagram/stamp_precondition_table
STAMP/STPA Loss Hazard Constraint Tablediagram/stamp_loss_hazard_safety_constraint_table
STAMP/STPA Control Structure Diagramdiagram/stamp_control_structure_diagram
STAMP/STPA UCA Tablediagram/stamp_uca_table
STAMP/STPA Control Loop Diagramdiagram/stamp_control_loop_diagram
STAMP/STPA Loss Scenariodiagram/stamp_hcf_table
STAMP/STPA Countermeasure Tablediagram/stamp_countermeasure_table
GSN/D-CASE GSN Diagramdiagram/gsn_gsn_diagram
Mindmapdiagram/mind_map_diagram
Alignmentalignment
Viewview
Tooltool
STAMP/STPAtool/stamp_and_stpa
Mindmaptool/mindmap
Correct Modeltool/correct_model
System Propertiestool/system_property
Windowwindow
Helphelp
section divider

Astah Plug-in SDK Command-List

CommandHelp
asdk
Show version
astah-generate-project
Generate Plug-in project for Astah Professional, UML and System Safety
astah-sysml-generate-project
Generate Plug-in project for Astah SysML
astah-build
Build plug-in
astah-launch
Launch Astah with dev Plug-ins
astah-debug
Launch Astah and open 44000 for debugging
section divider

Sample snippets

Astah API utilities

Some methods easing your Astah model operation.

/*
 * 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.internal;

import java.util.ArrayList;
import java.util.List;

import com.change_vision.jude.api.inf.exception.InvalidEditingException;
import com.change_vision.jude.api.inf.model.IAttribute;
import com.change_vision.jude.api.inf.model.IClass;
import com.change_vision.jude.api.inf.model.IClassifierTemplateParameter;
import com.change_vision.jude.api.inf.model.IElement;
import com.change_vision.jude.api.inf.model.IGeneralization;
import com.change_vision.jude.api.inf.model.INamedElement;
import com.change_vision.jude.api.inf.model.IOperation;
import com.change_vision.jude.api.inf.model.IPackage;
import com.change_vision.jude.api.inf.model.IParameter;
import com.change_vision.jude.api.inf.model.IRealization;

public class AstahUtils {

  /**
   * Get classes owned by the owner
   *
   * @param  owner   Class or Package
   * @return Classes nesting in the owner
   */
  public static IClass[] getOwnedClasses(Object owner) {
    if (owner instanceof IClass) {
      return ((IClass) owner).getNestedClasses();
    } else if (owner instanceof IPackage) {
      List<IClass> classes = new ArrayList<IClass>();
      for (INamedElement element : ((IPackage) owner).getOwnedElements()) {
        if (element instanceof IClass) {
          classes.add((IClass) element);
        }
      }
      return classes.toArray(new IClass[classes.size()]);
    } else {
      return new IClass[0];
    }
  }

  /**
   * Get a owner's class whose name is specified 
   *
   * @param owner Class or Package
   * @param name  Owner name
   * @return An owner's class whose name is specified
   */
  public static IClass getOwnedClass(Object owner, String name) {
    if (owner instanceof IClass) {
      return getNestedClass((IClass) owner, name);
    } else if (owner instanceof IPackage) {
      return getOwnedElement((IPackage) owner, name, IClass.class);
    } else {
      return null;
    }
  }


  /**
   * Get an INamedElement whose name is specified in the target package
   *
   * @param owner Target package
   * @param name  Name
   * @return a namedElement whose name is specified in the target package
   */
  public static INamedElement getOwnedElement(IPackage owner, String name) {
    return getOwnedElement(owner, name, INamedElement.class);
  }

  /**
   * Get an Object whose name and type are specified in the target package
   *
   * @param owner       Target package
   * @param name        Name
   * @param elementType The child class type of INamedElement
   * @return  the child class type of INamedElement whose name and type are specified in the target package
   */
  public static <T extends INamedElement> T getOwnedElement(IPackage owner,
      String name, Class<T> elementType) {
    for (INamedElement element : owner.getOwnedElements()) {
      if (name.equals(element.getName())) {
        if (elementType.isInstance(element)) {
          return elementType.cast(element);
        }
      }
    }
    return null;
  }

  /**
   * Get a class whose name is specified in the target class
   *
   * @param owner Target class
   * @param name  Name
   * @return a class whose name is specified in the target class
   */
  public static IClass getNestedClass(IClass owner, String name) {
    for (IClass element : owner.getNestedClasses()) {
      if (name.equals(element.getName())) {
        return element;
      }
    }
    return null;
  }

  /**
   * Get a generalization whose parent class is specified
   *
   * @param owner     Target class
   * @param superType Parent class
   * @return Generalization
   *         Null if the superType isn't generalized by the owner
   */
  public static IGeneralization getGeneralization(IClass owner,
      IClass superType) {
    for (IGeneralization generalization : owner.getGeneralizations()) {
      if (superType.equals(generalization.getSuperType())) {
        return generalization;
      }
    }
    return null;
  }

  /**
   * Get a generalization whose child class is specified
   *
   * @param owner   Target class
   * @param subType Child class
   * @return Generalization
   *         Null if the owner isn't generalized by the subType
   */
  public static IGeneralization getSpecialization(IClass owner, IClass subType) {
    for (IGeneralization generalization : owner.getSpecializations()) {
      if (subType.equals(generalization.getSubType())) {
        return generalization;
      }
    }
    return null;
  }

  /**
   * Get a realization whose supplier class is specified
   *
   * @param owner    Target class
   * @param supplier Supplier Class
   *
   * @return Realization
   *         Null if the owner isn't realized by the supplier
   */
  public static IRealization getClientRealization(IClass owner,
      IClass supplier) {
    for (IRealization realization : owner.getClientRealizations()) {
      if (supplier.equals(realization.getSupplier())) {
        return realization;
      }
    }
    return null;
  }

  /**
   * Get a realization whose client class is specified
   *
   * @param owner    Target class
   * @param client   Client Class
   *
   * @return Realization
   *         Null if the client isn't realized by the owner
   */
  public static IRealization getSupplierRealization(IClass owner,
      IClass client) {
    for (IRealization realization : owner.getSupplierRealizations()) {
      if (client.equals(realization.getClient())) {
        return realization;
      }
    }
    return null;
  }


  /**
   * Get a owner's template parameter whose name is specified
   *
   * @param owner  Target class
   * @param name   Parameter Name
   * @return  Template Parameter
   *          Null if the template parameter dosn't exist
   */
  public static IClassifierTemplateParameter getTemplateParameter(
      IClass owner, String name) {
    for (IClassifierTemplateParameter templateParameter : owner
        .getTemplateParameters()) {
      if (name.equals(templateParameter.getName())) {
        return templateParameter;
      }
    }
    return null;
  }

  /**
   * Get a owner's attribute whose name is specified
   *
   * @param owner Target class
   * @param name  Attribute name
   * @return Attribute
   *         Null if the attribute dosn't exist
   */
  public static IAttribute getAttribute(IClass owner, String name) {
    for (IAttribute attribute : owner.getAttributes()) {
      if (name.equals(attribute.getName())) {
        return attribute;
      }
    }
    return null;
  }

  /**
   * Get a owner's operation whose name is specified。
   *
   * @param owner Target class
   * @param name  Operation name
   * @return Operation
   *         Null if the operation dosn't exist
   */
  public static IOperation getOperation(IClass owner, String name,
      Object[] parameterTypes) {
    for (IOperation operation : owner.getOperations()) {
      if (name.equals(operation.getName())) {
        IParameter[] parameters = operation.getParameters();
        if (matches(parameters, parameterTypes)) {
          return operation;
        }
      }
    }
    return null;
  }

  /**
   * set a class as an interface
   *
   * @param type        Target class
   * @param isInterfase True if the class is an interface
   *                    False if the class isn't an interface
   */
  public static void setInterface(IClass type, boolean isInterface)
      throws InvalidEditingException {
    if (isInterface) {
      addStereotype(type, "interface");
    } else {
      type.removeStereotype("interface");
    }
  }

  /**
   * Add a stereotype to an element
   * @param element Target element
   * @param stereotype Added stereotype
   * @return True if the stereotype is added
   *         False if the stereotype has been owned by the element
   */
  public static boolean addStereotype(IElement element, String stereotype)
      throws InvalidEditingException {
    for (String exists : element.getStereotypes()) {
      if (stereotype.equals(exists)) {
        return false;
      }
    }
    element.addStereotype(stereotype);
    return true;
  }

  static boolean matches(IParameter[] parameters, Object[] parameterTypes) {
    if (parameterTypes.length != parameters.length) {
      return false;
    }
    for (int i = 0; i < parameterTypes.length; i++) {
      Object type = parameterTypes[i];
      if (type instanceof IClass) {
        if (!type.equals(parameters[i].getType())) {
          return false;
        }
      } else {
        if (!type.equals(parameters[i].getTypeExpression())) {
          return false;
        }
      }
    }
    return true;
  }

}

Methods for handling Astah API

/*
 * 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.internal;

import javax.swing.JFrame;

import com.change_vision.astah.extension.plugin.util.exception.APIException;
import com.change_vision.jude.api.inf.editor.BasicModelEditor;
import com.change_vision.jude.api.inf.editor.ClassDiagramEditor;
import com.change_vision.jude.api.inf.editor.IDiagramEditorFactory;
import com.change_vision.jude.api.inf.editor.IModelEditorFactory;
import com.change_vision.jude.api.inf.exception.InvalidEditingException;
import com.change_vision.jude.api.inf.exception.InvalidUsingException;
import com.change_vision.jude.api.inf.model.IClassDiagram;
import com.change_vision.jude.api.inf.project.ProjectAccessor;
import com.change_vision.jude.api.inf.project.ProjectAccessorFactory;
import com.change_vision.jude.api.inf.view.IDiagramViewManager;
import com.change_vision.jude.api.inf.view.IViewManager;

/**
 * A class containing utilities easing astah* API operation
 * Instance must be created before this class is used.
 */
public class AstahAPIUtils {

  /**
   * Get diagramViewManager
   */
  public IDiagramViewManager getDiagramViewManager() {
    IViewManager viewManager = getViewManager();
      IDiagramViewManager diagramViewManager = viewManager.getDiagramViewManager();
    return diagramViewManager;
  }


  /**
   * Get ClassDiagramEditor by which models on class diagrams can be modified
   */
  public ClassDiagramEditor getClassDiagramEditor() {
    try {
      return getDiagramEditorFactory().getClassDiagramEditor();
    } catch (InvalidUsingException e) {
      throw new APIException(e);
    }
  }

  /**
   * Get BasicModelEditor by which basic models can be modified
   *
   * @return BasicModelEditor
   */
  public BasicModelEditor getBasicModelEditor() {
    try {
      return getModelEditorFactory().getBasicModelEditor();
    } catch (InvalidEditingException e) {
      throw new APIException(e);
    }
  }

  /**
   * Get ProjectAccessor by which astah* project can be operated
   */
  public ProjectAccessor getProjectAccessor() {
    ProjectAccessor projectAccessor = null;
    try {
      projectAccessor = ProjectAccessorFactory.getProjectAccessor();
    } catch (ClassNotFoundException e) {
          throw new IllegalStateException(e);
    }
    if(projectAccessor == null) throw new IllegalStateException("projectAccessor is null.");
    return projectAccessor;
  }

  /**
   * Get JFrame representing the main window of astah*
   *
   * @return JFrame
   */
  public JFrame getMainFrame() {
    return getProjectAccessor().getViewManager().getMainFrame();
  }

  /**
   * Get the edition of running astah*
   */
  public String getEdition() {
    return getProjectAccessor().getAstahEdition();
  }

  private IViewManager getViewManager() {
    ProjectAccessor projectAccessor = getProjectAccessor();
    IViewManager viewManager = projectAccessor.getViewManager();
    if(viewManager == null) throw new IllegalStateException("ViewManager is null.");
    return viewManager;
  }

  private IModelEditorFactory getModelEditorFactory() {
    ProjectAccessor projectAccessor = getProjectAccessor();
    IModelEditorFactory modelEditorFactory = projectAccessor.getModelEditorFactory();
    if(modelEditorFactory == null) throw new IllegalStateException("modelEditorFactory is null.");
    return modelEditorFactory;
  }

  private IDiagramEditorFactory getDiagramEditorFactory() {
    ProjectAccessor projectAccessor = getProjectAccessor();
    IDiagramEditorFactory diagramEditorFactory = projectAccessor.getDiagramEditorFactory();
    if(diagramEditorFactory == null) throw new IllegalStateException("diagramEditorFactory is null.");
    return diagramEditorFactory;
  }

}

How to create a menu

An example of plugin.xml

<?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.TemplateAction"
               tooltip="%menu_tooltip"
               menubarPath="tool/helloworld/"
               id="com.example.actions.HelloWorldAction">
         </action>
     </actionSet>
   </extension>
</plugin>

An example of action

/*
 * 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;
  }
}

How to create an extra view view

An example of plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <extension point="com.change_vision.astah.ui.view">
        <view
            id="com.example.internal.HelloWorldView"
            type="extraTab"
            class="com.example.internal.HelloWorldView" />
   </extension>
</plugin>

An example of the view

/*
 * 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.internal;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.change_vision.jude.api.inf.project.ProjectAccessor;
import com.change_vision.jude.api.inf.project.ProjectAccessorFactory;
import com.change_vision.jude.api.inf.project.ProjectEvent;
import com.change_vision.jude.api.inf.project.ProjectEventListener;
import com.change_vision.jude.api.inf.ui.IPluginExtraTabView;
import com.change_vision.jude.api.inf.ui.ISelectionListener;

public class HelloWorldView extends JPanel implements IPluginExtraTabView, ProjectEventListener {

    public HelloWorldView() {
        initComponents();
    }

    private void initComponents() {
        setLayout(new BorderLayout());
        add(createLabelPane(), BorderLayout.CENTER);
        addProjectEventListener();
    }

  private void addProjectEventListener() {
    try {
      ProjectAccessor projectAccessor = ProjectAccessorFactory.getProjectAccessor();
      projectAccessor.addProjectEventListener(this);
    } catch (ClassNotFoundException e) {
      e.getMessage();
    }
  }

  private Container createLabelPane() {
      JLabel label = new JLabel("hello world");
        JScrollPane pane = new JScrollPane(label);
        return pane;
    }

    @Override
    public void projectChanged(ProjectEvent e) {
    }

    @Override
    public void projectClosed(ProjectEvent e) {
    }

     @Override
    public void projectOpened(ProjectEvent e) {
    }

  @Override
  public void addSelectionListener(ISelectionListener listener) {
  }

  @Override
  public Component getComponent() {
    return this;
  }

  @Override
  public String getDescription() {
    return "Show Hello World here";
  }

  @Override
  public String getTitle() {
    return "Hello World View";
  }

  public void activated() {

  }

  public void deactivated() {

  }
}

How to extend Drag and Drop

Please get detailed snippets with the com.change_vision.astah.extension.plugin.drag_and_drop_example project. To add DropTargetListener during the initialization of a plugin, Activator#start(BundleContext context) should be implemented.

package com.example;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import com.example.internal.ClassDiagramDropExtension;
import com.example.internal.util.AstahAPIUtils;
import com.change_vision.jude.api.inf.view.IDiagramViewManager;

public class Activator implements BundleActivator {

  private AstahAPIUtils utils = new AstahAPIUtils();

  public void start(BundleContext context) {
    ClassDiagramDropExtension diagramDropTargetListener = new ClassDiagramDropExtension();
    IDiagramViewManager diagramViewManager = utils.getDiagramViewManager();
    diagramViewManager.addDropTargetListener(diagramDropTargetListener);

  }

  public void stop(BundleContext context) {
  }

}

An example showing how to implement DropTargetListener

/*
 * 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.internal;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.change_vision.jude.api.inf.model.IClassDiagram;
import com.change_vision.jude.api.inf.view.DiagramDropTargetListener;

public final class ClassDiagramDropExtension extends DiagramDropTargetListener {

  public ClassDiagramDropExtension() {
    super(IClassDiagram.class);
  }

  @Override
  public void dropExternalData(DropTargetDropEvent dtde) {
    if(dtde.isLocalTransfer()) return;

    if(dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      System.out.println("ClassDiagramDropExtension.stringFlavor" + getURLStringFromDropContent(dtde));
      dtde.dropComplete(true);
    } else if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      List<File> files = getFilesFromDropContent(dtde);
      System.out.println("javaFileListFravor" + files);
      dtde.dropComplete(true);
    }
  }

  private String getURLStringFromDropContent(DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_LINK);
    Transferable target = dtde.getTransferable();

    String urlString;
    try {
      urlString = (String)target.getTransferData(DataFlavor.stringFlavor);
    } catch (Exception e) {
      urlString = "";
    }
    return urlString;
  }

  @SuppressWarnings("unchecked")
  private List<File> getFilesFromDropContent(DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY);
    List<File> list;
    try {
      list = (List<File>) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
    } catch (Exception e) {
      list = new ArrayList<File>();
    }
    return list;
  }

  @Override
  public void dropModels(DropTargetDropEvent dtde, Set<?> models) {
  }

  @Override
  public void dragEnter(DropTargetDragEvent dtde) {
  }

  @Override
  public void dragExit(DropTargetEvent dte) {
  }

  @Override
  public void dragOver(DropTargetDragEvent dtde) {
  }

  @Override
  public void dropActionChanged(DropTargetDragEvent dtde) {
  }
}