Create Decision Table using Open API

Decision Table is a handy tool to present the business rules and regulations. It present the rules in tabular form which make it become an extremely easy to use reference resource on business decisions and system logics. Decision Tables is supported starting from the Professional Edition of Visual Paradigm. Besides create it manually over Visual Paradigm’s client you can also do it programmatically using Open API. This article will demonstrate how to create Decision Table using Open API.

The decision table going to create by the plugin

Create Blank Decision Table Diagram

First we create a blank Decision Table Diagram using DiagramManager.

// Obtain DiagramManager and create Decision Table Diagram 
DiagramManager dm = ApplicationManager.instance().getDiagramManager();
IDTBDecisionTableEditorDiagramUIModel decisionTableDiagram = (IDTBDecisionTableEditorDiagramUIModel) dm.createDiagram(IDiagramTypeConstants.DIAGRAM_TYPE_DTB_DECISION_TABLE_EDITOR_DIAGRAM);

Unlike other diagrams that will associate with multiple model elements, the Decision Table Diagram will only associate with one decision table model called IDTBDecisionTable. After we create the IDTBDecisionTable from IModelElementFactory we can then retrieve its ID and associate it to the diagram.

// Obtain Model Element Factory
IModelElementFactory factory = IModelElementFactory.instance();

// Create Decision Table model 
// and clear its default condition, action and rule
IDTBDecisionTable decisionTable = factory.createDTBDecisionTable();
// Assign the decision table to diagram

Create Conditions

Next we create the conditions IDTBCondition for the decision table. We can simply create the IDTBCondition from IModelElementFactory, specify its name and assign it to decision table.

// Create conditions and assign to decision table
IDTBCondition condAddressProvided = factory.createDTBCondition();
condAddressProvided.setName("Address proof provided");

Repeat the steps to create other conditions for the decision table.

Create Actions

After that we create the Actions IDTBAction for the decision table. Same as the conditions we just create it from IModelElementFactory, specify its name and assign it to decision table.

// Create actions and assign to decision table
IDTBAction actApprove = factory.createDTBAction();
actApprove.setName("Approve loan request immediately");

Again, repeat the steps to create the other actions. After create the actions we then specify the width for the conditions and actions column to make sure the text can be fully shown in table.

Create Rules

Now we create the rules IDTBRule for the decision table. Again, the steps is similar to create conditions and actions. The only different is we need to specify the width of the rule column.

// Create rules and specify its width
IDTBRule rule1 = factory.createDTBRule();

Apply Conditions to Rule

As everything is ready let’s apply condition(s) to rule(s). We create IDTBRuleConditionValue from IModelElementFactory, then specify its rule, condition and name. Finally add it to decision table.

// Specify conditions and values and apply to rule
IDTBRuleConditionValue rule1Con = factory.createDTBRuleConditionValue();

Specify Action for Rule

The action value works in the similar way as the condition. We create IDTBRuleActionValue from IModelElementFactory, then specify its rule, action and name. Finally add it to decision table.

// Specify action for the rule
IDTBRuleActionValue rule1Act = factory.createDTBRuleActionValue();

Now repeat the above steps to create other rules.

Show up the Diagram

Finally we call DiagramManager.openDiagram to show up the Decision Table.

// Show up the diagram

Sample Plugin

The sample plugin demonstrate how to create Decision Table using Open API. After you deploy the plugin into Visual Paradigm you can then click the plugin button in the application toolbar to trigger it.

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