Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » How to replace object in ordered collection?
How to replace object in ordered collection? [message #1802002] Wed, 30 January 2019 14:55 Go to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 209
Registered: June 2010
Senior Member
Hi,

Assume that my language contains a CallExpression that owns a collection of arguments, each being represented by an Expression instance.
Assume that I create a property view where each argument is shown in a separate widget (a text widget or something like that).

Then, if the user changes such expression, I need to modify the collection. Typically, I would write a java service that interprets the text and then creates an Expression. That expression should replace the existing one in the 'arguments' collection.

What would be the best way to do that in Sirius? The approach that I've used so far is to navigate to the containing CallExpression. With a let operation, I create a variable that contains the list of current arguments. By using ->remove and ->insertAt on that variable I create the new 'arguments' collection. There I invoke an 'unset' operation that empties the old arguments collection and use a 'set' operation to give it the new collection.

That sounds cumbersome doesn't it? I'm looking for a 'replace' like operation on the arguments attribute of my CallExpression. What would be the preferred way to accomplish something like this?

Greetings,
Wilbert.
Re: How to replace object in ordered collection? [message #1802006 is a reply to message #1802002] Wed, 30 January 2019 15:46 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello,

I am not sure to understand. If the user changes an argument represented by an Expression instance, shouldn't you only need a Set operation on this semantic element to update its expression?

Regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to replace object in ordered collection? [message #1802007 is a reply to message #1802006] Wed, 30 January 2019 15:54 Go to previous messageGo to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 209
Registered: June 2010
Senior Member
Hi,

Assume that the metamodel looks like:

CallExpression
{
arguments: Expression[0,*] { composes }
}

If my properties view contains a dynamic widget by iterating over self.arguments, then each widget represents one element from the arguments collection.

A modification in such widget typically doesn't change any attributes of the Expression itself. Instead, it completely replaces the Expression by another Expression (likely of a different kind; note that Expression actually is an abstract class with a lot of specialized forms).

A 'set' operation requires an attribute to be specified that is to be changed. If I'm right, that does not allow you to replace the object all together.

Please feel free to ask additional questions. If I'm not sufficiently clear, I'll make up a toy example showing this problem.

Greetings,
Wilbert.
Re: How to replace object in ordered collection? [message #1802041 is a reply to message #1802007] Thu, 31 January 2019 09:48 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello,

In that case, from the top of my head, I do not have a better idea than your initial solution.

Regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to replace object in ordered collection? [message #1802044 is a reply to message #1802041] Thu, 31 January 2019 10:20 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

What language are you trying to write in?

If EMF-Java, then what is wrong with the standard (E)List API? "E set(int index, E element);"

Regards

Ed Willink
Previous Topic:Workspace Image style cannot take URI from feature.
Next Topic:Derived attribute
Goto Forum:
  


Current Time: Thu Apr 25 20:18:38 GMT 2024

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

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

Back to the top