astah* API User Guide


[Creating/Deleting Presentation]

  1. How to create presentations
  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
ER Diagram ERDiagramEditor
Mind Map MindmapEditor
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 = ProjectAccessorFactory.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 = ProjectAccessorFactory.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 = ProjectAccessorFactory.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 = ProjectAccessorFactory.getProjectAccessor().getModelEditorFactory().getBasicModelEditor();
        ClassDiagramEditor cde = ProjectAccessorFactory.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 = ProjectAccessorFactory.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 = ProjectAccessorFactory.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 = ProjectAccessorFactory.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 = ProjectAccessorFactory.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 = ProjectAccessorFactory.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 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 = ProjectAccessorFactory.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 = ProjectAccessorFactory.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 = ProjectAccessorFactory.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 = ProjectAccessorFactory.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 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