Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » DragAndDropCommand move objects between different owners
DragAndDropCommand move objects between different owners [message #1272822] Tue, 18 March 2014 21:23 Go to next message
Dmitry Spiridenok is currently offline Dmitry SpiridenokFriend
Messages: 12
Registered: August 2011
Junior Member
I'm trying to understand how org.eclipse.emf.edit.command.DragAndDropCommand class works.

I have the following EMF model:

Application
____|-> Node Element A
_______|-> Leaf Element 1
_______|-> Leaf Element 2
____|
____|-> Node Element B
_______|-> Leaf Element 10

What I would like is to move ("reparent") "Leaf Element 10" object from "Node Element B" to "Node Element A" in my Java code .
I can do that by creating 2 EMF commands for that:
    Command cmd = RemoveCommand.create(domain, NodeElement_B_Object, feature, LeafElement10Object);
    Command cmd = AddCommand.create(domain, NodeElement_A_Object, feature, LeafElement10Object, 0);

What I would like is move the object in 1 command, something like that:
    List coll = new ArrayList();
    coll.add(LeafElement10Object);
    Command cmd = DragAndDropCommand.create(domain, NodeElement_A_Object, 0.0F, DragAndDropFeedback.DROP_MOVE, DragAndDropFeedback.DROP_MOVE, coll);

However the drag&drop command canExecute() method returns false and the command does not get executed.
After some basic debugging of the class I see that prepare*() methods retrieve the parent of the owner object provided to the class (in my case the parent of "Node Element B" which is "Application") and try to operate on the parent instead of the owner object itself.

I've also read the Javadoc of the DragAndDropCommand class but it did not make it more clear to me how to work with this class.

So could you please tell me how I can perform such a model object move between different parents using an EMF command?
Also real-life examples on how to use DragAndDropCommand would be appreciated.

I'm new to EMF so I would really appreciate any support on this topic. Thank you in advance!

P.S. I've tried to use MoveCommand for that but as far as I can understand it moves only objects within a single owner object (in my example it would be moving "Leaf Element 1" to another location within "Node Element A" which is not what I want).
Re: DragAndDropCommand move objects between different owners [message #1272871 is a reply to message #1272822] Wed, 19 March 2014 00:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Dimitry,

Drag and drop command is really intended to deal with drag and drop
behavior in a UI. For what you describe, you should just use a compound
command that composes the basic things you want to do in the model,
i.e., a remove followed by and add rather than try to figure out what
magical arguments will make a drag and drop command do that same thing
under the covers.


On 18/03/2014 2:23 PM, Dmitry Spiridenok wrote:
> I'm trying to understand how
> org.eclipse.emf.edit.command.DragAndDropCommand class works.
>
> I have the following EMF model:
>
> Application
> ____|-> Node Element A
> _______|-> Leaf Element 1
> _______|-> Leaf Element 2
> ____|
> ____|-> Node Element B
> _______|-> Leaf Element 10
> What I would like is to move ("reparent") "Leaf Element 10"
> object from "Node Element B" to "Node Element A" in my Java code .
> I can do that by creating 2 EMF commands for that:
> Command cmd = RemoveCommand.create(domain, NodeElement_B_Object,
> feature, LeafElement10Object);
> Command cmd = AddCommand.create(domain, NodeElement_A_Object,
> feature, LeafElement10Object, 0);
> What I would like is move the object in 1 command, something like that:
> List coll = new ArrayList();
> coll.add(LeafElement10Object);
> Command cmd = DragAndDropCommand.create(domain,
> NodeElement_A_Object, 0.0F, DragAndDropFeedback.DROP_MOVE,
> DragAndDropFeedback.DROP_MOVE, coll);
>
> However the drag&drop command canExecute() method returns false and
> the command does not get executed.
> After some basic debugging of the class I see that prepare*() methods
> retrieve the parent of the owner object provided to the class (in my
> case the parent of "Node Element B" which is "Application") and try to
> operate on the parent instead of the owner object itself.
>
> I've also read the Javadoc of the DragAndDropCommand class but it did
> not make it more clear to me how to work with this class.
>
> So could you please tell me how I can perform such a model object move
> between different parents using an EMF command?
> Also real-life examples on how to use DragAndDropCommand would be
> appreciated.
>
> I'm new to EMF so I would really appreciate any support on this topic.
> Thank you in advance!
>
> P.S. I've tried to use MoveCommand for that but as far as I can
> understand it moves only objects within a single owner object (in my
> example it would be moving "Leaf Element 1" to another location within
> "Node Element A" which is not what I want).


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: DragAndDropCommand move objects between different owners [message #1273269 is a reply to message #1272871] Wed, 19 March 2014 20:22 Go to previous message
Dmitry Spiridenok is currently offline Dmitry SpiridenokFriend
Messages: 12
Registered: August 2011
Junior Member
Ed, many thanks for your reply! I'll try to create a compound command for both remove and add actions for my elements.
Previous Topic:EAttribute to Java datatype
Next Topic:Root element changed after saving model
Goto Forum:
  


Current Time: Thu Apr 25 10:49:43 GMT 2024

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

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

Back to the top