Create Timing Diagram using Open API

tomcat-thumbTiming diagram in Unified Modeling Language (UML) is a kind of interaction diagram. It is a special form of sequence diagram and focus on the time constraints of the interactions between objects. Instead of manually create the timing diagram, you can also generate it via Visual Paradigm’s Open API. In this article we will show you how to create timing diagram with Open API.

Timing diagram which we are going to create via Open API

Timing diagram which we are going to create via Open API

This is the timing diagram we are going to create. It consist of 2 lifelines, 5 states, 3 timing message and a duration constraint.

Create Blank Timing Diagram

Let’s start by create a blank diagram. We can use the DiagramManager.createDiagram operation to create a blank new diagram.

// create blank timing diagram
DiagramManager diagramManager = ApplicationManager.instance().getDiagramManager();
ITimingDiagramUIModel diagram = (ITimingDiagramUIModel) diagramManager.createDiagram(IDiagramTypeConstants.DIAGRAM_TYPE_TIMING_DIAGRAM);

Create Timing Frame and Time Unit

Once the diagram is created we can then start on create the timing frame. To create the frame:

// create a timing frame model
ITimingFrame frame = IModelElementFactory.instance().createTimingFrame();
frame.setName("sd UserAccepted");
// create a timing frame shape
ITimingFrameUIModel frameShape = (ITimingFrameUIModel) diagramManager.createDiagramElement(diagram, frame);
frameShape.setBounds(100, 100, 450, 370);
Create timing frame

Create timing frame

After the frame being created we can then create time unit on the frame.

// create an array to store all the time units
ITimeUnit[] timeUnits = new ITimeUnit[16];
// create 16 time units on the timing frame
for (int i = 0; i <= 15; i++) {
  ITimeUnit timeUnit = IModelElementFactory.instance().createTimeUnit();
  timeUnits[i] = timeUnit;
Create time unit

Create time unit

Create Lifeline and States in Timing Frame

After create the frame we can create lifeline and states in the frame. To create lifeline:

// create the first lifeline in the timing frame
ILifeLine lifelineUser = IModelElementFactory.instance().createLifeLine();
Create lifeline

Create lifeline

After create lifeline we then create states in it.

// create 3 states for the user lifeline
IStateCondition stateWaitAccess = IModelElementFactory.instance().createStateCondition();

Now repeat the above and try to create the WaitCard and Idle state in user lifeline, and create the ACSystem lifeline as well as the NoCard and HasCard state by yourself.

Create states under lifeline

Create states under lifeline

Create Time Messages and Duration Constraint

Next we create the duration constraint and time message. To crate time messages:

// create the time messages, we will then
// set its start and end when working on the time instance of the lifelines
ITimeMessage timeMsgCode = IModelElementFactory.instance().createTimeMessage();

Repeat the above to create the other two time message, the CardOut and OK. After that we move on to create the duration constraint:

// create duration constraint and specify its name
IDurationConstraint durationConstraint = IModelElementFactory.instance().createDurationConstraint();
// add duration constraint to user lifeline

Please note that the start and end of the time message and duration constraint is not yet specified in here. They will be specified in the next phrase.

Create Time Instance on lifeline

Now we are on the most important part, the time instance on the lifelines. To create time instance:

// create time instance on user lifeline from time 0 to 3 it should be on Idle state
for (int i = 0; i <= 3; i++) {
  ITimeInstance timeInstance = ModelElementFactory.instance().createTimeInstance();
  // specify the start of the Code message at time instance #3
  if (i == 3) {
Create time instance

Create time instance

For the duration constraint, we can use the setStartTime and setEndTime to specify the start and end time instance.

Repeat the above to create other time instance, and specify the start and end of the time message as well as duration constraint by following the information below.

User lifeline


WaitAccess WaitCard Idle
Time Instance 10-13 3-10 0-3, 13-15
Create time instance for User lifeline

Create time instance for User lifeline

ACSystem lifeline


NoCard HasCard
Time Instance 0-5, 11-15 5-11
Create time instance for ACSystem lifeline

Create time instance for ACSystem lifeline

Time Message Start End
Code 3 (Idle) 5 (NoCard)
CardOut 8 (HasCard) 10 (WaitCard)
OK 10 (HasCard) 13 (WaitAccess)
Create time message

Create time message

Duration constraint “{d..3*d}” Time Instance
Start 3
End 10
Create duration constraint

Create duration constraint

Finally we create the Time Constraint on time instance #13 of User lifeline.

// add a time constraint to time instance #13
Create Time Constraint

Create Time Constraint

Show up the diagram

When everything is ready we can show up the diagram.

// show up the diagram

Sample Plugin

The sample plugin attached in this article demonstrate how to create timing diagram using Open API. After you deploy the plugin into Visual Paradigm you can click the plugin button in the application toolbar to trigger it.

Trigger sample plugin

Trigger sample plugin

Download Sample Plugin

You can click this link to download the sample plugin.

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply