Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Drag and Drop with view does not function
Drag and Drop with view does not function [message #488856] Wed, 30 September 2009 14:01 Go to next message
Michelle Davidson is currently offline Michelle Davidson
Messages: 41
Registered: August 2009
Member
Hello,

I have a view with a treeViewer. For this viewer I want to support drag and drop.
The model for the viewer are objects of the type folder, consist of a name, an id and a parent(which is a folder).

For the drag and drop support. I generate the 2 classes FolderDragListener which extends DragsourceAdapter and
FolderTreeDropAdapter which extends ViewerdropAdapter.

I don't know the reason, but it doesn't function.

For debugging I add a state output in every methode of this two classes.

Now I see at first DragStart(), then repeatedly validateDrop() and at last dragSetData().

But the methode performDrop() will not be invoked.

Why what is the reason for that? Can anybody see a mistake or bug in my code?

I attach my code of the two classes and of the view with the treeviewer.

public class FolderDragListener extends DragSourceAdapter {

	private StructuredViewer viewer;

	public FolderDragListener(StructuredViewer viewer) {
		this.viewer = viewer;
	}

	@Override
	public void dragFinished(DragSourceEvent event) {
		System.out.println("__________________dragFinished()__________________");		
		if (!event.doit)
			return;
		viewer.refresh();
	}

	@Override
	public void dragSetData(DragSourceEvent event) {
		System.out.println("__________________dragSetData()__________________");
		
		IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
		Folder folder = (Folder)selection.getFirstElement();	   
	    if (PluginTransfer.getInstance().isSupportedType(event.dataType)) {
	        event.data = folder;
	    }
	}

	@Override
	public void dragStart(DragSourceEvent event) {
		System.out.println("__________________dragStart()__________________");		
		IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
	    Folder folder = (Folder)selection.getFirstElement();				
		event.doit = true ;
	}
}


public class FolderTreeDropAdapter extends ViewerDropAdapter {

	public FolderTreeDropAdapter(TreeViewer viewer) {
		super(viewer);		
	}

	@Override
	public boolean performDrop(Object data) {
		System.out.println("___________Perform_drop()__________________");
		Folder target = (Folder)getCurrentTarget();
	      if (target == null)
	         target = (Folder)getViewer().getInput();
	      Folder toDrop = (Folder)data;
	      TreeViewer viewer = (TreeViewer)getViewer();
	      //cannot drop a folder onto itself or a child
	      if (toDrop.equals(target) || isParentOf(toDrop, target))
	            return false;	    
	         toDrop.setParent(target);
	         viewer.refresh();
	      return true;
	}

	@Override
	public boolean validateDrop(Object target, int operation,
			TransferData transferType) {
		
		boolean valid = PluginTransfer.getInstance().isSupportedType(transferType);
		System.out.println("__________________validateDrop()__________________");
		System.out.println("Target:" +((Folder)target).getName()+ "  validate: "+ valid);
		return valid ;
	}
	
	private boolean isParentOf(Folder source, Folder target)
	{
		 Folder folder = target;
	      while (folder.getParent() != null)
	      {
	    	  if (folder.getParent() == source )
	    		  return true;
	    	  folder = folder.getParent();
	      }
		return false;
	}
}


public class FolderTreeView extends ViewPart {
	
	public static final String ID = "de.rcp.folderTreeView";
	
	private TreeViewer viewer;	
	private FolderTreeDropAdapter dropAdapter;
	
	public FolderTreeView() {		
	}

	@Override
	public void createPartControl(Composite parent) {
		
		viewer = new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL
				| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
		viewer.setContentProvider(new FolderTreeContentProvider());
		viewer.setLabelProvider(new FolderTreeLabelProvider());
		viewer.setInput(PersonModelProvider.getInstance().getPersons());
		addDndSupport(viewer);
	}
	
	private void addDndSupport(TreeViewer viewer)
	{
		int ops = DND.DROP_MOVE;
	    Transfer[] transfers = new Transfer[] { PluginTransfer.getInstance()};
	    viewer.addDragSupport(ops, transfers, new FolderDragListener(viewer));
	    transfers = new Transfer[] {PluginTransfer.getInstance()};
	    dropAdapter = new FolderTreeDropAdapter(viewer);
	    viewer.addDropSupport(ops, transfers, dropAdapter);
	}

	@Override
	public void setFocus() {
		viewer.getTree().setFocus();
	}
}


I want to attach my plugin. Perhaps can anybody try and see the mistake.

Thanks

[Updated on: Thu, 01 October 2009 06:56]

Report message to a moderator

Re: Drag and Drop with view does not function [message #489577 is a reply to message #488856] Mon, 05 October 2009 06:36 Go to previous message
Michelle Davidson is currently offline Michelle Davidson
Messages: 41
Registered: August 2009
Member
Hello,

the attachment of the plugin has not function. I don't know whats the reason is. Because the file was not to big.

Has nobody a idea, where I have a mistake, in my drag and drop classes. And whats the reason hat my drag functions where called but my drop functions not?

Can anybody send me a example for a drag and drop in a treeviewer in a rcp plugin with eclipse 3.4?

Maybe I see my mistake when I compare the code.

Previous Topic:[Databinding] Problems with DelegatingValueProperty
Next Topic:[Databinding] Binding checkbox to boolean property
Goto Forum:
  


Current Time: Sat Sep 20 20:09:34 GMT 2014

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

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