Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mdt-papyrus.dev] EMF transaction for inserting a new Element in a diagram

Hi,

Thanks for your previous answer. I finally managed to create an EMF object (an initial node) in an activity diagram with this following 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 the GMF part with the 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.






Le 17/04/2013 22:06, give.a.damus@xxxxxxxxx a écrit :
Hi, Alexandre,

Questions like this will find a wider audience (both to answer and to benefit from the discussion) of the newsgroup/forum.

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-17, at 9:33, Alexandre HERISSE <alexandre.herisse@xxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi all,

First, thanks a lot for your previous answers concerning how to get a "Comment" instance from the active editor. This works as expected.

My new 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


-- 
Alexandre HERISSE
Xcos developer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
Phone: +33.1.80.77.04.70
http://www.scilab-enterprises.com 
_______________________________________________
mdt-papyrus.dev mailing list
mdt-papyrus.dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/mdt-papyrus.dev


_______________________________________________
mdt-papyrus.dev mailing list
mdt-papyrus.dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/mdt-papyrus.dev


-- 
Alexandre HERISSE
Xcos developer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
Phone: +33.1.80.77.04.70
http://www.scilab-enterprises.com 

Back to the top