I want to generate an activity-diagram with my java code. it work's to create an actionelement:
//Add the actionElement to the package
Element actionElement = elements.AddNew("MyFirstAction", "Action");
elements.Refresh();
//Add the element to the activity diagram
DiagramObject dob = dobs.AddNew("", "");
dobs.Refresh();
//reference the DiagramObject to the before created element
dob.SetElementID(element.GetElementID());
dob.Update();
dobs.Refresh();
So I thought it will work's for the Initial (or EntryPoint) in the same way:
Element initElement = elements.AddNew("Start...","EntryPoint");
But the following Exception appears:
java.lang.Exception: Invalid parent for EntryPoint (Package)
Somebody can help me? My othe question is, if there is any Enumeration for the ElementTypes of the Collection? Because I only found the following information of the collection class..
AddNew (string Name, string Type)
But the information of the Type tells only "Type: String (up to 30 characters long)".
Here is a link to the Collection Class: http://www.sparxsystems.com/enterprise_architect_user_guide/9.2/automation/collection.html
Regards
EDIT
With help of Uffe I got the information of subtypes and types of some activity-diagram components. The "orginal name" is that name what you see in the GUI of the Enterprise Architect when you want to add a "New Element or Connector" :
- original name: "Action"; type: "Action"; subtype: 0;
- original name: "Activity"; type: "Activity"; subtype: 0;
- original name: "Structured Activity" (Other->Simple Composite); type: "Activity"; subtype: 8;
- original name: "Initial"; type: "StateNode"; subtype: 100;
- original name: "Final"; type: "StateNode"; subtype: 101;
- original name: "Flow Final"; type: "StateNode"; subtype: 102;
- original name: "Decision"; type: "Decision"; subtype: 0;
- original name: "Merge"; type: "MergeNode"; subtype: 0;
- original name: "Decision"; type: "Decision"; subtype: 0;
- original name: "Fork/Join" (horizontal); type: "Synchronization"; subtype: 0;
- original name: "Fork/Join" (vertical); type: "Synchronization"; subtype: 1;
- original name: "Diagram Legend"; type: "Text"; subtype: 76;
- original name: "Synch"; type: "StateNode"; subtype: 6;
Uffe already explained it in his answer. Firstly create the Element with the type parameter and after that set the specific subtype. Don't forget the update() after this.
Element element = elements.AddNew("StartHere", "StateNode");
element.Subtype = 100;
element.Update();
elements.Refresh();
Thanks to Uffe again for this example:)