[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: Problems with Duplicate action

Hi Mario,

my editors hide the "Duplicate"-action in generel.
However, with the approach described below, the drap-copy method invokes the command as well.
To my understanding, this is a more native and ergonomic method of cloning resp. duplicating objects, than right-clicking and explicitely invoking an action.
While draggin an element (of course also inside a compartment) and pushing the <ctrl>-Button, the Duplicate-command described below is executed.
I am pretty sure, you can adopt the default <Duplicate>-action provided by GMF to work on any GraphicalEditPart.
I haven't had the time to check which EditPolicy exactly implements this behavior, but there should be one that ould be modified as well, not having to modify the generated XXXBaseItemSemanticEditPolicy.
The only tricky thing is when duplicating Connections and assigning existing elements as source and target.



HTH Regards Thomas



Mario Cervera schrieb:
I can actually duplicate elements contained in the canvas so I've got something similar done in my editor, but my problem is that I can't duplicate elements contained in comparments (the item "Duplicate" doesn't even appear in the pop-up menu) and I don't see how that code can solve the problem :-(

Thanks

Mario

"Thomas Beyer" <thomas.beyer81@xxxxxxxxxxx> escribió en el mensaje news:gnk6l5$oea$1@xxxxxxxxxxxxxxxxxxxx
Hi Mario,


my solution below:

1. Create a new class called DuplicateAnythingCommand (see attached file).

2. In your generated XXXBaseItemSemanticEditPolicy, add the following
lines to your generated <getCommand>-method as follows:
public Command getCommand(Request request) {
[...]
Command result = super.getCommand(request);
if (request instanceof EditCommandRequestWrapper) {
IEditCommandRequest ier = ((EditCommandRequestWrapper)
request).getEditCommandRequest();
if (ier instanceof DuplicateElementsRequest && result == null) {
//call your new DuplicateCommand
return new ICommandProxy(new
DuplicateAnythingCommand(getEditingDomain(), (DuplicateElementsRequest)
ier));
}
}
[...]
return result;
}


Does the trick for me.

HTH
Regards, Thomas


Mario Cervera schrieb:
Hello,

I've noticed in my graphical editor that I can only duplicate elements that
are contained in the canvas element but not in compartments. I'd like to be
able to duplicate all elements. Does anyone know how to do this? I've seen
that the Duplicate action is contributed in the plug-in
"org.eclipse.gmf.runtime.diagram.ui.providers" so I can't modify those
classes.


Thanks in advance.

Mario





--------------------------------------------------------------------------------


package XXX.diagram.custom.command;

import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.emf.commands.core.commands.DuplicateEObjectsCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest;


/**
* Command that allows the duplication of any notational element with its
* underlying domain model element.
*
*/
public class DuplicateAnythingCommand extends DuplicateEObjectsCommand {

/**
* Constructor
*
* @param editingDomain
* @param req
*/
public DuplicateAnythingCommand(TransactionalEditingDomain editingDomain,
DuplicateElementsRequest req) {
super(editingDomain, req.getLabel(), req.getElementsToBeDuplicated(),
req.getAllDuplicatedElementsMap());
}

}