Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Problems with Duplicate action
Problems with Duplicate action [message #219293] Thu, 19 February 2009 16:19 Go to next message
Mario Cervera is currently offline Mario CerveraFriend
Messages: 66
Registered: July 2009
Member
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
Re: Problems with Duplicate action [message #219349 is a reply to message #219293] Thu, 19 February 2009 17:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: thomas.beyer81.t-online.de

This is a multi-part message in MIME format.
--------------040204070801040502090501
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

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


--------------040204070801040502090501
Content-Type: text/plain;
name="DuplicateAnythingCommand.java"
Content-Transfer-Encoding: base64
Content-Dispos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zTWFwKCkpOw0KCX0NCg0KfQ==
--------------040204070801040502090501--
Re: Problems with Duplicate action [message #219380 is a reply to message #219349] Fri, 20 February 2009 09:46 Go to previous messageGo to next message
Mario Cervera is currently offline Mario CerveraFriend
Messages: 66
Registered: July 2009
Member
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@t-online.de> escribi
Re: Problems with Duplicate action [message #219474 is a reply to message #219380] Fri, 20 February 2009 11:27 Go to previous message
Eclipse UserFriend
Originally posted by: thomas.beyer81.t-online.de

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@t-online.de> escribió en el mensaje
> news:gnk6l5$oea$1@build.eclipse.org...
>> 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.Duplicate EObjectsCommand;
>> import
>> org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElem entsRequest;
>>
>> /**
>> * 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());
>> }
>>
>> }
>
>
Previous Topic:Defining and instantiating shapes using GMF editor
Next Topic:Can't learn Eclipse GMF in 15 minutes
Goto Forum:
  


Current Time: Fri Feb 26 07:00:41 GMT 2021

Powered by FUDForum. Page generated in 0.01525 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top