Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to use SetCommand to set multiplicity(How to use SetCommand to set multiplicity)
How to use SetCommand to set multiplicity [message #1806318] Tue, 07 May 2019 17:09 Go to next message
Oliver Gardiner is currently offline Oliver GardinerFriend
Messages: 26
Registered: May 2014
Location: Oxford, UK
Junior Member
I'd like to create some shortcuts (e.g. on the context menu) that make it quick to set standard cardinalities on Associations. Have managed to get everything working to the point of being able to invoke a SetCommand but am struggling with the multiplicity element as there is the complication of the value type as well as the value itself.

The code I am using in the handler is along the lines of:

TransactionalEditingDomain editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
Command command = SetCommand.create(editingDomain, ends.get(0), UMLPackage.Literals.MULTIPLICITY_ELEMENT__UPPER_VALUE, upperSource);
editingDomain.getCommandStack().execute(command);

If I set upperSource to be an Integer.valueOf(-1) then the cardinality becomes * only if it had at some point been set to an unlimited natural. If it started out as an Integer then the command has no effect. Is there a correct way to set MultiplicityElement values such that you can be sure that a * will be a * and a 1 will be a 1?

Many thanks
Re: How to use SetCommand to set multiplicity [message #1806320 is a reply to message #1806318] Tue, 07 May 2019 17:39 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1199
Registered: July 2009
Location: Canada
Senior Member

Hi, Oliver,

I think it will always be best to replace the ValueSpecification element for the multiplicity bound in its entirety. So, create a LiteralUnlimitedNatural, set the LiteralUnlimitedNatural.UNLIMITED value into it, and use a SetCommand to set that unlimited-natural instance into the MultiplicityElement::upperBound reference.

HTH,

Christian
Re: How to use SetCommand to set multiplicity [message #1806407 is a reply to message #1806320] Wed, 08 May 2019 14:38 Go to previous message
Oliver Gardiner is currently offline Oliver GardinerFriend
Messages: 26
Registered: May 2014
Location: Oxford, UK
Junior Member
Many thanks - have got that to work.

Much appreciated
Previous Topic:State machine animation
Next Topic:How to declare a default constructor for C++ in Papyrus
Goto Forum:
  


Current Time: Mon Dec 16 02:57:16 GMT 2019

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

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

Back to the top