Search code examples
javaumlenterprise-architectactivity-diagram

enterprise architect scripting in java: how to change the way of a connector?


I try to change the way of a connector which connects two elements in an activity diagram. I use the Java API (eaapi.jar) from sparx. My function to connect two elements:

public void connectTwoElements(Element source, Element target) {
    Connector con = source.GetConnectors().AddNew("","ControlFlow");
    con.SetSupplierID(target.GetElementID());
    con.Update();
    source.GetConnectors().Refresh();
}

My goal is to change the way of connector like in the below right scenario. The way of the connector to the target element should have an edge point to create a 90° angle.

I didn't found any attribute of the class Connector to implement that. I expect that I can use a function like: myConnector.addBetweenPoint(int x, int y);

Maybe anyone can help me:)

Regards, Phil

EDIT:

After Nizam Mohamed and Uffe helps me below, I modified my method:

 public void connectTwoElements(Element source, Element target, String connectorLabel) {
    Connector con = source.GetConnectors().AddNew(connectorLabel,"ControlFlow");        
    con.SetSupplierID(target.GetElementID());
    con.Update();        
    source.GetConnectors().Refresh();
    diagram.GetDiagramLinks().Refresh();

    //change style of diagram link
    Collection<DiagramLink> diagramLinks = diagram.GetDiagramLinks();
    for(DiagramLink dl : diagramLinks){
        if(dl.GetConnectorID()==con.GetConnectorID()){
            dl.SetStyle("Mode=3;TREE=LV;");
            dl.Update();
            diagram.GetDiagramLinks().Refresh();
            break;
        }
    }
}

It is important to Refresh() the Collection DiagramLinks of the Diagram after add a new Connector because otherwise the DiagramLink isn't available in the Collection DiagramLinks to change the style. Of course you must Refresh() it again after changing the style.


Solution

  • You can set the linestyle to Orthogonal - Square or Lateral - Vertical to achieve this. To do this, you need to get the DiagramLink and set its style.

    Below are some combinations

    (for Orthogonal Square) Mode=3;TREE=OS;

    (for Lateral Vertical) Mode=3;TREE=LV;