NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Drag & Drop between Swing components and Nodes

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users
View previous topic :: View next topic  
Author Message
Marco Ehrentreich
Posted via mailing list.





PostPosted: Sun Oct 05, 2008 4:55 pm    Post subject: Drag & Drop between Swing components and Nodes Reply with quote

Hi folks,

first of all sorry for annoying you again with this problem Wink I already
posted this question a few weeks ago but I neither got an answer which
solved my problem nor could I come up with a solution on my own.

I have the following problem: In my NetBeans application my main view is
a JTable implementation which displays some kind of application specific
objects. A second window provides an explorer view based on the Nodes
API which displays some other objects. Now I want to enable drag & drop
from the JTable to certain Nodes in the explorer view. The curious thing
is that the drag & drop data transfer is already working! I have
implemented the necessary functionality to link objects of the table to
nodes in the explorer using drag & drop. Unfortunately the mouse cursor
doesn't change its appearance when a drop should be accepted. The cursor
always shows the "forbidden" icon.

For this I would guess I have implemented drag & drop correctly but not
the NetBeans way which is needed to work with Nodes. Unfortunately I
couldn't find any advices how the "drop" part for nodes has to be
configured to show the correct behaviour/icon for accepted and not
accepted drops. Can anyone please tell me what I have to do to get this
right?

Besides this problem I'm going to have another drag & drop feature
between pure nodes in the same explorer view. So I'd be interested in
both - the drag AND the drop implementation in Node classes.

Thanks in advance!

Marco
Back to top
StudentB
Posted via mailing list.





PostPosted: Tue Oct 07, 2008 11:20 pm    Post subject: Drag & Drop between Swing components and Nodes Reply with quote

I don't have an answer because I am having similar problems. I am trying to
get drag and drop working between two BeanTree Views, each in their own Top
component. I have read through every tutorial and book I can find and its
more confusing then helpful. I actually have the drag and drop partially
working as well but some things I notice. I always get the "can not drop"
icon. The image of the node being drug is not displayed during the
dragging. The tutorials talk about implementing a setDropTarget on a JPanel
and then adding code to the doDragOver to get the image to be displayed but
with the BeanTree View it is already implementing those methods and
subsequently calling getDropType on the target node; therefore I can't add
my code to display the image. I would think that the getIcon method would
be automactially called on the object in the transferrable to display the
image during the dragging. I also noticed that createPasteTypes is never
called so I don't see how the DataFlavors even comes in to play as it
mentions in the tutorials. Lastly, when I want to drag a node the first
time, I first have to single click somewhere in the scroll pane(BreanTree
view) and then click again on the node I want to drag and drag it. If I
don't click in the scroll pane first then dragging does not work. Calling
requestFocus, requestActive, setEnabled does not help. Also, I have noticed
that when the getDropType method is called the action value is some huge
number for a move when it should be a 2.

Sorry for not answering your question but maybe someone will read this and
realize that more than one person could use some help in this area.



erisch wrote:
Quote:

Hi folks,

first of all sorry for annoying you again with this problem Wink I already
posted this question a few weeks ago but I neither got an answer which
solved my problem nor could I come up with a solution on my own.

I have the following problem: In my NetBeans application my main view is
a JTable implementation which displays some kind of application specific
objects. A second window provides an explorer view based on the Nodes
API which displays some other objects. Now I want to enable drag & drop
from the JTable to certain Nodes in the explorer view. The curious thing
is that the drag & drop data transfer is already working! I have
implemented the necessary functionality to link objects of the table to
nodes in the explorer using drag & drop. Unfortunately the mouse cursor
doesn't change its appearance when a drop should be accepted. The cursor
always shows the "forbidden" icon.

For this I would guess I have implemented drag & drop correctly but not
the NetBeans way which is needed to work with Nodes. Unfortunately I
couldn't find any advices how the "drop" part for nodes has to be
configured to show the correct behaviour/icon for accepted and not
accepted drops. Can anyone please tell me what I have to do to get this
right?

