Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Drag and Drop issue --TransferDropTargetListener
Drag and Drop issue --TransferDropTargetListener [message #215348] Sun, 30 April 2006 14:11
Jan Vereecken is currently offline Jan VereeckenFriend
Messages: 1
Registered: July 2009
Junior Member
I will start with briefly describing what I'm trying to achieve. My
application consists of a NormTreeEditPart that is the root EditPart of
a GraphicalEditor. The NormTreeEditPart has TermEditParts as its
children. What I want now is that when I drag text from anywhere in the
system on the TermEditPart, a certain command (I named it
RenameTermCommand) gets executed. Currently I always get the forbidden
sign when I drag text from anywhere to my EditParts (and in fact
anywhere on the editor). I'm looking for clues, answers, tiny details I
forgot, all comments are greatly appriciated.

Following the example on the GEF project page, I started implementing.

First things first so I started with creating a
TextTransferDropTargetListener (which is the same as in the Logic

/** ## BEGIN CODE ## **/
public class TextTransferDropTargetListener extends
public TextTransferDropTargetListener(EditPartViewer viewer, Transfer xfer) {
super(viewer, xfer);

protected Request createTargetRequest() {
return new NativeDropRequest();
protected NativeDropRequest getNativeDropRequest() {
return (NativeDropRequest)getTargetRequest();
protected void updateTargetRequest(){
/** ## END CODE ## **/

The NativeDropRequest is also copied from the logic example.

/** ## BEGIN CODE ## **/
public class NativeDropRequest extends Request {
private Object data;
public static final String ID = "$Native Drop Request";//$NON-NLS-1$

public NativeDropRequest() {
public NativeDropRequest(Object type) {
public Object getData(){
return data;
public void setData(Object data){ = data;
/** ## END CODE ## **/

In the initializeGraphicalViewer method of the
GraphicalEditorWithFlyoutPalette I register my DropTargetListener :

/** ## BEGIN CODE ## **/
protected void initializeGraphicalViewer() {
/** ## END CODE ## **/

So far so good I guess (the code is mostly copied from the working
logic example). Now things get fussy. I guess that, in order to get the
drop working on my TermEditPart, I have to install (multiple?)

In order to create my Command (the RenameTermCommand), I created a
DndTermEditPolicy class, that when given a NativeDropRequests returns a
Command object. I have to note that this code NEVER gets called (using
the debug mode with setting break points).

/** ## BEGIN CODE ## **/
public class DndTermEditPolicy extends ComponentEditPolicy {
public Command getCommand(Request req) {
if (NativeDropRequest.ID.equals(req.getType())) {
return getDropTextCommand((NativeDropRequest)req);
} else {
return super.getCommand(req);
protected Command getDropTextCommand(NativeDropRequest request) {
RenameTermCommand command = new
return command;
public EditPart getTargetEditPart(Request request) {
if (NativeDropRequest.ID.equals(request.getType()))
return getHost();
return super.getTargetEditPart(request);
/** ## END CODE ## **/

The last step is installing the editpolicy on my TermEditPart.

/** ## BEGIN CODE ## **/
protected void createEditPolicies() {

installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new DndTermEditPolicy());
/** ## END CODE ## **/

This is what I think is necessary to get this (rather simple) drag and
drop operation going. Do I need to install more EditPolicies on the
EditPart? Do I need to install certain EditPolicies on the host parent
(NormTreeEditPart)? Did I forget to do other things.

ANY help is greatly appreciated. If I forgot listing certain
(important) parts of the code be sure to ask for them.

Anyone who read until this point, I thank you ;).
Previous Topic:How to control the adding of child figures
Next Topic:Multiple selection dnd from non-GEF View
Goto Forum:

Current Time: Sun Nov 27 17:06:10 GMT 2022

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

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

Back to the top