This page shows you how to create presentations using Astah SysML API.
To see a difference between presentations and models, please read this page.

When you create and edit presentations, you need the transaction process first.

section divider

How to use DiagramEditor

The target diagram must be set to DiagramEditor when editing/deleting diagrams or presentations.

   try {
       TransactionManager.beginTransaction();
       IBlockDefinitionDiagram blockDefinitionDiagram0 = editor.createBlockDefinitionDiagram(project, "blockDefinitionDiagram0");
       BlockDefinitionDiagramEditor editor = diagramEditorFactory.getBlockDefinitionDiagramEditor();
       //set the target diagram before calling diagramEditor
       editor.setDiagram(blockDefinitionDiagram0);
       
       SysmlModelEditor bme = AstahAPI.getAstahAPI().getProjectAccessor().getModelEditorFactory().getSysmlModelEditor();
       IBlock iBlock = bme.createBlock(project, "Block1_for_delete");
       //Create a block presentation on blockDefinitionDiagram0
       INodePresentation blockPs = editor.createNodePresentation(iBlock, new Point2D.Double(10.0, 10.0));  
            
       TransactionManager.endTransaction();
   } catch (InvalidEditingException e) {
      TransactionManager.abortTransaction();
      fail();
   }

If a diagram is created by using DiagramEditor, the diagram will be set to the DiagramEditor automatically.

					
	UseCaseModelEditor me = AstahAPI.getAstahAPI().getProjectAccessor().getModelEditorFactory().getUseCaseModelEditor();
    	SysmlModelEditor bme = AstahAPI.getAstahAPI().getProjectAccessor().getModelEditorFactory().getSysmlModelEditor();
    	BlockDefinitionDiagramEditor de = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getBlockDefinitionDiagramEditor();
        try {
            TransactionManager.beginTransaction();            
            IUseCase iUseCase = me.createUseCase(project, "UseCase0");
            assertNotNull(iUseCase);
            //Create a blockDefinitionDiagram under created usecase
            de.createBlockDefinitionDiagram(iUseCase, "Block Definition diagram2");
            
            IBlock iBlock = bme.createBlock(project, "Block1_for_delete");
            //Create a block presentation on created blockDefinitionDiagram
            //The blockDefinitionDiagram created by BlockDefinitionDiagramEditor has been set automatically.
            INodePresentation blockPs = de.createNodePresentation(iBlock, new Point2D.Double(10.0, 10.0));   
            
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            TransactionManager.abortTransaction();
        }
section divider

Create common elements presentations

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

    public INodePresentation createNotePresentation(IDiagram dgm, String note, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation ps = null;
        BlockDefinitionDiagramEditor bdde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getBlockDefinitionDiagramEditor();
        try {
            TransactionManager.beginTransaction();
            //set diagram
            bdde.setDiagram(dgm);
            //create presentation
            ps = bdde.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;
        BlockDefinitionDiagramEditor bdde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getBlockDefinitionDiagramEditor();
        try {
            TransactionManager.beginTransaction();
            //set diagram
            bdde.setDiagram(dgm);
            //create presentation
            ps = bdde.createNoteAnchor(note, annotatedElement);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return ps;
    }
section divider

Create a Block Definition Diagram

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

    public INodePresentation createBlockPresentation(IDiagram dgm, IBlock iBlock, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation ps = null;
        BlockDefinitionDiagramEditor bdde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getBlockDefinitionDiagramEditor();
        try {
            TransactionManager.beginTransaction();
            //set diagram
            bdde.setDiagram(dgm);
            //create presentation
            ps = bdde.createNodePresentation(iBlock, location);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return ps;
    }

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

    public INodePresentation createBlockModelAndPresentation(IDiagram dgm, String blockName, Point2D location)
            throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation ps = null;
        SysmlModelEditor bme = AstahAPI.getAstahAPI().getProjectAccessor().getModelEditorFactory().getSysmlModelEditor();
        BlockDefinitionDiagramEditor bdde = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getBlockDefinitionDiagramEditor();
        try {
            TransactionManager.beginTransaction();
            //create model
            IBlock iBlock = bme.createBlock(project, blockName);
            //set diagram
            bdde.setDiagram(dgm);
            //create presentation
            ps = bdde.createNodePresentation(iBlock, location);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return ps;
    }

Sample 3: Create an Association presentation between Block presentations

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

Create a Parametric Diagram

Sample 1: Create a constraint property presentation in specified diagram and location

    public INodePresentation createConstraintPropertyPresentation(IConstraintBlock parent, IConstraintBlock type, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation ps = null;
        SysmlModelEditor bme = ModelEditorFactory.getSysmlModelEditor();
        try {
            TransactionManager.beginTransaction();
            
            ParametricDiagramEditor parametricDiagramEditor = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getParametricDiagramEditor();
            IParametricDiagram createParametricDiagram = parametricDiagramEditor.createParametricDiagram(parent, "parametricDiagram");

            //create presentation
            IConstraintProperty constraintProp = bme.createConstraintProperty(parent, "constraintProperty", type);
            ps = parametricDiagramEditor.createNodePresentation(constraintProp, location);
            
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return ps;
    }

Sample 2: Create a constraint parameter in a specified constraint property

    public INodePresentation createConstraintParameterPresentation(IConstraintBlock parent, IConstraintBlock type, IValueType valueType, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation ps = null;
        SysmlModelEditor bme = ModelEditorFactory.getSysmlModelEditor();
        try {
            TransactionManager.beginTransaction();
            
            ParametricDiagramEditor parametricDiagramEditor = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getParametricDiagramEditor();
            IParametricDiagram createParametricDiagram = parametricDiagramEditor.createParametricDiagram(parent, "parametricDiagram");

            //create presentation
            IConstraintProperty constraintProp = bme.createConstraintProperty(parent, "constraintProperty", type);
            INodePresentation constraintPropPs= parametricDiagramEditor.createNodePresentation(constraintProp, location);
            IConstraintParameter constraintParameter = bme.createConstraintParameter(type, "constraintProperty0_constraintParameter", valueType);
            ps = (INodePresentation)constraintParameter.getPresentations()[0];
            
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return ps;
    }
section divider

Create an Internal Block Diagram

Sample 1: Create a Part presentation

    public INodePresentation createPartPresentation(IBlock parent, String partName, IBlock type) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation ps = null;
        SysmlModelEditor sme = ModelEditorFactory.getSysmlModelEditor();
        InternalBlockDiagramEditor de = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getInternalBlockDiagramEditor();
        try {
            TransactionManager.beginTransaction();
            IInternalBlockDiagram dgm = de.createInternalBlockDiagram(parent, "dgm0");
            
            //create presentation
            IAttribute part = sme.createPart(parent, partName, type);
            INodePresentation partPs = de.createNodePresentation(part, new Point2D.Double(10.0,	10.0));
            
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return ps;
    }

Sample 2: Create an External Part presentation

     public INodePresentation createExternalPartPresentation(IBlock parent, String partName, IBlock type) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation ps = null;
        SysmlModelEditor sme = ModelEditorFactory.getSysmlModelEditor();
        InternalBlockDiagramEditor de = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getInternalBlockDiagramEditor();
        try {
            TransactionManager.beginTransaction();
            IInternalBlockDiagram dgm = de.createInternalBlockDiagram(parent, "dgm0");
            
            //create presentation
            IAttribute part = sme.createReference(parent, partName, type);
            INodePresentation partPs = de.createNodePresentation(part, new Point2D.Double(10.0,	10.0));
            
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return ps;
    }

Sample 3: Create a Port presentation in owner block presentation or Part presentation

    public INodePresentation createPortPresentation() throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation portPs = null;
        SysmlModelEditor sme = ModelEditorFactory.getSysmlModelEditor();
        InternalBlockDiagramEditor de = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getInternalBlockDiagramEditor();
        IModel project = prjAccessor.getProject();
        try {
            TransactionManager.beginTransaction();
            
            IBlock block0 = bme.createBlock(project, "Block0");
            IBlock block1 = bme.createBlock(project, "Block1");

            IInternalBlockDiagram dgm = de.createInternalBlockDiagram(block0, "dgm0");
            IAttribute part0 = bme.createPart(block0, "part0", block1);
            IPort port1 = bme.createPort(block1, "port1");

            INodePresentation partPs = de.createNodePresentation(part0, new Point2D.Double(10.0, 10.0));
            INodePresentation portPs = de.createNodePresentation(port1, partPs, new Point2D.Double(10.0, 10.0));
            
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return portPs;
    }
section divider

Create a 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;
    }
section divider
section divider

Create a 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 the 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;
    }
section divider

Sequence Diagram

Sample 1: Create a lifeline presentation in specified diagram and location with the name

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

Sample 2: Create a message presentation between lifeline presentations in specified diagram

    public ILinkPresentation createMessagePresentation(IDiagram dgm, String messageName, INodePresentation sender, INodePresentation receiver, double locY) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        ILinkPresentation ps = null;
        SequenceDiagramEditor editor = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getSequenceDiagramEditor();
        try {
            TransactionManager.beginTransaction();
            //set diagram
            editor.setDiagram(dgm);
            //create presentation
            ps = editor.createCreateMessage(messageName, sender, receiver, locY);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return ps;
    }
section divider

Create an Activity Diagram

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

    public INodePresentation createPartitionPresentation(INodePresentation superPartition, INodePresentation previousPartition, String partitionName, boolean isHorizontal) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation ps = null;
        ActivityDiagramEditor editor = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getActivityDiagramEditor();
        IModel owner = AstahAPI.getAstahAPI().getProjectAccessor().getProject();
        try {
            TransactionManager.beginTransaction();
            IActivityDiagram activityDgm = editor.createActivityDiagram(owner, "activity diagram");
            //set diagram
            editor.setDiagram(activityDgm);
            //create presentation
            ps =  editor.createPartition(superPartition, previousPartition, partitionName, isHorizontal);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return ps;
    }

Sample 2: Create an action presentation in a partition presentation

    public INodePresentation createActionPresentation(String actionName) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation ps = null;
        ActivityDiagramEditor editor = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getActivityDiagramEditor();
        IModel owner = AstahAPI.getAstahAPI().getProjectAccessor().getProject();
        try {
            TransactionManager.beginTransaction();
            IActivityDiagram activityDgm = editor.createActivityDiagram(owner, "activity diagram");
            //set diagram
            editor.setDiagram(activityDgm);
            //create presentation
            INodePresentation partitionPs =  editor.createPartition(null, null, "partition0", false);
            ps = editor.createAction(actionName, new Point2D.Double(partitionPs.getRectangle().getCenterX() + 10,partitionPs.getRectangle().getCenterY() + 10));
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return ps;
    }

Sample 3: Create a pin presentation on an action presentation

    public INodePresentation createPinPresentation(String name, IClass base, boolean isInput, Point2D location) throws ClassNotFoundException, InvalidEditingException, InvalidUsingException {
        INodePresentation pinPs = null;
        ActivityDiagramEditor editor = AstahAPI.getAstahAPI().getProjectAccessor().getDiagramEditorFactory().getActivityDiagramEditor();
        IModel owner = AstahAPI.getAstahAPI().getProjectAccessor().getProject();
        try {
            TransactionManager.beginTransaction();
            IActivityDiagram activityDgm = editor.createActivityDiagram(owner, "activity diagram");
            //set diagram
            editor.setDiagram(activityDgm);
            //create presentation
            INodePresentation partitionPs =  editor.createPartition(null, null, "partition0", false);
            INodePresentation actionPs = editor.createAction(actionName, new Point2D.Double(partitionPs.getRectangle().getCenterX() + 10,partitionPs.getRectangle().getCenterY() + 10));
            pinPs = editor.createPin(name, base, isInput, actionPs, location);
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            e.printStackTrace();
            TransactionManager.abortTransaction();
        }
        return pinPs;
    }
section divider

Create a 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;
    }
section divider

Create a Requirement Diagram

Sample: 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;
    }