Hi Arnaud,
Assuming you are trying to create a delete command for a UML
element in Papyrus you should consider using the element edit service.
To start with, have a look at oep.modelexplorer.handler.DeleteCommandHandler
:
private
Command buildCommand() {
ICommand
gmfCommand = null;
for(EObject
selectedEObject : getSelectedElements()) {
IElementEditService
provider = ElementEditServiceUtils.getCommandProvider(selectedEObject);
if(provider
== null) {
continue;
}
//
Retrieve delete command from the Element Edit service
DestroyElementRequest
request = new DestroyElementRequest(selectedEObject, false);
ICommand
deleteCommand = provider.getEditCommand(request);
//
Add current EObject destroy command to the global command
gmfCommand
= CompositeCommand.compose(gmfCommand, deleteCommand);
}
if(gmfCommand
== null) {
return
UnexecutableCommand.INSTANCE;
}
Command
emfCommand = new
GMFtoEMFCommandWrapper(gmfCommand.reduce());
return emfCommand;
}
This creates a compound delete command for a set of elements,
their containments and related views.
See the parent class for the execution of this command:
public
Object execute(ExecutionEvent
event) throws ExecutionException {
try {
ServiceUtilsForActionHandlers
util = new ServiceUtilsForActionHandlers();
util.getTransactionalEditingDomain().getCommandStack().execute(getCommand());
} catch
(ServiceException e) {
Activator.log.error("Unexpected
error while executing command.", e);
}
return null;
}
Best regards,
YT
Hi all,
I have done many search to find if someone have the
same problem than me and I have found some clues but nothing work so I post
here.
I use Helios Build id: 20100617-1415
And Papyrus MDT 0.7.0.v201007251735
I'm creating a plugin to populate an UML model from a
database. So I have a parser getting elements from the database.
Then, I need to compare the existing elements with the
new element and replace/add/delete acccording to the result.
I have an IWorkbenchWindowActionDelegate to launch the
population of the diagram. In this action I have a WorkspaceModifyOperation.
In the WorkspaceModifyOperation, I have a
RecordingCommand in witch I make my modifications on the model.
These modifications are DeleteCommands and
RemoveCommands. I use the uml2 methods to create my new elements.
Is this a good way to modify a model (I mean is it good
to do Commands inside commands ?
When I try my plugin, the modifications are done, I
save the modified diagram (and so the model) and when I reopen it, I have an
error:
!MESSAGE org.eclipse.uml2.uml.internal.impl.ClassImpl
cannot be cast to org.eclipse.uml2.uml.Operation
!STACK 0
java.lang.ClassCastException: org.eclipse.uml2.uml.internal.impl.ClassImpl
cannot be cast to org.eclipse.uml2.uml.Operation
|
It seems that this error is close to this one: https://bugs.eclipse.org/bugs/show_bug.cgi?id=319240
But I do not find the way to solve it.
Here is a part of my code:
//Get the org.eclipse.uml2.uml.operation
Operation op = getOperationToModify();
EditingDomain dom = AdapterFactoryEditingDomain.getEditingDomainFor(op);
Command commDeleteOP = RemoveCommand.create(dom, op);
Command commDeleteParams = DeleteCommand.create(dom, op.getOwnedParameters());
tmp = (Class) op.getOwner();
domain.getCommandStack().execute(commDeleteParams);
domain.getCommandStack().execute(commDeleteOP);
op = ((Class)tmp).createOwnedOperation(actionName, tmpParamName, tmpParamType);
This is how I manage my
modification, is this good or is there a problem ?
I tried to find some Papyrus MDT Cookbook but on the
svn, it's an old version.
I also find this: http://wiki.eclipse.org/Papyrus_Developer_Guide/Editing_Domains_and_Commands
but it's for Papyrus (old version)
Is there a new version of the second document ?
Thanks for your help.
Arnaud