Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » drag and drop between to editors
drag and drop between to editors [message #248377] Fri, 17 April 2009 16:20 Go to next message
René is currently offline RenéFriend
Messages: 45
Registered: July 2009
Member
hi all,

i m trying to implement a drag and drop between to gef editors.
Therefore i added a DragSourceListener and DropTargetListener to my
GraphicalViewer.

Code:

protected void initializeGraphicalViewer() {
...
viewer.addDropTargetListener(new MyDropTargetListener(viewer));
viewer.addDragSourceListener(new MyDragSourceListener(viewer));
...
}

MyDragSourceListener extends from AbstractTransferDragSourceListener and
looks like this:

Code:

public MyDragSourceListener(EditPartViewer viewer) {
super(viewer,MyTransfer.getInstance());
}

@SuppressWarnings("unchecked")
@Override
public void dragStart(DragSourceEvent event) {
event.doit = false;
if (MyTransfer.getInstance().isDragAllowed()) {
List selectedEditParts = getViewer().getSelectedEditParts();
if (selectedEditParts.size() == 1) {
EditPart selectedPart = (EditPart) selectedEditParts.get(0);
if (selectedPart instanceof ComponentEditPart) {
MyTransfer.getInstance().setObject(selectedPart);
event.doit = true;
}
}
}
}

@Override
public void dragSetData(DragSourceEvent event) {
event.data = selectedEditPart; //class member
}

MyTransfer extends from SimpleObjectTransfer and i added a method to
determine a condition. This is because there was a problem moving
elements of the diagram after adding the DragSourceListener to my
GraphicalViewer ( see for details
http://dev.eclipse.org/newslists/news.eclipse.tools.gef/msg1 6123.html ).

When i start dragging a diagram element the dragStart-method would
invoked and all the code will executed. But then nothing happen anymore.
My mouse cursor in the application shows the blocking icon and the
setDragData-method will not invoked.

Whats wrong? Is there maybe an tutorial which describes the how to
implement a editor as drag source? For the other way (the editor as drop
target) several tutorials and news group entries exist but i cant find
some for my case.

Please help me.

Thanks in advance and best regards,
René
Re: drag and drop between to editors [message #248436 is a reply to message #248377] Mon, 20 April 2009 14:28 Go to previous message
René is currently offline RenéFriend
Messages: 45
Registered: July 2009
Member
hi all,

for further investigation of my problem override the method
isSupportedType(TransferData) in MyTransfer. So i could see that this
method is always false. That brings me to the suggestion that something
must be wrong with the transfer type.

In detail MyTransfer looks like this:

public class MyTransfer extends SimpleObjectTransfer {

private final static ComponentReferenceTransfer INSTANCE = new
MyTransfer ();

private boolean isDragAllowed = false;

private static final String TYPE_NAME =
"template_reference_transfer"//$NON-NLS-1$
+ System.currentTimeMillis() + ":"
+ INSTANCE.hashCode();//$NON-NLS-1$
private static final int TYPEID = registerType(TYPE_NAME);

private ComponentReferenceTransfer() {
}

public static ComponentReferenceTransfer getInstance() {
return INSTANCE;
}

@Override
protected int[] getTypeIds() {
return new int[] { TYPEID };
}

@Override
protected String[] getTypeNames() {
return new String[] { TYPE_NAME };
}

public boolean isDragAllowed() {
return isDragAllowed;
}

public void setDragAllowed(boolean isDragAllowed) {
this.isDragAllowed = isDragAllowed;
}


Is there anything wrong with that? Or i have to do more to determine the
transfer type correctly?

I hope you can help me. Thanks in advance.
René



René wrote:
> hi all,
>
> i m trying to implement a drag and drop between to gef editors.
> Therefore i added a DragSourceListener and DropTargetListener to my
> GraphicalViewer.
>
> Code:
>
> protected void initializeGraphicalViewer() {
> ...
> viewer.addDropTargetListener(new MyDropTargetListener(viewer));
> viewer.addDragSourceListener(new MyDragSourceListener(viewer));
> ...
> }
>
> MyDragSourceListener extends from AbstractTransferDragSourceListener and
> looks like this:
>
> Code:
>
> public MyDragSourceListener(EditPartViewer viewer) {
> super(viewer,MyTransfer.getInstance());
> }
>
> @SuppressWarnings("unchecked")
> @Override
> public void dragStart(DragSourceEvent event) {
> event.doit = false;
> if (MyTransfer.getInstance().isDragAllowed()) {
> List selectedEditParts = getViewer().getSelectedEditParts();
> if (selectedEditParts.size() == 1) {
> EditPart selectedPart = (EditPart) selectedEditParts.get(0);
> if (selectedPart instanceof ComponentEditPart) {
> MyTransfer.getInstance().setObject(selectedPart);
> event.doit = true;
> }
> }
> }
> }
>
> @Override
> public void dragSetData(DragSourceEvent event) {
> event.data = selectedEditPart; //class member
> }
>
> MyTransfer extends from SimpleObjectTransfer and i added a method to
> determine a condition. This is because there was a problem moving
> elements of the diagram after adding the DragSourceListener to my
> GraphicalViewer ( see for details
> http://dev.eclipse.org/newslists/news.eclipse.tools.gef/msg1 6123.html ).
>
> When i start dragging a diagram element the dragStart-method would
> invoked and all the code will executed. But then nothing happen anymore.
> My mouse cursor in the application shows the blocking icon and the
> setDragData-method will not invoked.
>
> Whats wrong? Is there maybe an tutorial which describes the how to
> implement a editor as drag source? For the other way (the editor as drop
> target) several tutorials and news group entries exist but i cant find
> some for my case.
>
> Please help me.
>
> Thanks in advance and best regards,
> René
Previous Topic:[zest] how to draw bends in connections
Next Topic:drawing shapes
Goto Forum:
  


Current Time: Thu Apr 25 06:16:58 GMT 2024

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

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

Back to the top