Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » EMF transaction for inserting a new Element in a diagram(EMF transaction and papyrus)
EMF transaction for inserting a new Element in a diagram [message #1048264] Wed, 24 April 2013 04:31 Go to next message
HERISSE Alexandre is currently offline HERISSE Alexandre
Messages: 3
Registered: April 2013
Junior Member
My question concerns the adding of a Comment or a NamedElement such as a CallBehaviour for example in an active activity diagram through an emf transaction.

I would use the following skeleton for example:

// we suppose we have access to the serviceRegistry instance
TransactionalEditingDomain domain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
domain.getCommandStack().execute(new RecordingCommand(domain) {
public void doExecute() {
// do the changes here
}
}

I have downloaded your Papyrus source code. However I have no idea where to search an example for adding an Element in the active editor or some code that might help me?
I have grep "RecordingCommand" but I found a lot of occurences with some "@generated code" comments. Thus I decided to ask for some help.

How to deal with my need ?


Thanks

Re: EMF transaction for inserting a new Element in a diagram [message #1048457 is a reply to message #1048264] Wed, 24 April 2013 09:47 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 551
Registered: July 2009
Senior Member
Hi, Alexandre,

Many (most?) such editing actions in Papyrus don't execute
RecordingCommands on the CommandStack but AbstractEMFOperations on the
IOperationHistory. They can be added to context menus using the
org.eclipse.ui.menus extension point, together with command handlers.
For an example, you might look at how the Add Child menu is implemented
in the Model Explorer.

HTH,

Christian


On 2013-04-24 12:48:39 +0000, HERISSE Alexandre said:

> My question concerns the adding of a Comment or a NamedElement such as
> a CallBehaviour for example in an active activity diagram through an
> emf transaction.
>
> I would use the following skeleton for example:
>
> // we suppose we have access to the serviceRegistry instance
> TransactionalEditingDomain domain =
> ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
>
> domain.getCommandStack().execute(new RecordingCommand(domain) {
> public void doExecute() {
> // do the changes here
> }
> }
>
> I have downloaded your Papyrus source code. However I have no idea
> where to search an example for adding an Element in the active editor
> or some code that might help me?
> I have grep "RecordingCommand" but I found a lot of occurences with
> some "@generated code" comments. Thus I decided to ask for some help.
>
> How to deal with my need ?
>
>
> Thanks
Re: EMF transaction for inserting a new Element in a diagram [message #1059902 is a reply to message #1048457] Wed, 22 May 2013 03:06 Go to previous messageGo to next message
HERISSE Alexandre is currently offline HERISSE Alexandre
Messages: 3
Registered: April 2013
Junior Member
Hi, I managed to create an EMF object (an initial node) in an activity diagram with this code :

"...
/**
*
*/
private IElementType getElementTypeToCreate() {
return UMLElementTypes.INITIAL_NODE;
}

/**
*
*/
private Command buildCommand()
{
IElementEditService provider = ElementEditServiceUtils.getCommandProvider(container);
if(provider == null) {
return UnexecutableCommand.INSTANCE;
}

// Retrieve create command from the Element Edit service
CreateElementRequest createRequest = null;
if(reference == null) {
createRequest = new CreateElementRequest(container, getElementTypeToCreate());
} else {
createRequest = new CreateElementRequest(container, getElementTypeToCreate(), reference);
}

ICommand createGMFCommand = provider.getEditCommand(createRequest);

Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
return emfCommand;
}

/**
*
*/
public Object executeCommand()
{
Command creationcommand = null;

try
{
ServiceUtilsForActionHandlers util = new ServiceUtilsForActionHandlers();
creationcommand = buildCommand();

util.getTransactionalEditingDomain().getCommandStack().execute(creationcommand);

return creationcommand.getResult();

} catch (ServiceException e)
{
e.printStackTrace();
}

return null;
}
..."

However it does not appear on the diagram. I have heard that I need to create the GMF part of the object and link GMF part with EMF part.

May you indicate me how I could get some examples or some help to create the graphical part of this item ?

Thanks for your help.


Re: EMF transaction for inserting a new Element in a diagram [message #1059909 is a reply to message #1048264] Wed, 22 May 2013 03:18 Go to previous message
HERISSE Alexandre is currently offline HERISSE Alexandre
Messages: 3
Registered: April 2013
Junior Member
Hi, I managed to create an EMF object (an initial node) in an activity diagram with this code :

"...
/**
*
*/
private IElementType getElementTypeToCreate() {
return UMLElementTypes.INITIAL_NODE;
}

/**
*
*/
private Command buildCommand()
{
IElementEditService provider = ElementEditServiceUtils.getCommandProvider(container);
if(provider == null) {
return UnexecutableCommand.INSTANCE;
}

// Retrieve create command from the Element Edit service
CreateElementRequest createRequest = null;
if(reference == null) {
createRequest = new CreateElementRequest(container, getElementTypeToCreate());
} else {
createRequest = new CreateElementRequest(container, getElementTypeToCreate(), reference);
}

ICommand createGMFCommand = provider.getEditCommand(createRequest);

Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
return emfCommand;
}

/**
*
*/
public Object executeCommand()
{
Command creationcommand = null;

try
{
ServiceUtilsForActionHandlers util = new ServiceUtilsForActionHandlers();
creationcommand = buildCommand();

util.getTransactionalEditingDomain().getCommandStack().execute(creationcommand);

return creationcommand.getResult();

} catch (ServiceException e)
{
e.printStackTrace();
}

return null;
}
..."

However it does not appear on the diagram. I have heard that I need to create the GMF part of the object and link GMF part with EMF part.

May you indicate me how I could get some examples or some help to create the graphical part of this item ?

Thanks for your help.
Previous Topic:Java Code Generation
Next Topic:Question about palette
Goto Forum:
  


Current Time: Tue May 28 16:41:48 EDT 2013

Powered by FUDForum. Page generated in 0.01620 seconds