Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Papyrus for Real Time » Creating a custom Capsule
Creating a custom Capsule [message #1749947] Wed, 14 December 2016 08:57 Go to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
Hi,

I'm trying to create a custom capsule (element type) with some custom behavior.

When creating a new instance of this capsule type the capsule should be created and a custom Capsule Structure Diagram be created in the capsule. This I've managed to do.

What I also want is to create an UML-RT Staemachine , i.e an instance of org.eclipse.papyrusrt.umlrt.core.RTStateMachine which in turn should create an instance of my custom StateMachineDiagram.

Here I suppose I need to create an specialization type of the org.eclipse.papyrusrt.umlrt.core.RTStateMachine and add an advice to create my custom StateMachineDiagram (similar to the custom Capsule Structure Diagram mention above).

The question is how to I create an instance of org.eclipse.papyrusrt.umlrt.core.RTStateMachine (or my specialization) and add it to my custom capsule?

I guess this boils down to the question how to create a instance of an element type programmatically.


Re: Creating a custom Capsule [message #1749956 is a reply to message #1749947] Wed, 14 December 2016 13:35 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
I managed to get it working with this code. Dont know it it is the 'right'/best way.


   ServicesRegistry registry;
   try {
      registry =  ServiceUtilsForEObject.getInstance().getServiceRegistry(elementToConfigure);
      TransactionalEditingDomain editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(registry);
      final CreateElementRequest request = 
         new CreateElementRequest(editingDomain, elementToConfigure,									ElementTypeRegistry.getInstance().getType("org.eclipse.papyrusrt.umlrt.core.RTStateMachine"));
      IElementEditService provider = ElementEditServiceUtils.getCommandProvider(elementToConfigure);
      ICommand createGMFCommand = provider.getEditCommand(request);
      final Command emfCommand = GMFtoEMFCommandWrapper.wrap(createGMFCommand);
					editingDomain.getCommandStack().execute(emfCommand);
      final EObject rtSM = request.getNewElement();
   } catch (ServiceException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
   }

Re: Creating a custom Capsule [message #1749957 is a reply to message #1749947] Wed, 14 December 2016 13:39 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1176
Registered: July 2009
Location: Canada
Senior Member

Hi, Patrik,

I think what you need is to advise the ConfigureRequest by which the command is obtained by the edit-helper that creates the capsule to configure that new capsule. Every new element created by the edit-helper framework is configured in this way after creation.

So, your configure advice can re-entrantly invoke the edit-helper framework to add a command that creates the state machine in the new capsule. The ConfigureRequest, because it is configuring the new capsule, already has the capsule type that you need from which to obtain the RT state machine creation command in the getTypeToConfigure().

HTH,

Christian
Re: Creating a custom Capsule [message #1749963 is a reply to message #1749947] Wed, 14 December 2016 13:56 Go to previous messageGo to next message
Remi Schnekenburger is currently offline Remi SchnekenburgerFriend
Messages: 167
Registered: July 2009
Location: Palaiseau, France
Senior Member
Hi Patrick,

To create an element base on its element type, I advise you to use this method: org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils.getCreateChildCommandWithContext(EObject, IHintedType)

This will return you a command that you can execute on the editing domain command stack or null or an unexecutable command depending on the ability to create the element or not in the specified context.

HTH,
Rémi


Remi Schnekenburger

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: Creating a custom Capsule [message #1749975 is a reply to message #1749947] Wed, 14 December 2016 15:32 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 350
Registered: March 2011
Senior Member
I don't know the specifics of this case, but Philip Langer created a very nice Papyrus customization guide [1] which he followed to create "Papyrus for Information Modelling". He also gave a webinar [2] on this customization. I thought these might be of interest to you.

[1] https://wiki.eclipse.org/Papyrus_for_Information_Modeling/Customization_Guide
[2] https://drive.google.com/open?id=0B7MUe4SLYLPmbU16NFZEUFFUbk0
Re: Creating a custom Capsule [message #1750045 is a reply to message #1749975] Thu, 15 December 2016 12:33 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
Thanks for the help everyone.

I managed to get it working by adding the following code to the Capsule's Advice#getAfterConfigureCommand():
   registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(elementToConfigure);
   TransactionalEditingDomain editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(registry);
   ICommand c = ElementEditServiceUtils.getCreateChildCommandWithContext(elementToConfigure,
      (IHintedType) ElementTypeRegistry.getInstance().getType("my.CapsuleDiagramTest.MyStateMachine"));
   Command emfCommand = GMFtoEMFCommandWrapper.wrap(c);
   editingDomain.getCommandStack().execute(emfCommand);

Re: Creating a custom Capsule [message #1750050 is a reply to message #1750045] Thu, 15 December 2016 13:36 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
Apparently the diagram synchronization doesn't work with my customization. It works in pure UML-RT.

Is the synchronization tied to a specific element type i.e. 'org.eclipse.papyrusrt.umlrt.core.RTStateMachine' and doesn't work with my specialization ('my.CapsuleDiagramTest.MyStateMachine') of that type?
Re: Creating a custom Capsule [message #1750052 is a reply to message #1750050] Thu, 15 December 2016 13:56 Go to previous messageGo to next message
Remi Schnekenburger is currently offline Remi SchnekenburgerFriend
Messages: 167
Registered: July 2009
Location: Palaiseau, France
Senior Member
Does it work without your new specific diagram type? There was a bug in Papyrus-RT, where synchro was lost for quite many elements. It has been restored today.

Otherwise, the viewpoint is in charge of the deployment of the css that enables the canonical for state machine diagrams. The viewpoint mechanism may tight the stylesheet to the exact kind of diagram, not the sub-kinds of the diagrams. You can try to add your own css to the viewpoint, with canonical mode added, and checks if it works.
IMO the CSS should be inherited, but I am not sure how the viewpoint engine handles the declared css currently.

There is a way to see easaily if synchro is activated => go to Property View, appearance tab => Synchronization (sync with model) should be true.

HTH
Rémi


Remi Schnekenburger

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: Creating a custom Capsule [message #1750064 is a reply to message #1750052] Thu, 15 December 2016 15:35 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
Thanks Remi, I'll look into that
Re: Creating a custom Capsule [message #1750067 is a reply to message #1750064] Thu, 15 December 2016 16:32 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
Works, thanks again for the help.

(I wan't aware of the canonical CSS property)
Re: Creating a custom Capsule [message #1751660 is a reply to message #1750045] Thu, 12 January 2017 10:46 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
Patrik Nandorf wrote on Thu, 15 December 2016 13:33
Thanks for the help everyone.

I managed to get it working by adding the following code to the Capsule's Advice#getAfterConfigureCommand():
   registry = ServiceUtilsForEObject.getInstance().getServiceRegistry(elementToConfigure);
   TransactionalEditingDomain editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(registry);
   ICommand c = ElementEditServiceUtils.getCreateChildCommandWithContext(elementToConfigure,
      (IHintedType) ElementTypeRegistry.getInstance().getType("my.CapsuleDiagramTest.MyStateMachine"));
   Command emfCommand = GMFtoEMFCommandWrapper.wrap(c);
   editingDomain.getCommandStack().execute(emfCommand);



Now when using this I get this when executing the command. Anyone having an idea why?
!ENTRY org.eclipse.emf.common 2 0 2017-01-12 11:28:16.966
!MESSAGE An exception was ignored during command execution
!STACK 0
org.eclipse.emf.common.util.WrappedException: An exception was ignored during command execution
	at org.eclipse.emf.common.command.BasicCommandStack.handleError(BasicCommandStack.java:281)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.handleError(AbstractTransactionalCommandStack.java:125)
	at org.eclipse.papyrus.infra.emf.gmf.command.NestingNotifyingWorkspaceCommandStack.handleError(NestingNotifyingWorkspaceCommandStack.java:164)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:229)
	at org.eclipse.papyrus.infra.emf.gmf.command.NestingNotifyingWorkspaceCommandStack.execute(NestingNotifyingWorkspaceCommandStack.java:130)
	at org.eclipse.papyrus.infra.emf.gmf.command.NestingNotifyingWorkspaceCommandStack.startNestedTransaction(NestingNotifyingWorkspaceCommandStack.java:85)
	at org.eclipse.papyrus.infra.emf.gmf.command.NestingNotifyingWorkspaceCommandStack.execute(NestingNotifyingWorkspaceCommandStack.java:137)
	at com.ericsson.dura.bbi.cbb.tooling.core.advice.HiveActorEditHelperAdvice$1.doExecuteWithResult(HiveActorEditHelperAdvice.java:158)

----

Caused by: org.eclipse.emf.transaction.RollbackException: Impossible to find a command to create the region
	at org.eclipse.papyrus.infra.emf.gmf.command.NotifyingWorkspaceCommandStack.doExecute(NotifyingWorkspaceCommandStack.java:268)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)





Re: Creating a custom Capsule [message #1751680 is a reply to message #1751660] Thu, 12 January 2017 12:30 Go to previous message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
Sorry, I missed to add the UML-RT Statemachine profile. With that applied it works.
Previous Topic:Papyrus for Realt Time + Qt GUI + RTOS for full RT application
Next Topic:list of RTS services?
Goto Forum:
  


Current Time: Fri Sep 21 05:36:23 GMT 2018

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

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

Back to the top