Hi,
I have a simple View with a TreeViewer representing POJOs. I need to drag the TreeItems from the view and drop them to a GEF editor (inside a multipage editor).
When I drag the item from the viewer to the editor area, the create request, handle drag and update request methods are called in the listener. but when I drop the item handleDrop/drop is NOT called.
what am i missing?
My View contains:
Transfer[] types = new Transfer[]{TextTransfer.getInstance()};
treeViewer.addDragSupport(DND.DROP_MOVE, types, new InstructionDragListener(treeViewer));
The DragListener looks like:
public class InstructionDragListener implements DragSourceListener {
private Viewer viewer;
public InstructionDragListener(Viewer viewer) {
this.viewer = viewer;
}
@Override
public void dragStart(DragSourceEvent event) {
System.out.println("start");
event.doit = true;
}
@Override
public void dragSetData(DragSourceEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Instruction ins=null;
if (selection.getFirstElement() instanceof Instruction)
ins = (Instruction) selection.getFirstElement();
event.data= ins.getID();
System.out.println("data");
}
@Override
public void dragFinished(DragSourceEvent event) {
System.out.println("end");
}
}
The Editor is part of a MultiPageEditor and looks like:
public class MyGraphicalEditor extends GraphicalEditorWithFlyoutPalette {
public static String ID = "MyEditorID";
public MyGraphicalEditor() {
setEditDomain(new DefaultEditDomain(this));
}
@Override
protected void initializeGraphicalViewer() {
super.initializeGraphicalViewer();
getGraphicalViewer().setContents(ProjectManager.getInstance().getTestCaseTest());
}
@Override
protected void configureGraphicalViewer() {
super.configureGraphicalViewer();
getGraphicalViewer().setEditPartFactory(new TestCaseEditPartFactory());
getGraphicalViewer().addDropTargetListener(new MyTransferTargetDropListener(getGraphicalViewer()));
}
}
and the DropListener looks like:
public class MyTransferTargetDropLsitener extends AbstractTransferDropTargetListener {
private MyTransferTagetDropFactory factory = new MyTransferTagetDropFactory();
public MyTransferTargetDropLsitener(EditPartViewer viewer, Transfer xfer) {
super(viewer, xfer);
}
@Override
protected Request createTargetRequest() {
System.out.println("CREATE REQUEST");
CreateRequest request = new CreateRequest();
request.setFactory(factory);
return request;
}
protected void handleDragOver() {
System.out.println("HANDLE DRAG");
super.handleDragOver();
}
@Override
protected void updateTargetRequest() {
System.out.println("UPDATE REQUEST");
System.out.println(getDropLocation().toString());
((CreateRequest)getTargetRequest()).setLocation(getDropLocation());
}
@Override
protected void handleDrop() {
System.out.println("DROP HANDLED");
super.handleDrop();
}
@Override
public void drop(DropTargetEvent event) {
System.out.println("DROPPED");
super.drop(event);
}
}
thanks!