Besides this problem I'm going to have another drag & drop feature
between pure nodes in the same explorer view. So I'd be interested in
both - the drag AND the drop implementation in Node classes.

Thanks in advance!

Marco




--
View this message in context: http://www.nabble.com/Drag---Drop-between-Swing-components-and-Nodes-tp19826660p19869424.html
Sent from the Netbeans - Open API mailing list archive at Nabble.com.
Back to top
Wade Chandler
Posted via mailing list.





PostPosted: Wed Oct 08, 2008 3:42 am    Post subject: Drag & Drop between Swing components and Nodes Reply with quote

Maybe you guys can find something in Geertjan's blog:
http://onesearch.sun.com/search/blog/index.jsp?col=blog&charset=utf-8&weblog=geertjan&qt=drag+and+drop

He has lots of examples from different versions of the IDE. If those don't help, he might be able to point you to some kind of other working examples.

Wade

==================
Wade Chandler, CCE
Software Engineer and Developer, Certified Forensic Computer Examiner, NetBeans Dream Team Member, and NetBeans Board Member
http://www.certified-computer-examiner.com
http://wiki.netbeans.org/wiki/view/NetBeansDreamTeam
http://www.netbeans.org



----- Original Message ----
Quote:
From: StudentB <address-removed>
To: address-removed
Sent: Tuesday, October 7, 2008 7:19:58 PM
Subject: Re: [openide-dev] Drag & Drop between Swing components and Nodes


I don't have an answer because I am having similar problems. I am trying to
get drag and drop working between two BeanTree Views, each in their own Top
component. I have read through every tutorial and book I can find and its
more confusing then helpful. I actually have the drag and drop partially
working as well but some things I notice. I always get the "can not drop"
icon. The image of the node being drug is not displayed during the
dragging. The tutorials talk about implementing a setDropTarget on a JPanel
and then adding code to the doDragOver to get the image to be displayed but
with the BeanTree View it is already implementing those methods and
subsequently calling getDropType on the target node; therefore I can't add
my code to display the image. I would think that the getIcon method would
be automactially called on the object in the transferrable to display the
image during the dragging. I also noticed that createPasteTypes is never
called so I don't see how the DataFlavors even comes in to play as it
mentions in the tutorials. Lastly, when I want to drag a node the first
time, I first have to single click somewhere in the scroll pane(BreanTree
view) and then click again on the node I want to drag and drag it. If I
don't click in the scroll pane first then dragging does not work. Calling
requestFocus, requestActive, setEnabled does not help. Also, I have noticed
that when the getDropType method is called the action value is some huge
number for a move when it should be a 2.

Sorry for not answering your question but maybe someone will read this and
realize that more than one person could use some help in this area.



erisch wrote:
Quote:

Hi folks,

first of all sorry for annoying you again with this problem Wink I already
posted this question a few weeks ago but I neither got an answer which
solved my problem nor could I come up with a solution on my own.

I have the following problem: In my NetBeans application my main view is
a JTable implementation which displays some kind of application specific
objects. A second window provides an explorer view based on the Nodes
API which displays some other objects. Now I want to enable drag & drop
from the JTable to certain Nodes in the explorer view. The curious thing
is that the drag & drop data transfer is already working! I have
implemented the necessary functionality to link objects of the table to
nodes in the explorer using drag & drop. Unfortunately the mouse cursor
doesn't change its appearance when a drop should be accepted. The cursor
always shows the "forbidden" icon.

For this I would guess I have implemented drag & drop correctly but not
the NetBeans way which is needed to work with Nodes. Unfortunately I
couldn't find any advices how the "drop" part for nodes has to be
configured to show the correct behaviour/icon for accepted and not
accepted drops. Can anyone please tell me what I have to do to get this
right?

Besides this problem I'm going to have another drag & drop feature
between pure nodes in the same explorer view. So I'd be interested in
both - the drag AND the drop implementation in Node classes.

