Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » problem with adding element to ordered set(problem with adding element to ordered set)
problem with adding element to ordered set [message #1758636] Thu, 30 March 2017 21:50 Go to next message
taghreed altamimi is currently offline taghreed altamimiFriend
Messages: 182
Registered: October 2014
Senior Member
Hi ,
I am trying to add a child type activity to taskactivities(parent)
and when i run the code it keeps adding the child to the root .

I have attached a minimal example to reproduce the problem please :

1- run testCode.eol launch
2-open NewLqnFeb.model (you can see that New OpaqueAction activity added to the root not not taskactivities.
3.lqnmodel is the metamodel


Thanks,
Taghreed
Re: problem with adding element to ordered set [message #1758650 is a reply to message #1758636] Fri, 31 March 2017 07:46 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1612
Registered: July 2009
Location: York, UK
Senior Member

Hi Taghreed,

"taskactivity" is a collection so "taskactivity.activity" returns a collection of collections, which you're then adding "activity" to. This is the expected behaviour; it appears that you're adding "activity" to the wrong collection.

Thanks a lot for the additional effort you've put into preparing your minimal example. A couple more things if I may:
- In Ecore there's a strong convention for class names to start with an upper-case letter and to be in singular (i.e. "class TaskActivity" instead of "class taskactivities")
- It's usually a good idea for variable names to be consistent with the values they hold. For example, in "var taskactivity = t.taskactivities;" your variable should be called "taskactivities" instead of "taskactivity" as you're expecting its value to be assigned to a collection. This can help make your code more readable and maintainable.
- I would recommend using "var tasks = Lqn!task.all;" in the first statement of your program. The current syntax works as "tasks" is then consumed in a for loop but "tasks.size()" for example wouldn't work as expected because the value of "tasks" in your version of the program is a model element type; not a collection of all its instances.

Cheers,
Dimitris

[Updated on: Fri, 31 March 2017 07:57]

Report message to a moderator

Re: problem with adding element to ordered set [message #1758681 is a reply to message #1758650] Fri, 31 March 2017 15:41 Go to previous messageGo to next message
taghreed altamimi is currently offline taghreed altamimiFriend
Messages: 182
Registered: October 2014
Senior Member
Hi Dimitris,
Thanks for your comments.I checked the metamodel and activity is a child for taskactivities according to the metamodel .Is there any trick to add the activity to its parent not to the root.


Cheers,
Taghreed
Re: problem with adding element to ordered set [message #1758687 is a reply to message #1758681] Fri, 31 March 2017 16:16 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1612
Registered: July 2009
Location: York, UK
Senior Member

Hi Taghreed,

You just need to add your "activity" under the "activity" containment reference of a "taskactivities" model element.

One more piece of advice that I forgot to mention in my previous message:
- It is also very useful for the names of attributes/references to reflect their multiplicities e.g. "val activity[1..*] activity;" should read "val Activity[1..*] activities;" instead

If you can try to refactor your metamodel according to these principles I will be able to help more effectively.

Cheers,
Dimitris

[Updated on: Sat, 01 April 2017 07:29]

Report message to a moderator

Re: problem with adding element to ordered set [message #1758690 is a reply to message #1758687] Fri, 31 March 2017 16:44 Go to previous messageGo to next message
taghreed altamimi is currently offline taghreed altamimiFriend
Messages: 182
Registered: October 2014
Senior Member
Hi Dimitris,
Refactoring the metamodel will affect the transformation and other codes that depend on it so i don't think it is going to be easy at this point:)
i am using this code taskactivities.activity.add(activity2); to add my "activity" under the "activity" containment reference but it didn't work .
Please can you give me any trick to do that .

Thanks,
Taghreed
Re: problem with adding element to ordered set [message #1758696 is a reply to message #1758690] Fri, 31 March 2017 17:19 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1612
Registered: July 2009
Location: York, UK
Senior Member

Hi Taghreed,

Trying to understand and suggest solutions against a poorly named metamodel is not easy either I'm afraid. You'll have to help me out a bit more here before I can provide any further assistance.

Cheers,
Dimitris

[Updated on: Fri, 31 March 2017 17:21]

Report message to a moderator

Re: problem with adding element to ordered set [message #1758716 is a reply to message #1758696] Fri, 31 March 2017 21:58 Go to previous messageGo to next message
taghreed altamimi is currently offline taghreed altamimiFriend
Messages: 182
Registered: October 2014
Senior Member
index.php/fa/28951/0/index.php/fa/28950/0/index.php/fa/28950/0/Hi Dimitris ,
I have attached the metamodel as a diagram ,i hope it can help you .The relation between taskactivities and activity is very clear in the diagram.

I wish you can help me .

Thanks,
Taghreed.

[Updated on: Fri, 31 March 2017 22:00]

Report message to a moderator

Re: problem with adding element to ordered set [message #1758730 is a reply to message #1758716] Sat, 01 April 2017 07:27 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1612
Registered: July 2009
Location: York, UK
Senior Member

Hi Taghreed,

To add an "activity" "a" under a "taskactivities" "ta", "ta.activity.add(a);" should work.

Cheers,
Dimitris
Re: problem with adding element to ordered set [message #1758745 is a reply to message #1758730] Sat, 01 April 2017 15:16 Go to previous message
taghreed altamimi is currently offline taghreed altamimiFriend
Messages: 182
Registered: October 2014
Senior Member
Hi Dimitris,
i added a loop to for taskactivities sequence then i used ta.activity.add(a) .Thanks for your help.
var tasks = Lqn!task.all;
	 	  for (t in  tasks){
	 	  if (t.name="Artifact3"){
	 	  var ta=t.taskactivities.println();	 	  
	 if (not ta.isEmpty()){
          	  var a :new Lqn!activity;
                 a.name="OpaqueAction999";
             
             for (tac in t.taskactivities) {
                 tac.activity.add(a);}
               "activity2.name ".print()+a.name.println();
          	
          	  }
      
          	 }
	 	      }

[Updated on: Sat, 01 April 2017 15:18]

Report message to a moderator

Previous Topic:commit in EOL
Next Topic:Error in installing epsilon on eclipse Luna
Goto Forum:
  


Current Time: Fri Nov 16 16:02:12 GMT 2018

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

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

Back to the top