Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Dnd Problems on a Tree
Dnd Problems on a Tree [message #455958] Tue, 24 May 2005 04:44 Go to next message
Eclipse UserFriend
Originally posted by: ssc.acentic.net

Hi

I have a tree with drag and drop which works fine so far.

I created a object "Book" which I attach to the treeItem with setData.
This also works fine.

The problem appears when I drag and drop a treeitem, I am not able to
transfer the object to the new treeitem. Getting the name is not a
problem, but the object is.

I use this to get the name :

public void drop (DropTargetEvent event) {
if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}

String text = (String) event.data;

}


which works ok, but how would I get the object. I assumed to do someting
like this :

Book mybook = (Book) event.data;
System.out.println(mybook.gettitle());

But that gave me a CastException.


Book mybook = (Book) event.item;
System.out.println(mybook.gettitle());

This works fine on the other hand, but unfortunately that gives me the
data of the drop target and not the source.

Hope anyone can help me out here.

Thanks,

Sebastian
Re: Dnd Problems on a Tree [message #455960 is a reply to message #455958] Tue, 24 May 2005 05:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ssc.acentic.net

Hi

actually I did a "workaround" if you can call it, just taking the class
defined

private Item dragSourceItem;

and this :

TreeItem tmpItem = (TreeItem)dragSourceItem;
Book mybook = (Book) tmpItem.getdata();
System.out.println(mybook.gettitle());


Now is that a good way to do this or any other suggestions ?


-Sebastian
Re: Dnd Problems on a Tree [message #456309 is a reply to message #455960] Mon, 30 May 2005 13:56 Go to previous message
Eclipse UserFriend
You should define a data transfer type for Book. See:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet79.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup


"Sebastian Scholz" <ssc@acentic.net> wrote in message
news:pan.2005.05.24.09.13.07.406000@acentic.net...
> Hi
>
> actually I did a "workaround" if you can call it, just taking the class
> defined
>
> private Item dragSourceItem;
>
> and this :
>
> TreeItem tmpItem = (TreeItem)dragSourceItem;
> Book mybook = (Book) tmpItem.getdata();
> System.out.println(mybook.gettitle());
>
>
> Now is that a good way to do this or any other suggestions ?
>
>
> -Sebastian
Previous Topic:Window title font
Next Topic:Safe to call setTransfer multiple times on a DragSource?
Goto Forum:
  


Current Time: Wed Jul 02 17:02:13 EDT 2025

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

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

Back to the top