# astah* API User Guide

## [Creating/Deleting Presentation]

1. How to create presentations

- How to create common elements presentations

- How to create presentations in Class Diagram

- How to create presentations in UseCase Diagram

- How to create presentations in Statemachine Diagram

- How to create presentations in Activity Diagram

- How to create presentations in Sequence Diagram

- How to create presentations in Composite Structure Diagram

- How to create presentations in ER Diagram

- How to create presentations in Mind Map

- How to create presentations in Requirement Diagram

2. How to delete presentations

Please refer to astah* API JavaDoc for each interface and method.
Creating/Deleting presentation are supported in astah* UML and professional. (ER Diagram is supported in astah* professional only.)

#### [Transaction Operation]

Transaction Operation is required when creating/editing/deleting presentations.
Please read Transaction operation when creating/modifying/deleting models/diagrams/presentation.

#### [How to create presentations]

1. Obtain models (IElement).
2. Start Transaction.
3. Specify a diagram by using setDiagram method of each DiagramEditor.
4. Set the model to createXXXmethod of each DiagramEditor and create a presentation(IPresentation).

Class Diagram/Object Diagram | ClassDiagramEditor
UseCase Diagram | UseCaseDiagramEditor
Statemachine Diagram | StateMachineDiagramEditor
Activity Diagram | ActivityDiagramEditor
Sequence Diagram | SequenceDiagramEditor
Composite Structure Diagram | CompositeStructureDiagramEditor
ER Diagram | ERDiagramEditor
Mind Map | MindmapEditor
Requirement Diagram | RequirementDiagramEditor

5. End the transaction
6. Save a project if necessary

#### [How to create presentations]

Sample 1: Create a Note Presentation with text in specified diagram and location

        public INodePresentation createNotePresentation(IDiagram dgm, String note, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            ClassDiagramEditor cde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getClassDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                cde.setDiagram(dgm);
                //create presentation
                ps = cde.createNote(note, location);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 2: Create a Noteanchor presentation between Note presentation and an object presentation and note

        public ILinkPresentation createNoteAnchorPresentation(IDiagram dgm, INodePresentation note, IPresentation annotatedElement) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            ILinkPresentation ps = null;
            ClassDiagramEditor cde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getClassDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                cde.setDiagram(dgm);
                //create presentation
                ps = cde.createNoteAnchor(note, annotatedElement);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

#### [How to create common elements presentations]

Sample 1: Create a Class presentation in specified diagram and location

        public INodePresentation createClassPresentation(IDiagram dgm, IClass iClass, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            ClassDiagramEditor cde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getClassDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                cde.setDiagram(dgm);
                //create presentation
                ps = cde.createNodePresentation(iClass, location);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 2: Create a Class under the project and create a Class presentation in specified diagram and location

        public INodePresentation createClassModelAndPresentation(IDiagram dgm, String className, Point2D location)
                throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            BasicModelEditor bme = AstahAPI.getAstahAPI().getProjectAccessor().getModelEditorFactory().getBasicModelEditor();
            ClassDiagramEditor cde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getClassDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //create model
                IClass iClass = bme.createClass(project, className);
                //set diagram
                cde.setDiagram(dgm);
                //create presentation
                ps = cde.createNodePresentation(iClass, location);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 3: Create an Association presentation between Class presentations

        public ILinkPresentation createAssociationPresentation(IDiagram dgm, IAssociation iAssociation, INodePresentation sourcePs, INodePresentation targetPs) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            ILinkPresentation ps = null;
            ClassDiagramEditor cde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getClassDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                cde.setDiagram(dgm);
                //create presentation
                ps = cde.createLinkPresentation(iAssociation, sourcePs, targetPs);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

#### [How to create presentations in UseCase Diagram]

Sample 1: Create an UseCase presentation in specified diagram and location

        public INodePresentation createUseCasePresentation(IDiagram dgm, IUseCase iUseCase, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            UseCaseDiagramEditor cde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getUseCaseDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                cde.setDiagram(dgm);
                //create presentation
                ps = cde.createNodePresentation(iUseCase, location);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 2: Create an Extend presentation between a source UseCase presentation and a target UseCase presentation

        public ILinkPresentation createExtendPresentation(IDiagram dgm, IExtend iExtend, INodePresentation sourcePs, INodePresentation targetPs) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            ILinkPresentation ps = null;
            UseCaseDiagramEditor cde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getUseCaseDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                cde.setDiagram(dgm);
                //create presentation
                ps = cde.createLinkPresentation(iExtend, sourcePs, targetPs);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

#### [How to create presentations in Statemachine Diagram]

Sample 1: Create a State presentation in specified diagram and location with name and its parent presentation

        public INodePresentation createStatePresentation(IDiagram dgm, String stateName, INodePresentation parent, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            StateMachineDiagramEditor ste = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getStateMachineDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                ste.setDiagram(dgm);
                //create presentation
                ps = ste.createState(stateName, parent, location);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 2: Create a Transition presentation between source IVertex presentation and target IVertax presentation in specified diagram

        public ILinkPresentation createTransitionPresentation(IDiagram dgm, INodePresentation sourcePs, INodePresentation targetPs) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            ILinkPresentation ps = null;
            StateMachineDiagramEditor ste = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getStateMachineDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                ste.setDiagram(dgm);
                //create presentation
                ps = ste.createTransition(sourcePs, targetPs);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

#### [How to create presentations in Activity Diagram]

Sample 1: Create a Action presentation in specified diagram and name and location

        public INodePresentation createActionPresentation(IDiagram dgm, String name, Point2D location) throws ClassNotFoundException, InvalidUsingException {
            INodePresentation ps = null;
            ActivityDiagramEditor ade = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getActivityDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                // set diagram
                ade.setDiagram(dgm);
                // create presentation
                ps = ade.createAction(name, location);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

#### [How to create presentations in Sequence Diagram]

Sample 1: Create a Lifeline presentation in specified diagram and name and location X

        public INodePresentation createLifelinePresentation(IDiagram dgm, String name, double locX) throws ClassNotFoundException, InvalidUsingException {
            INodePresentation ps = null;
            SequenceDiagramEditor sde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getSequenceDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                // set diagram
                sde.setDiagram(dgm);
                // create presentation
                ps = sde.createLifeline(name, locX);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 2: Create a Combined Fragment presentation in specified diagram and name and interaction operator and location and width and height

        public INodePresentation createCombinedFragmentPresentation(IDiagram dgm, String name, String interactionOperator, Point2D location, double width, double height)
                throws ClassNotFoundException, InvalidUsingException {
            INodePresentation ps = null;
            SequenceDiagramEditor sde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getSequenceDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                // set diagram
                sde.setDiagram(dgm);
                // create presentation
                ps = sde.createCombinedFragment(name, interactionOperator, location, width, height);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

#### [How to create presentations in Composite Structure Diagram]

Sample 1: Create a Structured Class presentation in specified diagram and location

        public INodePresentation createClassPresentation(IDiagram dgm, IClass iClass, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            CompositeStructureDiagramEditor cse = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getCompositeStructureDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                cse.setDiagram(dgm);
                //create presentation
                ps = cse.createStructuredClassPresentation(iClass, location);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 2: Create a Part presentation in specified Structured Class.

        public INodePresentation createPartPresentation(IDiagram dgm, IClass parentClass, IClass partBaseClass, INodePresentation parentClassPresentation, String partName, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            BasicModelEditor bme = ModelEditorFactory.getBasicModelEditor();
            CompositeStructureDiagramEditor cse = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getCompositeStructureDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                IAssociation asso = bme.createAssociation(parentClass, partBaseClass, "", "", partName);
                IAttribute[] memberEnds = asso.getMemberEnds();
                memberEnds[0].setComposite();

                //set diagram
                cse.setDiagram(dgm);
                //create presentation
                ps = cde.createNodePresentation(memberEnds[1], parentClassPresentation, location);

                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 3: Create a External Part presentation in specified Structured Class.

        public INodePresentation createExternalPartPresentation(IDiagram dgm, IClass partBaseClass, INodePresentation parentClassPresentation, IClass externalPartBaseClass, IAttribute part1, String externalPartName, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            BasicModelEditor bme = ModelEditorFactory.getBasicModelEditor();
            CompositeStructureDiagramEditor cse = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getCompositeStructureDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                IAssociation asso = bme.createAssociation(partBaseClass, externalPartBaseClass, "", "", externalPartName);
                IAttribute[] memberEnds = asso.getMemberEnds();
                IConnector connector = csme.createConnector(part1, null, memberEnds[1], null);

                //set diagram
                cse.setDiagram(dgm);
                //create presentation
                ps = cde.createNodePresentation(memberEnds[1], parentClassPresentation, location);

                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 4: Create a Port presentation in specified Structured Class presentation or Part presentation.

        public INodePresentation createPortPresentation(IDiagram dgm, INodePresentation parentNode) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            CompositeStructureDiagramEditor cse = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getCompositeStructureDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                cse.setDiagram(dgm);
                //create presentation
                ps = cse.createPortPresentation(parentNode);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

#### [How to create presentations in ER Diagram]

Sample 1: Create an ER Entity presentation in specified diagram and location

        public INodePresentation createEREntityPresentation(IDiagram dgm, IEREntity iEREntity, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            ERDiagramEditor ede = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getERDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                ede.setDiagram(dgm);
                //create presentation
                ps = ede.createNodePresentation(iEREntity, location);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 2: Create an ER relationship presentation

        public ILinkPresentation createERRelationshipPresentation(IDiagram dgm, IERRelationship iERRelationship, INodePresentation sourcePs, INodePresentation targetPs) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            ILinkPresentation ps = null;
            ERDiagramEditor ede = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getERDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                ede.setDiagram(dgm);
                //create presentation
                ps = ede.createLinkPresentation(iERRelationship, sourcePs, targetPs);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

#### [How to create presentations in Mind Map]

Sample 1: Create a topic presentation with its name under the root topic in specified Mind Map

        public INodePresentation createTopicPresentation(IMindMapDiagram dgm, String topicName)
                throws InvalidUsingException, ClassNotFoundException {
            INodePresentation ps = null;
           	MindmapEditor mme = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getMindmapEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                mme.setDiagram(dgm);
                INodePresentation iRootTopic = dgm.getRoot();
                //create presentation
                ps = mme.addChild(iRootTopic, topicName);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

Sample 2: Create a Topic line between topics

        public ILinkPresentation createMMLinkPresentation(IDiagram dgm, INodePresentation sourcePs, INodePresentation targetPs)
                throws ClassNotFoundException, InvalidUsingException {
            ILinkPresentation ps = null;
           	MindmapEditor mme = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getMindmapEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                mme.setDiagram(dgm);
                //create presentation
                ps = mme.createMMLinkPresentation(sourcePs, targetPs);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

#### [How to create presentations in Requirement Diagram]

Sample 1:Create a Requirement presentation in specified diagram and location

        public INodePresentation createRequirementPresentation(IDiagram dgm, IRequirement iRequirement, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
            INodePresentation ps = null;
            RequirementDiagramEditor rde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getRequirementDiagramEditor();
            try {
                TransactionManager.beginTransaction();
                //set diagram
                rde.setDiagram(dgm);
                //create presentation
                ps = rde.createNodePresentation(iRequirement, location);
                TransactionManager.endTransaction();
            } catch (InvalidEditingException e) {
                e.printStackTrace();
                TransactionManager.abortTransaction();
            }
            return ps;
        }

#### [How to delete presentations]

1. Obtain presentation(IPresentation).
2. Start a Transaction operation.
3. Set a diagram by using setDiagram method of its DiagramEditor.
4. Set a presentation to deletePresentation method of its DiagramEditor and delete it(IPresentation).
5. End the transaction.
6. Save a project if necessary.
Sample : Deleting a diagram

    	private void deletePresentation(IDiagram diagram, IPresentation ps) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
    		ERDiagramEditor editor = DiagramEditorFactory.getERDiagramEditor();
    		try {
    			TransactionManager.beginTransaction();
    			editor.setDiagram(diagram);
    			editor.deletePresentation(ps);
    			TransactionManager.endTransaction();
    		} catch (InvalidEditingException e) {
    			e.printStackTrace();
    			TransactionManager.abortTransaction();
    		}
    	}

HOME