Home » Modeling » GMF (Graphical Modeling Framework) » Drag'n drop between multiple GMF editors
Drag'n drop between multiple GMF editors [message #121064] |
Sun, 22 April 2007 08:40  |
Eclipse User |
|
|
|
Originally posted by: dimos.bekas.gmail.com
Dear all,
I have created two GMF editors that implement the same ecore model.
I would like to drag and drop elements from one editor to the other.
Following previous posts, I have implemented a dropListener that extends
the DiagramDropTargetListener and also install an edit policy. However, this
does not work and I am not allowed to drop the element to the second editor.
Can you please give me a hand?
Thanks
|
|
| | |
Re: Drag'n drop between multiple GMF editors [message #122048 is a reply to message #122035] |
Thu, 26 April 2007 14:45   |
Eclipse User |
|
|
|
Originally posted by: atoulme.intalio.com
Vlad,
you are talking about the drag of a view ? Meaning a view in the same
editor ? In that case the implementation is very different.
You should make sure there is a DragSourceAdapter installed on the
source editor and an edit policy with the DRAG_DROP_ROLE installed on
the diagram of the other editor. That's a minimum, you might want to
have an edit policy with a DRAG_DROP_ROLE for each of your shapes,
depending of how the drop is handled.
Hope this helps.
Antoine
Vlad Vergu wrote:
> He is trying to do a copy.
> The goal is to be able to drag a node from an open gmf editor to another
> open gmf editor. The two diagrams have the same underlying models.
>
> I have managed to get the editor accept a transfer from a view, but not from
> another gmf editor. I think the problem is with the DragSource. I assumed
> that the DragSource is already defined and i need only worry about the
> DropTarget. Is this correct? Can somebody please provide some code for how
> this is supposed to work?
>
> Thanks for your help.
>
> Vlad
>
> "Antoine Toulme" <atoulme@intalio.com> wrote in message
> news:f0o9ga$f1r$1@build.eclipse.org...
>> What exactly is not working ?
>> Do you have a log or something ?
>>
>> What are you trying to do ? A copy or a cut ?
>>
>> 1. Try to set the requiredDetail of the dropRequest to DND.COPY in the
>> DropTargetListener. By default the requiredDetail of the request is not
>> high enough to allow the drop.
>> 2. Keep in mind that the objects are in two different edit domains. You
>> have to open a transaction of the two editing domains simultaneously to do
>> the drop.
>>
>> DnD is not easy. You might want to be a bit more incremental : make sure
>> you can simulate a drag and drop by doing two actions, one drag the other
>> drop. When this works perfectly, you can go crazy with the DnD
>> interactions themselves.
>>
>> We implemented a mechanism to do DnD on the STP BPMN modeler.
>>
>> Here is our listener:
>>
>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.stp.bpm n/org.eclipse.stp.bpmn.diagram/customsrc/org/eclipse/stp/bpm n/dnd/GenericEAnnotationDropTargetListener.java?revision=1.4 &root=STP_Project&view=markup
>>
>> Good luck !
>>
>> Antoine
>>
>> Dimosthenis wrote:
>>> Dear all,
>>>
>>> I have created two GMF editors that implement the same ecore model.
>>> I would like to drag and drop elements from one editor to the other.
>>>
>>> Following previous posts, I have implemented a dropListener that extends
>>> the DiagramDropTargetListener and also install an edit policy. However,
>>> this
>>> does not work and I am not allowed to drop the element to the second
>>> editor.
>>>
>>> Can you please give me a hand?
>>>
>>> Thanks
>
>
--
Intalio, the Open Source BPMS Company
<a href="http://www.intalio.com">http://www.intalio.com</a>
<a href="http://bpms.intalio.com">Community website</a>
|
|
|
Re: Drag'n drop between multiple GMF editors [message #122074 is a reply to message #122048] |
Thu, 26 April 2007 19:06   |
Eclipse User |
|
|
|
Originally posted by: v.vergu.gmail.com
Thanks Antoine. I'll try it and get back to you tomorrow.
"Antoine Toulme" <atoulme@intalio.com> wrote in message
news:f0qs0j$pf2$1@build.eclipse.org...
> Vlad,
> you are talking about the drag of a view ? Meaning a view in the same
> editor ? In that case the implementation is very different.
>
> You should make sure there is a DragSourceAdapter installed on the source
> editor and an edit policy with the DRAG_DROP_ROLE installed on the diagram
> of the other editor. That's a minimum, you might want to have an edit
> policy with a DRAG_DROP_ROLE for each of your shapes, depending of how the
> drop is handled.
>
> Hope this helps.
>
> Antoine
>
> Vlad Vergu wrote:
>> He is trying to do a copy.
>> The goal is to be able to drag a node from an open gmf editor to another
>> open gmf editor. The two diagrams have the same underlying models.
>>
>> I have managed to get the editor accept a transfer from a view, but not
>> from another gmf editor. I think the problem is with the DragSource. I
>> assumed that the DragSource is already defined and i need only worry
>> about the DropTarget. Is this correct? Can somebody please provide some
>> code for how this is supposed to work?
>>
>> Thanks for your help.
>>
>> Vlad
>>
>> "Antoine Toulme" <atoulme@intalio.com> wrote in message
>> news:f0o9ga$f1r$1@build.eclipse.org...
>>> What exactly is not working ?
>>> Do you have a log or something ?
>>>
>>> What are you trying to do ? A copy or a cut ?
>>>
>>> 1. Try to set the requiredDetail of the dropRequest to DND.COPY in the
>>> DropTargetListener. By default the requiredDetail of the request is not
>>> high enough to allow the drop.
>>> 2. Keep in mind that the objects are in two different edit domains. You
>>> have to open a transaction of the two editing domains simultaneously to
>>> do the drop.
>>>
>>> DnD is not easy. You might want to be a bit more incremental : make sure
>>> you can simulate a drag and drop by doing two actions, one drag the
>>> other drop. When this works perfectly, you can go crazy with the DnD
>>> interactions themselves.
>>>
>>> We implemented a mechanism to do DnD on the STP BPMN modeler.
>>>
>>> Here is our listener:
>>>
>>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.stp.bpm n/org.eclipse.stp.bpmn.diagram/customsrc/org/eclipse/stp/bpm n/dnd/GenericEAnnotationDropTargetListener.java?revision=1.4 &root=STP_Project&view=markup
>>>
>>> Good luck !
>>>
>>> Antoine
>>>
>>> Dimosthenis wrote:
>>>> Dear all,
>>>>
>>>> I have created two GMF editors that implement the same ecore model.
>>>> I would like to drag and drop elements from one editor to the other.
>>>>
>>>> Following previous posts, I have implemented a dropListener that
>>>> extends
>>>> the DiagramDropTargetListener and also install an edit policy. However,
>>>> this
>>>> does not work and I am not allowed to drop the element to the second
>>>> editor.
>>>>
>>>> Can you please give me a hand?
>>>>
>>>> Thanks
>>
>>
>
>
> --
> Intalio, the Open Source BPMS Company
>
> <a href="http://www.intalio.com">http://www.intalio.com</a>
> <a href="http://bpms.intalio.com">Community website</a>
|
|
|
Re: Drag'n drop between multiple GMF editors [message #122123 is a reply to message #122074] |
Fri, 27 April 2007 05:40   |
Eclipse User |
|
|
|
Originally posted by: v.vergu.gmail.com
Hi. I've done some things and it still doesn't work. I'm going to first
explain again what i want to do, then tell you what i did.
To avoid complications i've got a very simple ecore model and then generated
the diagram from it. It draws either a rectangle or a connection between two
rectangles. The requirement is that if i open two editors for two distinct
diagram files (with the editors from the same plugin) i can drag a rectangle
from one to the other. After your post i've tried the things you
recommended.
I created two classes: ExTransferDragSourceListener extends
AbstractTransferDragSourceListener and public class
ExTransferDropTargetListener extends AbstractTransferDropTargetListener.
Then i added these to the ModelDiagramEditor like so:
@Override
protected void initializeGraphicalViewer() {
super.initializeGraphicalViewer();
getGraphicalViewer().addDragSourceListener(new
ExTransferDragSourceListener(getGraphicalViewer()));
getGraphicalViewer().addDropTargetListener(new
ExTransferDropTargetListener(getGraphicalViewer()));
}
Then, i installed a DRAG_DROP_ROLE policy on the RectangularShapeEditPart
(the one that i want to drag about). The method now looks like this:
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
new RectangularShapeItemSemanticEditPolicy());
installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,new DragDropEditPolicy());
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE,
new RectangularShapeGraphicalNodeEditPolicy());
installEditPolicy(EditPolicyRoles.CANONICAL_ROLE,
new RectangularShapeCanonicalEditPolicy());
installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
}
The problems are as follows:
1. It seems that something i've done replaces the listener that the
editor has from it's factory. Without the listeners added, when i drag a
node around in the editor, the shape follows the mouse (shaded out).
However, after i add the listeners, this doesn't happen. Moving a node
withing it's editor works slower than before.
2. If I try to drag a node outside it's editor it doesn't do anything.
It just keeps trying to follow the mouse, but within it's editor.
3. Also, if there are no listeners added and i try to drag the node our
of the editor, i get the usual mouse cursor with a crossed out circle. This
is why i was left with the impression (actually more like hoping) that a
DropListener would be sufficient. After i add the listeners as described
above and below the mouse cursor gives no indication of a drag.
Please help, my project manager has been breathing down my neck to get this
figured out! What am i not seeing, except for everything? The transfer type
that i use is
org.eclipse.gmf.runtime.common.ui.services.dnd.core.Selectio nTransfer. Could
this be screwing things up? Any other ideas?
Thanks.
public class ExTransferDragSourceListener extends
AbstractTransferDragSourceListener {
public ExTransferDragSourceListener(EditPartViewer arg0) {
super(arg0, SelectionTransfer.getInstance());
System.out.println("1");
// TODO Auto-generated constructor stub
}
public ExTransferDragSourceListener(EditPartViewer arg0, Transfer arg1) {
super(arg0, arg1);
System.out.println("2");
// TODO Auto-generated constructor stub
}
public void dragSetData(DragSourceEvent event) {
// TODO Auto-generated method stub
System.out.println("Set data .. "
+ getViewer().getSelectedEditParts().get(0).getClass()
..toString());
}
@Override
public void dragStart(DragSourceEvent arg0) {
System.out.println("Starting drag... "
+ getViewer().getSelectedEditParts().get(0).getClass()
..toString());
super.dragStart(arg0);
}
--------
public class ExTransferDropTargetListener extends
AbstractTransferDropTargetListener {
public ExTransferDropTargetListener(EditPartViewer arg0) {
super(arg0, SelectionTransfer.getInstance());
System.out.println("5");
// TODO Auto-generated constructor stub
}
public ExTransferDropTargetListener(EditPartViewer arg0, Transfer arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
}
@Override
protected void updateTargetRequest() {
// TODO Auto-generated method stub
System.err.println("UpdatingTargetRequest");
}
@Override
protected Request createTargetRequest() {
// TODO Auto-generated method stub
System.err.println("CreatingTargetRequest");
return super.createTargetRequest();
}
@Override
protected void handleDragOver() {
System.err.println("You're on top of me!!!");
super.handleDragOver();
}
@Override
protected void handleDrop() {
System.err.println("Ouch!!! That hurts");
super.handleDrop();
}
@Override
public void drop(DropTargetEvent arg0) {
// TODO Auto-generated method stub
System.err.println("Ouch!!! That hurts");
super.drop(arg0);
}
@Override
protected void handleHover() {
System.err.println("You're on top of me!!!");
super.handleHover();
}
}
"Vlad Vergu" <v.vergu@gmail.com> wrote in message
news:f0rba6$jbm$1@build.eclipse.org...
> Thanks Antoine. I'll try it and get back to you tomorrow.
>
> "Antoine Toulme" <atoulme@intalio.com> wrote in message
> news:f0qs0j$pf2$1@build.eclipse.org...
>> Vlad,
>> you are talking about the drag of a view ? Meaning a view in the same
>> editor ? In that case the implementation is very different.
>>
>> You should make sure there is a DragSourceAdapter installed on the source
>> editor and an edit policy with the DRAG_DROP_ROLE installed on the
>> diagram of the other editor. That's a minimum, you might want to have an
>> edit policy with a DRAG_DROP_ROLE for each of your shapes, depending of
>> how the drop is handled.
>>
>> Hope this helps.
>>
>> Antoine
>>
>> Vlad Vergu wrote:
>>> He is trying to do a copy.
>>> The goal is to be able to drag a node from an open gmf editor to another
>>> open gmf editor. The two diagrams have the same underlying models.
>>>
>>> I have managed to get the editor accept a transfer from a view, but not
>>> from another gmf editor. I think the problem is with the DragSource. I
>>> assumed that the DragSource is already defined and i need only worry
>>> about the DropTarget. Is this correct? Can somebody please provide some
>>> code for how this is supposed to work?
>>>
>>> Thanks for your help.
>>>
>>> Vlad
>>>
>>> "Antoine Toulme" <atoulme@intalio.com> wrote in message
>>> news:f0o9ga$f1r$1@build.eclipse.org...
>>>> What exactly is not working ?
>>>> Do you have a log or something ?
>>>>
>>>> What are you trying to do ? A copy or a cut ?
>>>>
>>>> 1. Try to set the requiredDetail of the dropRequest to DND.COPY in the
>>>> DropTargetListener. By default the requiredDetail of the request is not
>>>> high enough to allow the drop.
>>>> 2. Keep in mind that the objects are in two different edit domains. You
>>>> have to open a transaction of the two editing domains simultaneously to
>>>> do the drop.
>>>>
>>>> DnD is not easy. You might want to be a bit more incremental : make
>>>> sure you can simulate a drag and drop by doing two actions, one drag
>>>> the other drop. When this works perfectly, you can go crazy with the
>>>> DnD interactions themselves.
>>>>
>>>> We implemented a mechanism to do DnD on the STP BPMN modeler.
>>>>
>>>> Here is our listener:
>>>>
>>>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.stp.bpm n/org.eclipse.stp.bpmn.diagram/customsrc/org/eclipse/stp/bpm n/dnd/GenericEAnnotationDropTargetListener.java?revision=1.4 &root=STP_Project&view=markup
>>>>
>>>> Good luck !
>>>>
>>>> Antoine
>>>>
>>>> Dimosthenis wrote:
>>>>> Dear all,
>>>>>
>>>>> I have created two GMF editors that implement the same ecore model.
>>>>> I would like to drag and drop elements from one editor to the other.
>>>>>
>>>>> Following previous posts, I have implemented a dropListener that
>>>>> extends
>>>>> the DiagramDropTargetListener and also install an edit policy.
>>>>> However, this
>>>>> does not work and I am not allowed to drop the element to the second
>>>>> editor.
>>>>>
>>>>> Can you please give me a hand?
>>>>>
>>>>> Thanks
>>>
>>>
>>
>>
>> --
>> Intalio, the Open Source BPMS Company
>>
>> <a href="http://www.intalio.com">http://www.intalio.com</a>
>> <a href="http://bpms.intalio.com">Community website</a>
>
>
|
|
|
Re: Drag'n drop between multiple GMF editors [message #123027 is a reply to message #122123] |
Mon, 30 April 2007 17:15   |
Eclipse User |
|
|
|
Originally posted by: atoulme.intalio.com
Hi Vlad,
Vlad Vergu wrote:
> Hi. I've done some things and it still doesn't work. I'm going to first
> explain again what i want to do, then tell you what i did.
> To avoid complications i've got a very simple ecore model and then generated
> the diagram from it. It draws either a rectangle or a connection between two
> rectangles. The requirement is that if i open two editors for two distinct
> diagram files (with the editors from the same plugin) i can drag a rectangle
> from one to the other. After your post i've tried the things you
> recommended.
>
> I created two classes: ExTransferDragSourceListener extends
> AbstractTransferDragSourceListener and public class
> ExTransferDropTargetListener extends AbstractTransferDropTargetListener.
> Then i added these to the ModelDiagramEditor like so:
> @Override
>
> protected void initializeGraphicalViewer() {
>
> super.initializeGraphicalViewer();
>
> getGraphicalViewer().addDragSourceListener(new
> ExTransferDragSourceListener(getGraphicalViewer()));
>
> getGraphicalViewer().addDropTargetListener(new
> ExTransferDropTargetListener(getGraphicalViewer()));
>
> }
>
>
this is good.
>
> Then, i installed a DRAG_DROP_ROLE policy on the RectangularShapeEditPart
> (the one that i want to drag about). The method now looks like this:
>
> protected void createDefaultEditPolicies() {
>
> super.createDefaultEditPolicies();
>
> installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
>
> new RectangularShapeItemSemanticEditPolicy());
>
> installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,new DragDropEditPolicy());
This is less like it. The DnD policy should be applied to the container
of the shape. And instead of the DragDropEditPolicy, you should use the
DiagramDragDropEditPolicy. The dragDropEditPolicy is necessary to move
shapes around and reparent them.
>
> installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE,
>
> new RectangularShapeGraphicalNodeEditPolicy());
>
> installEditPolicy(EditPolicyRoles.CANONICAL_ROLE,
>
> new RectangularShapeCanonicalEditPolicy());
>
> installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
>
> }
>
> The problems are as follows:
>
> 1. It seems that something i've done replaces the listener that the
> editor has from it's factory. Without the listeners added, when i drag a
> node around in the editor, the shape follows the mouse (shaded out).
> However, after i add the listeners, this doesn't happen. Moving a node
> withing it's editor works slower than before.
I did not implement a drag source on an editor, so I cannot really help
you there. Normally, it should just put the current selection in
LocalSelectionTransfer. You might want to make sure that it is not
repeating the operation every time by checking that the members of the
selection are still the same as what you want to drag.
>
> 2. If I try to drag a node outside it's editor it doesn't do anything.
> It just keeps trying to follow the mouse, but within it's editor.
>
> 3. Also, if there are no listeners added and i try to drag the node our
> of the editor, i get the usual mouse cursor with a crossed out circle. This
> is why i was left with the impression (actually more like hoping) that a
> DropListener would be sufficient. After i add the listeners as described
> above and below the mouse cursor gives no indication of a drag.
I have no idea about that, as depicted above.
>
>
>
> Please help, my project manager has been breathing down my neck to get this
> figured out!
You know that implementing the DnD won't change that problem. You might
need to consider changing your manager expectations, so that he
understands that you are not doing some basic stuff here.
Good luck on that !
What am i not seeing, except for everything? The transfer type
> that i use is
>
> org.eclipse.gmf.runtime.common.ui.services.dnd.core.Selectio nTransfer. Could
> this be screwing things up? Any other ideas?
Just try using LocalSelectionTransfer.getInstance(). It's working for us.
Here is our implementation of DropTargetListener, it's quite simple to
build over DiagramDropTargetListener:
/**
* Listener taking the localSelectionTransfer selection
* and giving it to the superclass to form the DropObjectsRequest.
* @author <a href="mailto:atoulme@intalio.com">Antoine Toulm?</a>
* @author <a href="http://www.intalio.com">© Intalio, Inc.</a>
*/
public class BpmnDropTargetListener extends
DiagramDropTargetListener {
public BpmnDropTargetListener(EditPartViewer viewer) {
super(viewer, LocalSelectionTransfer.getInstance());
}
/* (non-Javadoc)
* @see
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramDropTargetLi stener#getObjectsBeingDropped()
*/
@SuppressWarnings("unchecked")
@Override
protected List getObjectsBeingDropped() {
ISelection selection =
LocalSelectionTransfer.getInstance().getSelection();
if (selection instanceof IStructuredSelection) {
return ((IStructuredSelection) selection).toList();
}
return null;
}
/* (non-Javadoc)
* @see
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramDropTargetLi stener#createTargetRequest()
*/
/**
* Overrides the default request creation by adding it a MOVE operation
* in case that the selection is valid.
* FIXME if only I knew why this is needed !!!!!
*/
@Override
protected Request createTargetRequest() {
DropObjectsRequest req = (DropObjectsRequest) super.createTargetRequest();
req.setRequiredDetail(DND.DROP_COPY);
return req;
}
}
>
> Thanks.
>
>
> public class ExTransferDragSourceListener extends
>
> AbstractTransferDragSourceListener {
>
>
> public ExTransferDragSourceListener(EditPartViewer arg0) {
>
>
> super(arg0, SelectionTransfer.getInstance());
>
> System.out.println("1");
>
> // TODO Auto-generated constructor stub
>
> }
>
>
> public ExTransferDragSourceListener(EditPartViewer arg0, Transfer arg1) {
>
>
> super(arg0, arg1);
>
> System.out.println("2");
>
> // TODO Auto-generated constructor stub
>
> }
>
>
> public void dragSetData(DragSourceEvent event) {
>
> // TODO Auto-generated method stub
>
> System.out.println("Set data .. "
>
> + getViewer().getSelectedEditParts().get(0).getClass()
>
> .toString());
>
> }
>
>
> @Override
>
> public void dragStart(DragSourceEvent arg0) {
>
> System.out.println("Starting drag... "
>
> + getViewer().getSelectedEditParts().get(0).getClass()
>
> .toString());
>
> super.dragStart(arg0);
>
> }
>
> --------
>
> public class ExTransferDropTargetListener extends
>
> AbstractTransferDropTargetListener {
>
>
> public ExTransferDropTargetListener(EditPartViewer arg0) {
>
> super(arg0, SelectionTransfer.getInstance());
>
> System.out.println("5");
>
> // TODO Auto-generated constructor stub
>
> }
>
>
> public ExTransferDropTargetListener(EditPartViewer arg0, Transfer arg1) {
>
> super(arg0, arg1);
>
> // TODO Auto-generated constructor stub
>
> }
>
>
> @Override
>
> protected void updateTargetRequest() {
>
> // TODO Auto-generated method stub
>
> System.err.println("UpdatingTargetRequest");
>
> }
>
>
> @Override
>
> protected Request createTargetRequest() {
>
> // TODO Auto-generated method stub
>
> System.err.println("CreatingTargetRequest");
>
> return super.createTargetRequest();
>
> }
>
>
> @Override
>
> protected void handleDragOver() {
>
> System.err.println("You're on top of me!!!");
>
> super.handleDragOver();
>
> }
>
>
> @Override
>
> protected void handleDrop() {
>
> System.err.println("Ouch!!! That hurts");
>
> super.handleDrop();
>
> }
>
>
> @Override
>
> public void drop(DropTargetEvent arg0) {
>
> // TODO Auto-generated method stub
>
> System.err.println("Ouch!!! That hurts");
>
> super.drop(arg0);
>
> }
>
>
> @Override
>
> protected void handleHover() {
>
> System.err.println("You're on top of me!!!");
>
> super.handleHover();
>
> }
>
>
>
> }
>
> "Vlad Vergu" <v.vergu@gmail.com> wrote in message
> news:f0rba6$jbm$1@build.eclipse.org...
>> Thanks Antoine. I'll try it and get back to you tomorrow.
>>
>> "Antoine Toulme" <atoulme@intalio.com> wrote in message
>> news:f0qs0j$pf2$1@build.eclipse.org...
>>> Vlad,
>>> you are talking about the drag of a view ? Meaning a view in the same
>>> editor ? In that case the implementation is very different.
>>>
>>> You should make sure there is a DragSourceAdapter installed on the source
>>> editor and an edit policy with the DRAG_DROP_ROLE installed on the
>>> diagram of the other editor. That's a minimum, you might want to have an
>>> edit policy with a DRAG_DROP_ROLE for each of your shapes, depending of
>>> how the drop is handled.
>>>
>>> Hope this helps.
>>>
>>> Antoine
>>>
>>> Vlad Vergu wrote:
>>>> He is trying to do a copy.
>>>> The goal is to be able to drag a node from an open gmf editor to another
>>>> open gmf editor. The two diagrams have the same underlying models.
>>>>
>>>> I have managed to get the editor accept a transfer from a view, but not
>>>> from another gmf editor. I think the problem is with the DragSource. I
>>>> assumed that the DragSource is already defined and i need only worry
>>>> about the DropTarget. Is this correct? Can somebody please provide some
>>>> code for how this is supposed to work?
>>>>
>>>> Thanks for your help.
>>>>
>>>> Vlad
>>>>
>>>> "Antoine Toulme" <atoulme@intalio.com> wrote in message
>>>> news:f0o9ga$f1r$1@build.eclipse.org...
>>>>> What exactly is not working ?
>>>>> Do you have a log or something ?
>>>>>
>>>>> What are you trying to do ? A copy or a cut ?
>>>>>
>>>>> 1. Try to set the requiredDetail of the dropRequest to DND.COPY in the
>>>>> DropTargetListener. By default the requiredDetail of the request is not
>>>>> high enough to allow the drop.
>>>>> 2. Keep in mind that the objects are in two different edit domains. You
>>>>> have to open a transaction of the two editing domains simultaneously to
>>>>> do the drop.
>>>>>
>>>>> DnD is not easy. You might want to be a bit more incremental : make
>>>>> sure you can simulate a drag and drop by doing two actions, one drag
>>>>> the other drop. When this works perfectly, you can go crazy with the
>>>>> DnD interactions themselves.
>>>>>
>>>>> We implemented a mechanism to do DnD on the STP BPMN modeler.
>>>>>
>>>>> Here is our listener:
>>>>>
>>>>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.stp.bpm n/org.eclipse.stp.bpmn.diagram/customsrc/org/eclipse/stp/bpm n/dnd/GenericEAnnotationDropTargetListener.java?revision=1.4 &root=STP_Project&view=markup
>>>>>
>>>>> Good luck !
>>>>>
>>>>> Antoine
>>>>>
>>>>> Dimosthenis wrote:
>>>>>> Dear all,
>>>>>>
>>>>>> I have created two GMF editors that implement the same ecore model.
>>>>>> I would like to drag and drop elements from one editor to the other.
>>>>>>
>>>>>> Following previous posts, I have implemented a dropListener that
>>>>>> extends
>>>>>> the DiagramDropTargetListener and also install an edit policy.
>>>>>> However, this
>>>>>> does not work and I am not allowed to drop the element to the second
>>>>>> editor.
>>>>>>
>>>>>> Can you please give me a hand?
>>>>>>
>>>>>> Thanks
>>>>
>>>
>>> --
>>> Intalio, the Open Source BPMS Company
>>>
>>> <a href="http://www.intalio.com">http://www.intalio.com</a>
>>> <a href="http://bpms.intalio.com">Community website</a>
>>
>
>
--
Intalio, the Open Source BPMS Company
<a href="http://www.intalio.com">http://www.intalio.com</a>
<a href="http://bpms.intalio.com">Community website</a>
|
|
|
Re: Drag'n drop between multiple GMF editors [message #123643 is a reply to message #123027] |
Thu, 03 May 2007 04:04  |
Eclipse User |
|
|
|
Originally posted by: v.vergu.gmail.com
Hi Antoine and everyone,
I've got a lead from someone on how to add a drag source in the editor. The
problem is that when the drag source listener is added the DragService (or
whatever is called) doesn't delegate move/resize operations to it's builtin
listener but to my custom one. The solution as described in this post:
http://dev.eclipse.org/newslists/news.eclipse.tools.gef/msg1 7362.html . It
describes using the modifier mask to distinguish between the different drag
operations and in turn between drag source listeners.
Checking for the modifier mask is spoken about here:
http://dev.eclipse.org/newslists/news.eclipse.platform.swt/m sg14369.html
I'm going to try this later today. If anyone has already done this or
something similar please post.
Vlad
"Antoine Toulme" <atoulme@intalio.com> wrote in message
news:f15ma2$jcj$1@build.eclipse.org...
> Hi Vlad,
> Vlad Vergu wrote:
>> Hi. I've done some things and it still doesn't work. I'm going to first
>> explain again what i want to do, then tell you what i did.
>> To avoid complications i've got a very simple ecore model and then
>> generated the diagram from it. It draws either a rectangle or a
>> connection between two rectangles. The requirement is that if i open two
>> editors for two distinct diagram files (with the editors from the same
>> plugin) i can drag a rectangle from one to the other. After your post
>> i've tried the things you recommended.
>>
>> I created two classes: ExTransferDragSourceListener extends
>> AbstractTransferDragSourceListener and public class
>> ExTransferDropTargetListener extends AbstractTransferDropTargetListener.
>> Then i added these to the ModelDiagramEditor like so:
>> @Override
>>
>> protected void initializeGraphicalViewer() {
>>
>> super.initializeGraphicalViewer();
>>
>> getGraphicalViewer().addDragSourceListener(new
>> ExTransferDragSourceListener(getGraphicalViewer()));
>>
>> getGraphicalViewer().addDropTargetListener(new
>> ExTransferDropTargetListener(getGraphicalViewer()));
>>
>> }
>>
>>
> this is good.
>>
>> Then, i installed a DRAG_DROP_ROLE policy on the RectangularShapeEditPart
>> (the one that i want to drag about). The method now looks like this:
>>
>> protected void createDefaultEditPolicies() {
>>
>> super.createDefaultEditPolicies();
>>
>> installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
>>
>> new RectangularShapeItemSemanticEditPolicy());
>>
>> installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,new
>> DragDropEditPolicy());
> This is less like it. The DnD policy should be applied to the container of
> the shape. And instead of the DragDropEditPolicy, you should use the
> DiagramDragDropEditPolicy. The dragDropEditPolicy is necessary to move
> shapes around and reparent them.
>>
>> installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE,
>>
>> new RectangularShapeGraphicalNodeEditPolicy());
>>
>> installEditPolicy(EditPolicyRoles.CANONICAL_ROLE,
>>
>> new RectangularShapeCanonicalEditPolicy());
>>
>> installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
>>
>> }
>>
>> The problems are as follows:
>>
>> 1. It seems that something i've done replaces the listener that the
>> editor has from it's factory. Without the listeners added, when i drag a
>> node around in the editor, the shape follows the mouse (shaded out).
>> However, after i add the listeners, this doesn't happen. Moving a node
>> withing it's editor works slower than before.
> I did not implement a drag source on an editor, so I cannot really help
> you there. Normally, it should just put the current selection in
> LocalSelectionTransfer. You might want to make sure that it is not
> repeating the operation every time by checking that the members of the
> selection are still the same as what you want to drag.
>>
>> 2. If I try to drag a node outside it's editor it doesn't do
>> anything. It just keeps trying to follow the mouse, but within it's
>> editor.
>>
>> 3. Also, if there are no listeners added and i try to drag the node
>> our of the editor, i get the usual mouse cursor with a crossed out
>> circle. This is why i was left with the impression (actually more like
>> hoping) that a DropListener would be sufficient. After i add the
>> listeners as described above and below the mouse cursor gives no
>> indication of a drag.
> I have no idea about that, as depicted above.
>>
>>
>>
>> Please help, my project manager has been breathing down my neck to get
>> this figured out!
> You know that implementing the DnD won't change that problem. You might
> need to consider changing your manager expectations, so that he
> understands that you are not doing some basic stuff here.
> Good luck on that !
> What am i not seeing, except for everything? The transfer type
>> that i use is
>>
>> org.eclipse.gmf.runtime.common.ui.services.dnd.core.Selectio nTransfer.
>> Could this be screwing things up? Any other ideas?
> Just try using LocalSelectionTransfer.getInstance(). It's working for us.
>
> Here is our implementation of DropTargetListener, it's quite simple to
> build over DiagramDropTargetListener:
> /**
> * Listener taking the localSelectionTransfer selection
> * and giving it to the superclass to form the DropObjectsRequest.
> * @author <a href="mailto:atoulme@intalio.com">Antoine Toulm?</a>
> * @author <a href="http://www.intalio.com">© Intalio, Inc.</a>
> */
> public class BpmnDropTargetListener extends
> DiagramDropTargetListener {
>
> public BpmnDropTargetListener(EditPartViewer viewer) {
> super(viewer, LocalSelectionTransfer.getInstance());
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gmf.runtime.diagram.ui.parts.DiagramDropTargetLi stener#getObjectsBeingDropped()
> */
> @SuppressWarnings("unchecked")
> @Override
> protected List getObjectsBeingDropped() {
> ISelection selection =
> LocalSelectionTransfer.getInstance().getSelection();
> if (selection instanceof IStructuredSelection) {
> return ((IStructuredSelection) selection).toList();
> }
> return null;
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gmf.runtime.diagram.ui.parts.DiagramDropTargetLi stener#createTargetRequest()
> */
> /**
> * Overrides the default request creation by adding it a MOVE operation
> * in case that the selection is valid.
> * FIXME if only I knew why this is needed !!!!!
> */
> @Override
> protected Request createTargetRequest() {
> DropObjectsRequest req = (DropObjectsRequest) super.createTargetRequest();
> req.setRequiredDetail(DND.DROP_COPY);
> return req;
> }
> }
>
>>
>> Thanks.
>>
>>
>> public class ExTransferDragSourceListener extends
>>
>> AbstractTransferDragSourceListener {
>>
>>
>> public ExTransferDragSourceListener(EditPartViewer arg0) {
>>
>>
>> super(arg0, SelectionTransfer.getInstance());
>>
>> System.out.println("1");
>>
>> // TODO Auto-generated constructor stub
>>
>> }
>>
>>
>> public ExTransferDragSourceListener(EditPartViewer arg0, Transfer arg1) {
>>
>>
>> super(arg0, arg1);
>>
>> System.out.println("2");
>>
>> // TODO Auto-generated constructor stub
>>
>> }
>>
>>
>> public void dragSetData(DragSourceEvent event) {
>>
>> // TODO Auto-generated method stub
>>
>> System.out.println("Set data .. "
>>
>> + getViewer().getSelectedEditParts().get(0).getClass()
>>
>> .toString());
>>
>> }
>>
>>
>> @Override
>>
>> public void dragStart(DragSourceEvent arg0) {
>>
>> System.out.println("Starting drag... "
>>
>> + getViewer().getSelectedEditParts().get(0).getClass()
>>
>> .toString());
>>
>> super.dragStart(arg0);
>>
>> }
>>
>> --------
>>
>> public class ExTransferDropTargetListener extends
>>
>> AbstractTransferDropTargetListener {
>>
>>
>> public ExTransferDropTargetListener(EditPartViewer arg0) {
>>
>> super(arg0, SelectionTransfer.getInstance());
>>
>> System.out.println("5");
>>
>> // TODO Auto-generated constructor stub
>>
>> }
>>
>>
>> public ExTransferDropTargetListener(EditPartViewer arg0, Transfer arg1) {
>>
>> super(arg0, arg1);
>>
>> // TODO Auto-generated constructor stub
>>
>> }
>>
>>
>> @Override
>>
>> protected void updateTargetRequest() {
>>
>> // TODO Auto-generated method stub
>>
>> System.err.println("UpdatingTargetRequest");
>>
>> }
>>
>>
>> @Override
>>
>> protected Request createTargetRequest() {
>>
>> // TODO Auto-generated method stub
>>
>> System.err.println("CreatingTargetRequest");
>>
>> return super.createTargetRequest();
>>
>> }
>>
>>
>> @Override
>>
>> protected void handleDragOver() {
>>
>> System.err.println("You're on top of me!!!");
>>
>> super.handleDragOver();
>>
>> }
>>
>>
>> @Override
>>
>> protected void handleDrop() {
>>
>> System.err.println("Ouch!!! That hurts");
>>
>> super.handleDrop();
>>
>> }
>>
>>
>> @Override
>>
>> public void drop(DropTargetEvent arg0) {
>>
>> // TODO Auto-generated method stub
>>
>> System.err.println("Ouch!!! That hurts");
>>
>> super.drop(arg0);
>>
>> }
>>
>>
>> @Override
>>
>> protected void handleHover() {
>>
>> System.err.println("You're on top of me!!!");
>>
>> super.handleHover();
>>
>> }
>>
>>
>>
>> }
>>
>> "Vlad Vergu" <v.vergu@gmail.com> wrote in message
>> news:f0rba6$jbm$1@build.eclipse.org...
>>> Thanks Antoine. I'll try it and get back to you tomorrow.
>>>
>>> "Antoine Toulme" <atoulme@intalio.com> wrote in message
>>> news:f0qs0j$pf2$1@build.eclipse.org...
>>>> Vlad,
>>>> you are talking about the drag of a view ? Meaning a view in the same
>>>> editor ? In that case the implementation is very different.
>>>>
>>>> You should make sure there is a DragSourceAdapter installed on the
>>>> source editor and an edit policy with the DRAG_DROP_ROLE installed on
>>>> the diagram of the other editor. That's a minimum, you might want to
>>>> have an edit policy with a DRAG_DROP_ROLE for each of your shapes,
>>>> depending of how the drop is handled.
>>>>
>>>> Hope this helps.
>>>>
>>>> Antoine
>>>>
>>>> Vlad Vergu wrote:
>>>>> He is trying to do a copy.
>>>>> The goal is to be able to drag a node from an open gmf editor to
>>>>> another open gmf editor. The two diagrams have the same underlying
>>>>> models.
>>>>>
>>>>> I have managed to get the editor accept a transfer from a view, but
>>>>> not from another gmf editor. I think the problem is with the
>>>>> DragSource. I assumed that the DragSource is already defined and i
>>>>> need only worry about the DropTarget. Is this correct? Can somebody
>>>>> please provide some code for how this is supposed to work?
>>>>>
>>>>> Thanks for your help.
>>>>>
>>>>> Vlad
>>>>>
>>>>> "Antoine Toulme" <atoulme@intalio.com> wrote in message
>>>>> news:f0o9ga$f1r$1@build.eclipse.org...
>>>>>> What exactly is not working ?
>>>>>> Do you have a log or something ?
>>>>>>
>>>>>> What are you trying to do ? A copy or a cut ?
>>>>>>
>>>>>> 1. Try to set the requiredDetail of the dropRequest to DND.COPY in
>>>>>> the DropTargetListener. By default the requiredDetail of the request
>>>>>> is not high enough to allow the drop.
>>>>>> 2. Keep in mind that the objects are in two different edit domains.
>>>>>> You have to open a transaction of the two editing domains
>>>>>> simultaneously to do the drop.
>>>>>>
>>>>>> DnD is not easy. You might want to be a bit more incremental : make
>>>>>> sure you can simulate a drag and drop by doing two actions, one drag
>>>>>> the other drop. When this works perfectly, you can go crazy with the
>>>>>> DnD interactions themselves.
>>>>>>
>>>>>> We implemented a mechanism to do DnD on the STP BPMN modeler.
>>>>>>
>>>>>> Here is our listener:
>>>>>>
>>>>>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.stp.bpm n/org.eclipse.stp.bpmn.diagram/customsrc/org/eclipse/stp/bpm n/dnd/GenericEAnnotationDropTargetListener.java?revision=1.4 &root=STP_Project&view=markup
>>>>>>
>>>>>> Good luck !
>>>>>>
>>>>>> Antoine
>>>>>>
>>>>>> Dimosthenis wrote:
>>>>>>> Dear all,
>>>>>>>
>>>>>>> I have created two GMF editors that implement the same ecore model.
>>>>>>> I would like to drag and drop elements from one editor to the other.
>>>>>>>
>>>>>>> Following previous posts, I have implemented a dropListener that
>>>>>>> extends
>>>>>>> the DiagramDropTargetListener and also install an edit policy.
>>>>>>> However, this
>>>>>>> does not work and I am not allowed to drop the element to the second
>>>>>>> editor.
>>>>>>>
>>>>>>> Can you please give me a hand?
>>>>>>>
>>>>>>> Thanks
>>>>>
>>>>
>>>> --
>>>> Intalio, the Open Source BPMS Company
>>>>
>>>> <a href="http://www.intalio.com">http://www.intalio.com</a>
>>>> <a href="http://bpms.intalio.com">Community website</a>
>>>
>>
>>
>
>
> --
> Intalio, the Open Source BPMS Company
>
> <a href="http://www.intalio.com">http://www.intalio.com</a>
> <a href="http://bpms.intalio.com">Community website</a>
|
|
|
Goto Forum:
Current Time: Sun Jul 27 09:21:03 EDT 2025
Powered by FUDForum. Page generated in 0.30049 seconds
|