Thanks in advance!

Marco




--
View this message in context:
http://www.nabble.com/Drag---Drop-between-Swing-components-and-Nodes-tp19826660p19869424.html
Sent from the Netbeans - Open API mailing list archive at Nabble.com.
Back to top
Marco Ehrentreich
Posted via mailing list.





PostPosted: Thu Oct 09, 2008 7:11 am    Post subject: Drag & Drop between Swing components and Nodes Reply with quote

Hi,

@Wade: Thanks for the link. There are indeed some useful information on
these pages but unfortunately none could solve or explain my problem :(

Anyway after experimenting some hours and testing all advices from all
tutorials I could find I finally have discovered by accident how to
change my d&d cursor to an accepting one. In my case it was the d&d
action I used before. From a logical view I thouhgt the LINK action
would describe the action in my application most reasonable. But for any
reasons the DndConstants.LINK action always leads to a non-accepting
cursor when trying to drop something on my Nodes within a BeanTreeView.
All the examples and description I found didn't help anything. Only
after I changed the action to COPY I got an accepting cursor.

But it's really frustrating that nobody can explain why it behaves like
this or if and how one could change that. Moreover I couldn't find any
examples which show how to use plain Swing components as drag source and
drop onto NetBeans targets. Is this situation such uncommon?!? The
NetBeans platform is really helpful in many, many ways but simple
problems like this may cost hours or days without finally finding a real
answer... How do you all handle these situations when you really don't
know what else you can do about a problem but you have to get done
something?

@StudentB: After investigating most tutorials on the internet once again
I found those two most useful. Unfortunately the second is in German but
perhaps it may help, too:

http://platform.netbeans.org/tutorials/nbm-nodesapi3.html
http://www.sepix.de/blogs/blogrittner/blog/archive////beandev_minimaler_einsatz_fuer_drag_and_drop_von_nodes/index.html

I hope you can solve you problems with this drag & drop thing.
Unfortunately I can't really help you. I tested all the changes in the
code described in any tutorial and example. As I wrote I finally figured
out that (at least in my application) it was simply this damn drag
action which doesn't produce an "accepting" cursor when dropped on a
node tree. Good Luck!

Marco


Wade Chandler schrieb:
Quote:
Maybe you guys can find something in Geertjan's blog:
http://onesearch.sun.com/search/blog/index.jsp?col=blog&charset=utf-8&weblog=geertjan&qt=drag+and+drop

He has lots of examples from different versions of the IDE. If those don't help, he might be able to point you to some kind of other working examples.

Wade

==================
Wade Chandler, CCE
Software Engineer and Developer, Certified Forensic Computer Examiner, NetBeans Dream Team Member, and NetBeans Board Member
http://www.certified-computer-examiner.com
http://wiki.netbeans.org/wiki/view/NetBeansDreamTeam
http://www.netbeans.org



----- Original Message ----
Quote:
From: StudentB <address-removed>
To: address-removed
Sent: Tuesday, October 7, 2008 7:19:58 PM
Subject: Re: [openide-dev] Drag & Drop between Swing components and Nodes


I don't have an answer because I am having similar problems. I am trying to
get drag and drop working between two BeanTree Views, each in their own Top
component. I have read through every tutorial and book I can find and its
more confusing then helpful. I actually have the drag and drop partially
working as well but some things I notice. I always get the "can not drop"
icon. The image of the node being drug is not displayed during the
dragging. The tutorials talk about implementing a setDropTarget on a JPanel
and then adding code to the doDragOver to get the image to be displayed but
with the BeanTree View it is already implementing those methods and
subsequently calling getDropType on the target node; therefore I can't add
my code to display the image. I would think that the getIcon method would
be automactially called on the object in the transferrable to display the
image during the dragging. I also noticed that createPasteTypes is never
called so I don't see how the DataFlavors even comes in to play as it
mentions in the tutorials. Lastly, when I want to drag a node the first
time, I first have to single click somewhere in the scroll pane(BreanTree
view) and then click again on the node I want to drag and drag it. If I
don't click in the scroll pane first then dragging does not work. Calling
requestFocus, requestActive, setEnabled does not help. Also, I have noticed
that when the getDropType method is called the action value is some huge
number for a move when it should be a 2.

Sorry for not answering your question but maybe someone will read this and
realize that more than one person could use some help in this area.



erisch wrote:
Quote:
Hi folks,

first of all sorry for annoying you again with this problem Wink I already
posted this question a few weeks ago but I neither got an answer which
solved my problem nor could I come up with a solution on my own.

I have the following problem: In my NetBeans application my main view is
a JTable implementation which displays some kind of application specific
objects. A second window provides an explorer view based on the Nodes
API which displays some other objects. Now I want to enable drag & drop
from the JTable to certain Nodes in the explorer view. The curious thing
is that the drag & drop data transfer is already working! I have
implemented the necessary functionality to link objects of the table to
nodes in the explorer using drag & drop. Unfortunately the mouse cursor
doesn't change its appearance when a drop should be accepted. The cursor
always shows the "forbidden" icon.

For this I would guess I have implemented drag & drop correctly but not
the NetBeans way which is needed to work with Nodes. Unfortunately I
couldn't find any advices how the "drop" part for nodes has to be
configured to show the correct behaviour/icon for accepted and not
accepted drops. Can anyone please tell me what I have to do to get this
right?

Besides this problem I'm going to have another drag & drop feature
between pure nodes in the same explorer view. So I'd be interested in
both - the drag AND the drop implementation in Node classes.

Thanks in advance!

Marco



--
View this message in context:
http://www.nabble.com/Drag---Drop-between-Swing-components-and-Nodes-tp19826660p19869424.html
Sent from the Netbeans - Open API mailing list archive at Nabble.com.
Back to top
Wade Chandler
Posted via mailing list.





PostPosted: Thu Oct 09, 2008 3:59 pm    Post subject: Drag & Drop between Swing components and Nodes Reply with quote

----- Original Message ----

Quote:
From: Marco Ehrentreich <address-removed>
To: address-removed
Sent: Thursday, October 9, 2008 3:10:46 AM
Subject: Re: [openide-dev] Drag & Drop between Swing components and Nodes

Hi,

@Wade: Thanks for the link. There are indeed some useful information on
these pages but unfortunately none could solve or explain my problem :(

:-(

Quote:
Anyway after experimenting some hours and testing all advices from all
tutorials I could find I finally have discovered by accident how to
change my d&d cursor to an accepting one. In my case it was the d&d
action I used before. From a logical view I thouhgt the LINK action
would describe the action in my application most reasonable. But for any
reasons the DndConstants.LINK action always leads to a non-accepting
cursor when trying to drop something on my Nodes within a BeanTreeView.
All the examples and description I found didn't help anything. Only
after I changed the action to COPY I got an accepting cursor.

But it's really frustrating that nobody can explain why it behaves like
this or if and how one could change that. Moreover I couldn't find any
examples which show how to use plain Swing components as drag source and
drop onto NetBeans targets. Is this situation such uncommon?!?
I think this is part of the way the community gets these things done. This happens in all kinds of projects. Different issues come up, solutions are made, once they are there then everyone in the future has it licked, but for the pioneer there are many hours involved. Essentially if someone hasn't had to do something yet, or the use case hasn't come up, then folks won't have many if any answers for you. The down side is you spend a lot of time with something. The bright side is that others love you for it, and in the end you have not only helped others, but you have improved the community and our tools.

Quote:
The NetBeans platform is really helpful in many, many ways but simple
problems like this may cost hours or days without finally finding a real
answer... How do you all handle these situations when you really don't
know what else you can do about a problem but you have to get done
something?


Yes, the platform solves many things, and helps with a lot, but there will always be things that it doesn't have until someone determines they need it and put it there or if it is functionality which is available yet not really a lot is known about becomes better documented and some tutorials are created. This is the great dilemma with anything. If we knew what we would need we could have it all, but as they say, necessity is the mother of invention, and sometimes that falls on different folks shoulders.

As far as how I go about finding an answer, I usually dig through the sources. I find something does seemingly does what I need to do, and I investigate at the lowest levels. In this case, if it were me, I would dig into the DND support in NB and some things using it. I would then look in the Swing sources from the JDK and examine the DND there and look for commonality and any hooks I could use. If I had some example doing what I need I would go straight to that first. This is the handiest part of open source...we have the best examples because we have the source code readily available.

Not the best answer as it doesn't exactly solve your issue, but it is the best one I have. I looked around NB for a while before I decided that making my own central lookup and an interface where objects could be added to it at will would make more sense and my life easier in RCP applications. It was a simple thing to do, and I spent less time going ahead and doing it than I did researching whether the platform supported it or not. In the process I learned more about what the platform did and didn't provide in the means of a mutable global lookup versus the merged ones, and my simple library really let me clean up some code, and I have been thinking of ways of having such a thing which is merged with the default lookup or the global context. Anyways, once you start digging you may find what you need exists, and you may find you might have to add it...sometimes a bear. :-S

Wade
Back to top
Marco Ehrentreich
Posted via mailing list.





PostPosted: Wed Oct 15, 2008 8:42 am    Post subject: Drag & Drop between Swing components and Nodes Reply with quote

Quote:
Quote:
Anyway after experimenting some hours and testing all advices from all
tutorials I could find I finally have discovered by accident how to
change my d&d cursor to an accepting one. In my case it was the d&d
action I used before. From a logical view I thouhgt the LINK action
would describe the action in my application most reasonable. But for any
reasons the DndConstants.LINK action always leads to a non-accepting
cursor when trying to drop something on my Nodes within a BeanTreeView.
All the examples and description I found didn't help anything. Only
after I changed the action to COPY I got an accepting cursor.

But it's really frustrating that nobody can explain why it behaves like
this or if and how one could change that. Moreover I couldn't find any
examples which show how to use plain Swing components as drag source and
drop onto NetBeans targets. Is this situation such uncommon?!?
I think this is part of the way the community gets these things done. This happens in all kinds of projects. Different issues come up, solutions are made, once they are there then everyone in the future has it licked, but for the pioneer there are many hours involved. Essentially if someone hasn't had to do something yet, or the use case hasn't come up, then folks won't have many if any answers for you. The down side is you spend a lot of time with something. The bright side is that others love you for it, and in the end you have not only helped others, but you have improved the community and our tools.

It's very interesting to hear that it's not only me having such
problems. Of course you're absolutely right that a community like this
often just works this way. I really don't mind spending some time to
work on solutions for a problem which may help others too. What I really
wanted to say is that I already have some experience with the NetBeans
platform and when I get into trouble it's still hard to tell whether I'm
just to stupid to find an existing solution or if there's a solution
available but just badly documented or if I'm really the first one to
have such a problem. So it's always a decision between working on an own
solution or searching for an existing solution. But from what you wrote
I guess that almost everyone has to make these decisions...

Quote:
Quote:
The NetBeans platform is really helpful in many, many ways but simple
problems like this may cost hours or days without finally finding a real
answer... How do you all handle these situations when you really don't
know what else you can do about a problem but you have to get done
something?


Yes, the platform solves many things, and helps with a lot, but there will always be things that it doesn't have until someone determines they need it and put it there or if it is functionality which is available yet not really a lot is known about becomes better documented and some tutorials are created. This is the great dilemma with anything. If we knew what we would need we could have it all, but as they say, necessity is the mother of invention, and sometimes that falls on different folks shoulders.

Really true words. But sometimes even a simple small list with all
things the platform definitely can NOT do would already be helpful :-)

Quote:
As far as how I go about finding an answer, I usually dig through the sources. I find something does seemingly does what I need to do, and I investigate at the lowest levels. In this case, if it were me, I would dig into the DND support in NB and some things using it. I would then look in the Swing sources from the JDK and examine the DND there and look for commonality and any hooks I could use. If I had some example doing what I need I would go straight to that first. This is the handiest part of open source...we have the best examples because we have the source code readily available.

The source code is indeed a great pool of information and it really help
me often to show similar solutions for my own problems. The only problem
is - especially for someone new to the platform - that it's a
comparatively big software project and you definitely need some
experience before you can effectively use the source code to search for
solutions in it.

Quote:
Not the best answer as it doesn't exactly solve your issue, but it is the best one I have. I looked around NB for a while before I decided that making my own central lookup and an interface where objects could be added to it at will would make more sense and my life easier in RCP applications. It was a simple thing to do, and I spent less time going ahead and doing it than I did researching whether the platform supported it or not. In the process I learned more about what the platform did and didn't provide in the means of a mutable global lookup versus the merged ones, and my simple library really let me clean up some code, and I have been thinking of ways of having such a thing which is merged with the default lookup or the global context. Anyways, once you start digging you may find what you need exists, and you may find you might have to add it...sometimes a bear. :-S

Far from it! This was a very good answer Wink Not directly a solution for
my problem (which I already solved) but it's surely great to hear some
advices from someone with much more experience. This made me think about
the NetBeans platform as a work in progress instead of an already
finished perfect piece of software. I think this an important point you
should have in mind but I probably wouldn't see it this way without this
kind of discussions ;)

Marco
Back to top
tomwheeler



Joined: 03 Sep 2008
Posts: 950

PostPosted: Wed Oct 15, 2008 3:41 pm    Post subject: Drag & Drop between Swing components and Nodes Reply with quote

On Wed, Oct 15, 2008 at 3:42 AM, Marco Ehrentreich
<address-removed> wrote:
Quote:
Far from it! This was a very good answer Wink Not directly a solution for
my problem (which I already solved) but it's surely great to hear some
advices from someone with much more experience...

If you've figured it out, I'd encourage you to add an entry describing
the solution to the NetBeans Developer FAQ (probably under the "Nodes
and Explorer" section):

http://wiki.netbeans.org/NetBeansDeveloperFAQ

That will help the next person who comes along and needs to do the
same thing. In fact, over the years I've been involved with the
platform, there have been a few times where I find a helpful answer
there only to discover that it was me who originally wrote it! I've
also found many times where others have greatly expanded upon what
I've written and I've learned from their experience too.

--
Tom Wheeler
http://www.tomwheeler.com/
Back to top
Marco Ehrentreich
Posted via mailing list.





PostPosted: Thu Oct 23, 2008 1:15 pm    Post subject: Drag & Drop between Swing components and Nodes Reply with quote

Hi Tom,

Tom Wheeler schrieb:
Quote:
On Wed, Oct 15, 2008 at 3:42 AM, Marco Ehrentreich
<address-removed> wrote:
Quote:
Far from it! This was a very good answer Wink Not directly a solution for
my problem (which I already solved) but it's surely great to hear some
advices from someone with much more experience...

If you've figured it out, I'd encourage you to add an entry describing
the solution to the NetBeans Developer FAQ (probably under the "Nodes
and Explorer" section):

http://wiki.netbeans.org/NetBeansDeveloperFAQ

That will help the next person who comes along and needs to do the
same thing. In fact, over the years I've been involved with the
platform, there have been a few times where I find a helpful answer
there only to discover that it was me who originally wrote it! I've
also found many times where others have greatly expanded upon what
I've written and I've learned from their experience too.

I'd really like to help other people with my "solution". Unfortunately
it seems to me more like a stupid workaround than a solution. It almost
works like expected and I simply accepted, that it won't behave exactly
like I expected. What's more frustrating is that I still don't know what
was or is the problem so I hoped some other could tell a little bit more
about this. It's hard to give anyone advices to a solution if you even
don't know the problem Smile
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo