Creating a custom Capsule [message #1749947] |
Wed, 14 December 2016 08:57  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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
|
|
|
|
Re: Creating a custom Capsule [message #1750045 is a reply to message #1749975] |
Thu, 15 December 2016 12:33   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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
|
|
|
|
|
Re: Creating a custom Capsule [message #1751660 is a reply to message #1750045] |
Thu, 12 January 2017 10:46   |
Eclipse User |
|
|
|
Patrik Nandorf wrote on Thu, 15 December 2016 13:33Thanks 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)
|
|
|
|
Powered by
FUDForum. Page generated in 0.04374 seconds