I try to generate an activity diagram with help of my external java program. My problem: After I add an element (for example an Action) to the diagram I want to modify the position of it (left,right) because some elements are bigger than others.
My code:
Collection<DiagramObject> dobs = diagram.GetDiagramObjects();
//location calculation left out here
DiagramObject dob = dobs.AddNew(location.toString(),"");
dobs.Refresh();
dob.SetElementID(e.GetElementID());
dob.Update();
//center the position of the diagramobject on the left&right value
int horizontalDiff = dob.GetRight() - dob.GetLeft();
dob.SetRight(dob.GetRight()-horizontalDiff/2);
dob.SetLeft(dob.GetLeft()-horizontalDiff/2);
dob.Update();
If I check the values Left
and Right
of the dob
-Object the values are changed. But when I open my EA Project they appears at the old position (before the centering code was executed).
When I execute the code to center all diagram objects after I opened and close the EA-Project it work's:
for(DiagramObject dob : diagram.GetDiagramObjects){
int horizontalDiff = dob.GetRight() - dob.GetLeft();
dob.SetRight(dob.GetRight()-horizontalDiff/2);
dob.SetLeft(dob.GetLeft()-horizontalDiff/2);
dob.Update();
}
But when I execute this without open EA-Project before, it changes the appearance not.
Anyone have an idea why it work's after open the EA-Project manually?
Here my goal in form of an image: