Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 Tools » [SOLVED] Failed to add a node in Activity diagram in a standalone application
[SOLVED] Failed to add a node in Activity diagram in a standalone application [message #891988] Tue, 26 June 2012 18:48 Go to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Hello everybody,

I have created this simple model with one activity inside and I was trying to add the first node to the activity (the initial node)

Unfortunately there is now way I can get it done. The activity get correctly added to the model, but not the initial node

here is the code
	//Create the model
        Model model = UMLFactory.eINSTANCE.createModel();
        model.setName("Calico model");

        //Create the activity
        Activity activity_=UMLFactory.eINSTANCE.createActivity();
        model.createOwnedType("Activity", activity_.eClass());
        
        //Create the initial node
        InitialNode initialNode_=UMLFactory.eINSTANCE.createInitialNode();
        
        //add it to the activity
        //initialNode_.setActivity(activity_);
        
        //another try
        activity_.getNodes().add(initialNode_);
        
        //another try
        //initialNode_ = activity_.createNode("test",initialNode_.eClass());
        
        //save the model
        ResourceSet resourceSet = new ResourceSetImpl();
        UML300ResourcesUtil.init(resourceSet);
        Resource resource = resourceSet.createResource(URI.createFileURI("/home/motta/Desktop/Calico/CalicoSoft/AnalysisPlugin/model/model.uml"));
        resource.getContents().add(model);
        resource.save(null);


here are the libraries I am using
org.eclipse.emf.common_2.7.0.v20120127-1122.jar
org.eclipse.emf.ecore_2.7.0.v20120127-1122.jar
org.eclipse.emf.ecore.xmi_2.7.0.v20120127-1122.jar
org.eclipse.emf.mapping.ecore2xml_2.7.0.v20120130-0943.jar
org.eclipse.uml2.common_1.6.0.v201105021727.jar
org.eclipse.uml2.uml_3.2.100.v201108110105.jar


the xmi is attached. I am on Indingo
Thank you for your help
  • Attachment: model.uml
    (Size: 0.32KB, Downloaded 406 times)

[Updated on: Wed, 27 June 2012 03:07]

Report message to a moderator

Re: Failed to add a node in Activity diagram in a standalone application [message #892039 is a reply to message #891988] Tue, 26 June 2012 23:56 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Update:

The problem should be when I save the XMI file.
In fact if I try to retrieve the Initial node it has been actually added to the internal structure of the activity

		for (Element descendant : activity_.allOwnedElements()) {
			if (descendant instanceof InitialNode){
				System.out.println("Found it");
			}
		}


Adding this snippet to the previous code actually I can find the initial node
However the node is missing in the xmi
Re: Failed to add a node in Activity diagram in a standalone application [message #892059 is a reply to message #891988] Wed, 27 June 2012 03:06 Go to previous message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
solved! The problem was not correctly adding the activity to the model
here the corrected code

	//Create the model
        Model model = UMLFactory.eINSTANCE.createModel();
        model.setName("Calico model");

        //Create the activity
        Activity activity_=UMLFactory.eINSTANCE.createActivity();
wrong-->model.createOwnedType("Activity", activity_.eClass());
corr--->model.getPackagedElements().add(activity);
        
        //Create the initial node
        InitialNode initialNode_=UMLFactory.eINSTANCE.createInitialNode();
        
        //add it to the activity
        //initialNode_.setActivity(activity_);
        
        //another try
        activity_.getNodes().add(initialNode_);
        
        //another try
        //initialNode_ = activity_.createNode("test",initialNode_.eClass());
        
        //save the model
        ResourceSet resourceSet = new ResourceSetImpl();
        UML300ResourcesUtil.init(resourceSet);
        Resource resource = resourceSet.createResource(URI.createFileURI("/home/motta/Desktop/Calico/CalicoSoft/AnalysisPlugin/model/model.uml"));
        resource.getContents().add(model);
        resource.save(null);

Previous Topic:Installation Problems
Next Topic:Deployment Diagram-How to change labels in <<artifacts>>
Goto Forum:
  


Current Time: Fri Apr 26 22:39:45 GMT 2024

Powered by FUDForum. Page generated in 0.03203 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top