Skip to main content



      Home
Home » Modeling » EMF » Customizing standard EMF editor Drag & Drop behavior
Customizing standard EMF editor Drag & Drop behavior [message #499037] Thu, 19 November 2009 10:44 Go to next message
Eclipse UserFriend
Hi,

I would like to change the EMF editors "standard D&D behavior" as follows:

I have an ecore model which contains two classes: EObjectA and EObjectB. EObjectA has a non-containment reference to EObjectB.

I would like to allow user to drag an instance of EObjectB over EObjectA and drop it and set the non-containment reference from instance of EObjectA to EObjectB.

By default it is not possible to drag and drop objects to another without containment reference defined.... As far as I have got it right.

Can anyone help me?

Re: Customizing standard EMF editor Drag & Drop behavior [message #499069 is a reply to message #499037] Thu, 19 November 2009 12:27 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jan,

I think what you are looking for is in your generated Editor class the method
createContextMenuFor(StructuredViewer viewer)


That method is responsible for hooking the DND support of your Editor.
You can add your custom DropAdapter and add the drop functionality you want for your objects in there.

Best regards,
Artur


Jan Landen wrote on Thu, 19 November 2009 10:44
Hi,

I would like to change the EMF editors "standard D&D behavior" as follows:

I have an ecore model which contains two classes: EObjectA and EObjectB. EObjectA has a non-containment reference to EObjectB.

I would like to allow user to drag an instance of EObjectB over EObjectA and drop it and set the non-containment reference from instance of EObjectA to EObjectB.

By default it is not possible to drag and drop objects to another without containment reference defined.... As far as I have got it right.

Can anyone help me?



Re: Customizing standard EMF editor Drag & Drop behavior [message #499094 is a reply to message #499069] Thu, 19 November 2009 14:34 Go to previous messageGo to next message
Eclipse UserFriend
Thank you Artur,

Yes, I thought that the generated editors
createContextMenuFor(StructuredViewer viewer)
method was the correct place to modify in order to have customized D&D behavior.

I tried to override some methods of
EditingDomainViewerDropAdapter
- class, but I really can not figure out how to actually enable dragging objects to non-containment reference.

I would appriciate a lot if you could help me a bit more how to actually do the job (which methods I need to overwrite etc.). Or if you have any code to demonstrate the thing it would be even better...

Thank you,

Best Regards,
Jan
Re: Customizing standard EMF editor Drag & Drop behavior [message #499098 is a reply to message #499094] Thu, 19 November 2009 15:17 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jan,

First, what exactly is a non-containment reference? The way I understood it you wanted to drop an EObject A over a different EObject Band in that way change one (or more) atributes that EObject B has?

I overwrote the:
EditingDomainViewerDropAdapter


and in there I overwrote this methods:
public void dragEnter(DropTargetEvent event)
public void dragOver(DropTargetEvent event)
public void drop(DropTargetEvent event)
protected Collection<?> extractDragSource(Object object)


What should be the most important is the extractDragSource. The other methods are basically just for user interaction (showing if dropping is possible or not).
So the extracting of the drag source is the key of dropping something over your eObject and in that way adding a new Object in the tree. For example if you wanted to have B as a Child of A you coudl drop B on A and it would appear there.

If you don't want to create children you need to overwrite the drop method a little bit more:

So the basic implementation of the drop method is creating a drop command which would add a new child into the tree (if i remember correctly). If you just want to change something on the diagram you are dropping on, you need to overwrite the drop command in a way that it would create e.g. a SetCommand that would set an atribute of your EObject (or more then one Command to modify more then one atribute).

Again, I am not completely sure what you are trying to do, so if that does not answere your question completely feel free to write and I will give it another shot Wink

Best,
Artur

Jan Landen wrote on Thu, 19 November 2009 14:34
Thank you Artur,

Yes, I thought that the generated editors
createContextMenuFor(StructuredViewer viewer)
method was the correct place to modify in order to have customized D&D behavior.

I tried to override some methods of
EditingDomainViewerDropAdapter
- class, but I really can not figure out how to actually enable dragging objects to non-containment reference.

I would appriciate a lot if you could help me a bit more how to actually do the job (which methods I need to overwrite etc.). Or if you have any code to demonstrate the thing it would be even better...

Thank you,

Best Regards,
Jan

Re: Customizing standard EMF editor Drag & Drop behavior [message #499120 is a reply to message #499098] Thu, 19 November 2009 18:12 Go to previous messageGo to next message
Eclipse UserFriend
Guys,

I think it's as simple as specializing the BItemProviderAdapter's
getChildFeature so that it returns the appropriate feature for B to
reference an A instance. If that returns non null, you should be able
to create a link..


Artur Kronenberg wrote:
> Hi Jan,
>
> First, what exactly is a non-containment reference? The way I
> understood it you wanted to drop an EObject A over a different EObject
> Band in that way change one (or more) atributes that EObject B has?
> I overwrote the:
> EditingDomainViewerDropAdapter
>
> and in there I overwrote this methods:
>
> public void dragEnter(DropTargetEvent event)
> public void dragOver(DropTargetEvent event)
> public void drop(DropTargetEvent event)
> protected Collection<?> extractDragSource(Object object)
>
>
> What should be the most important is the extractDragSource. The other
> methods are basically just for user interaction (showing if dropping
> is possible or not).
> So the extracting of the drag source is the key of dropping something
> over your eObject and in that way adding a new Object in the tree. For
> example if you wanted to have B as a Child of A you coudl drop B on A
> and it would appear there.
>
> If you don't want to create children you need to overwrite the drop
> method a little bit more:
>
> So the basic implementation of the drop method is creating a drop
> command which would add a new child into the tree (if i remember
> correctly). If you just want to change something on the diagram you
> are dropping on, you need to overwrite the drop command in a way that
> it would create e.g. a SetCommand that would set an atribute of your
> EObject (or more then one Command to modify more then one atribute).
> Again, I am not completely sure what you are trying to do, so if that
> does not answere your question completely feel free to write and I
> will give it another shot ;)
> Best,
> Artur
>
> Jan Landen wrote on Thu, 19 November 2009 14:34
>> Thank you Artur,
>>
>> Yes, I thought that the generated editors
>> createContextMenuFor(StructuredViewer viewer) method was the correct
>> place to modify in order to have customized D&D behavior.
>>
>> I tried to override some methods of EditingDomainViewerDropAdapter -
>> class, but I really can not figure out how to actually enable
>> dragging objects to non-containment reference.
>>
>> I would appriciate a lot if you could help me a bit more how to
>> actually do the job (which methods I need to overwrite etc.). Or if
>> you have any code to demonstrate the thing it would be even better...
>>
>> Thank you,
>>
>> Best Regards,
>> Jan
>
>
Re: Customizing standard EMF editor Drag & Drop behavior [message #499167 is a reply to message #499120] Fri, 20 November 2009 04:08 Go to previous message
Eclipse UserFriend
Hello Artur, Ed,

Thanks a lot guys! I'll try this right away...

Regards,
Jan


Ed Merks wrote on Thu, 19 November 2009 18:12
Guys,

I think it's as simple as specializing the BItemProviderAdapter's
getChildFeature so that it returns the appropriate feature for B to
reference an A instance. If that returns non null, you should be able
to create a link..


Artur Kronenberg wrote:
> Hi Jan,
>
> First, what exactly is a non-containment reference? The way I
> understood it you wanted to drop an EObject A over a different EObject
> Band in that way change one (or more) atributes that EObject B has?
> I overwrote the:
> EditingDomainViewerDropAdapter
>
> and in there I overwrote this methods:
>
> public void dragEnter(DropTargetEvent event)
> public void dragOver(DropTargetEvent event)
> public void drop(DropTargetEvent event)
> protected Collection<?> extractDragSource(Object object)
>
>
> What should be the most important is the extractDragSource. The other
> methods are basically just for user interaction (showing if dropping
> is possible or not).
> So the extracting of the drag source is the key of dropping something
> over your eObject and in that way adding a new Object in the tree. For
> example if you wanted to have B as a Child of A you coudl drop B on A
> and it would appear there.
>
> If you don't want to create children you need to overwrite the drop
> method a little bit more:
>
> So the basic implementation of the drop method is creating a drop
> command which would add a new child into the tree (if i remember
> correctly). If you just want to change something on the diagram you
> are dropping on, you need to overwrite the drop command in a way that
> it would create e.g. a SetCommand that would set an atribute of your
> EObject (or more then one Command to modify more then one atribute).
> Again, I am not completely sure what you are trying to do, so if that
> does not answere your question completely feel free to write and I
> will give it another shot Wink
> Best,
> Artur
>
> Jan Landen wrote on Thu, 19 November 2009 14:34
>> Thank you Artur,
>>
>> Yes, I thought that the generated editors
>> createContextMenuFor(StructuredViewer viewer) method was the correct
>> place to modify in order to have customized D&D behavior.
>>
>> I tried to override some methods of EditingDomainViewerDropAdapter -
>> class, but I really can not figure out how to actually enable
>> dragging objects to non-containment reference.
>>
>> I would appriciate a lot if you could help me a bit more how to
>> actually do the job (which methods I need to overwrite etc.). Or if
>> you have any code to demonstrate the thing it would be even better...
>>
>> Thank you,
>>
>> Best Regards,
>> Jan
>
>

Previous Topic:[CDO] how to register package ?
Next Topic:EMF 2.2 missing OPTION_ELEMENT_HANDLER
Goto Forum:
  


Current Time: Sat Nov 08 00:02:59 EST 2025

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

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

Back to the top