This page shows you how to create diagram presentations by using Astah SysML API.

section divider

DiagramEditor

Use DiagramEditor to create diagrams and diagram presentations.

DiagramEditor nameCreate method
Block Definition Diagram InterfaceBlockDefinitionDiagramEditorcreateBlockDefinitionDiagram
Internal Block Diagram InterfaceInternalBlockDiagramEditorcreateInternalBlockDiagram
Parametric Diagram InterfaceParametricDiagramEditorcreateParametricDiagram
UseCase Diagram InterfaceUseCaseDiagramEditorcreateUseCaseDiagram
Requirement Diagram InterfaceRequirementDiagramEditorcreateRequirementDiagram
Statemachine Diagram Interface StateMachineDiagramEditorcreateStateMachineDiagram
Sequence Diagram InterfaceSequenceDiagramEditorcreateSequenceDiagram
Activity Diagram InterfaceActivityDiagramEditorcreateActivityDiagram
Mind Map InterfaceMindmapEditorcreateMindmap
section divider

Transaction process

Transaction processing is required when creating/editing/deleting diagrams.
Please refer to the Transaction Process.

section divider

Sample Code

Creating diagrams

Sample Code: Creating a Block Definition Diagram

public IDiagram createBlockDefinitionDiagram(IModel project, String diagramName) 
        throws InvalidUsingException, ClassNotFoundException {
    ProjectAccessor projectAccessor =  AstahAPI.getAstahAPI().getProjectAccessor();
    BlockDefinitionDiagramEditor bdde = projectAccessor.getDiagramEditorFactory().getBlockDefinitionDiagramEditor();
    try {
        TransactionManager.beginTransaction();
        IDiagram iBlockDefinitionDiagram = bdde.createBlockDefinitionDiagram(project, diagramName);
        TransactionManager.endTransaction();
        return iBlockDefinitionDiagram;
    } catch (InvalidEditingException e) {
        e.printStackTrace();
        TransactionManager.abortTransaction();
    }
}

Deleting diagrams

Sample Code A: Deleting diagram

public void deleteDiagram(IDiagram diagram) 
        throws ClassNotFoundException, InvalidUsingException {
    ProjectAccessor projectAccessor =  AstahAPI.getAstahAPI().getProjectAccessor();
    BlockDefinitionDiagramEditor bdde = projectAccessor.getDiagramEditorFactory().getBlockDefinitionDiagramEditor();
    try {
        TransactionManager.beginTransaction();
        bdde.setDiagram(diagram);
        bdde.deleteDiagram();
        TransactionManager.endTransaction();
    } catch (InvalidEditingException e) {
        e.printStackTrace();
        TransactionManager.abortTransaction();
    }
}

Sample Code B: Deleting diagram

public void deleteDiagram(IDiagram diagram) 
        throws ClassNotFoundException, InvalidUsingException {
    ProjectAccessor projectAccessor =  AstahAPI.getAstahAPI().getProjectAccessor();
    BlockDefinitionDiagramEditor bdde = projectAccessor.getDiagramEditorFactory().getBlockDefinitionDiagramEditor();
    try {
        TransactionManager.beginTransaction();
        bdde.delete(diagram);
        TransactionManager.endTransaction();
    } catch (InvalidEditingException e) {
        e.printStackTrace();
        TransactionManager.abortTransaction();
    }
}