sjPlot / macwidgets

Automatically exported from code.google.com/p/macwidgets
0 stars 0 forks source link

Question about SourceList Behavior #130

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I posted this question as a comment on the examples page because I  didn't want 
to clutter up 
your issue repository, but I'm in a place where I need an answer now (I fear 
this is somewhat 
trivial):

How do you detect which Category or Parent Item a Selected "Child" item is in? 
Effectively, I want 
to be able to render some kind of action based on the potential Category, or 
Parent as I might 
have a similarly named "Child".

For example, in Mail, there is the category "Mailboxes" and parent items of 
"Inbox", "Sent", and 
"Junk" the child items are my email "accounts". When you click on a particular 
account from a 
particular parent item, you go to the appropriate view. I'd like to mimic that 
behavior.

Also, just to be fair, I've spent most of my development life working on Web 
applications; Swing 
is a new beast to me, so perhaps the solution is easy and I'm just not familiar 
with it.

Thanks in advance!

Original issue reported on code.google.com by jbhawe...@gmail.com on 5 Oct 2009 at 10:46

GoogleCodeExporter commented 8 years ago
Sounds like you want to add a SourceListSelectionListener.

http://exploding-
pixels.com/google_code/javadoc_0.9.5/com/explodingpixels/macwidgets/SourceListSe
lectionListener.html

Original comment by kenneth....@gmail.com on 13 Oct 2009 at 5:23

GoogleCodeExporter commented 8 years ago
Unless I'm mistaken, this doesn't give me the "path" (for lack of a better 
term) of where the selection came 
from. In the above example the SourceListItem for the selected account will 
always give me the account name, 
nothing more, because the makeup of SourceListItem is a text and an icon.  So 
if I as the end user want to 
select an account "foo" from within the "Inbox" category it'll return "foo"; 
just as if I were to select "foo" from 
within "Junk".  It seems to me that the SourceListItem should have some kind of 
indicator as to where it came 
from so that an appropriate decision can be made.  

In fact, this was how I resolved this.  I created a custom SourceListItem by 
extending SourceListItem and 
adding a "parent" Object to it's contents.  I create a new object and set the 
parent reference.  That way in the 
SourceListSelectionListener I can cast it to my custom object and receive the 
parent object and make my 
decision of what I want it to do.  This is by far not the best solution, but it 
seems to work.

Original comment by jbhawe...@gmail.com on 13 Oct 2009 at 5:44

GoogleCodeExporter commented 8 years ago
You can certainly do what your trying to do without extending SourceListItem, 
though ideally you would be able 
to provide an action to be performed when a particular node is selected (this 
has been asked for).

For now, you can simply keep a Map of SourceListItems to "paths".

Original comment by kenneth....@gmail.com on 13 Oct 2009 at 5:52

GoogleCodeExporter commented 8 years ago
I see what you are getting at and it worked like a charm.  Thanks for the help!

BTW - I just have to say that this is a great library!

Original comment by jbhawe...@gmail.com on 14 Oct 2009 at 3:39

GoogleCodeExporter commented 8 years ago
Glad it worked for you!

Original comment by kenneth....@gmail.com on 14 Oct 2009 at 9:29