# astah* API User Guide

## [Creating/Deleting diagrams]

1. Creating Diagrams
2. Deleting Diagrams

Please refer to astah* API JavaDoc for details of each Interface and method.
Creating/editing/Deleting diagrams are supported in astah* UML and professional.

#### [Transaction operation]

Transaction operation is required when creating/editing/deleting diagrams.
Please refer to Transaction Operations.

#### [Creating diagrams]

- Class Diagram/Object Diagram : Use createClassDiagram method of ClassDiagramEditor
- UseCase Diagram : Use createUseCaseDiagram method of UseCaseDiagramEditor
- Statemachine Diagram : Use createStatemachineDiagram method of StateMachineDiagramEditor
- Activity Diagram : Use createActivityDiagram method of ActivityDiagramEditor
- Sequence Diagram : Use createSequenceDiagram method of SequenceDiagramEditor
- Composite Structure Diagram : Use createCompositeStructureDiagram method of CompositeStructureDiagramEditor
- ER Diagram (professional only) : Use createERDiagram method of ERDiagramEditor
- Mind Map : Use createMindmapDiagram method of MindmapEditor
- Requirement Diagram : Use createRequirementDiagram method of RequirementDiagramEditor

Sample Code: Creating Class Diagram/Object Diagram

    public IDiagram createClassDiagram(IModel project, String diagramName)
            throws InvalidUsingException, ClassNotFoundException {
        ProjectAccessor projectAccessor =  AstahAPI.getAstahAPI().getProjectAccessor();
        ClassDiagramEditor cde = projectAccessor.getDiagramEditorFactory().getClassDiagramEditor();
        try {
            TransactionManager.beginTransaction();
            IDiagram iClassDiagram = cde.createClassDiagram(project, diagramName);
            TransactionManager.endTransaction();
            return iClassDiagram;
        } 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();
        ClassDiagramEditor cde = projectAccessor.getDiagramEditorFactory().getClassDiagramEditor();
        try {
            TransactionManager.beginTransaction();
            cde.setDiagram(diagram);
            cde.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();
        ClassDiagramEditor cde = projectAccessor.getDiagramEditorFactory().getClassDiagramEditor();
        try {
            TransactionManager.beginTransaction();
            cde.delete(diagram);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
    }

HOME