1 package com.melloware.jukes.gui.view.node;
2
3 import java.text.MessageFormat;
4 import java.util.Iterator;
5
6 import javax.swing.Icon;
7
8 import org.apache.commons.lang.StringUtils;
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 import com.jgoodies.uif.util.ResourceUtils;
13 import com.melloware.jukes.db.HibernateDao;
14 import com.melloware.jukes.db.orm.Artist;
15 import com.melloware.jukes.db.orm.Disc;
16 import com.melloware.jukes.gui.tool.Resources;
17
18
19
20
21
22
23
24
25
26
27 public final class ArtistNode
28 extends AbstractTreeNode {
29
30 private static final Log LOG = LogFactory.getLog(ArtistNode.class);
31
32
33
34
35
36
37
38 public ArtistNode(NavigationNode aParent, Artist aModel) {
39 super(aParent, aModel);
40 this.settings = ((AbstractTreeNode)aParent).settings;
41 }
42
43
44
45
46
47
48
49 public Artist getArtist() {
50 return (Artist)getModel();
51 }
52
53
54
55
56
57
58
59 public Icon getIcon(final boolean sel) {
60 Icon icon = null;
61 if (StringUtils.equalsIgnoreCase(getArtist().getName(), "grateful dead")) {
62 icon = Resources.DISC_GD_ICON;
63 } else if (StringUtils.equalsIgnoreCase(getArtist().getName(), "pink floyd")) {
64 icon = Resources.DISC_PF_ICON;
65 } else if (StringUtils.equalsIgnoreCase(getArtist().getName(), "who")) {
66 icon = Resources.DISC_WHO_ICON;
67 } else if (StringUtils.equalsIgnoreCase(getArtist().getName(), "beatles")) {
68 icon = Resources.DISC_BEATLES_ICON;
69 } else if (StringUtils.equalsIgnoreCase(getArtist().getName(), "rolling stones")) {
70 icon = Resources.DISC_STONES_ICON;
71 } else {
72 icon = Resources.ARTIST_TREE_ICON;
73 }
74 return icon;
75 }
76
77
78
79
80
81
82 public String getName() {
83 return getArtist().getName();
84 }
85
86
87
88
89 public void loadChildren() {
90 if (!childrenLoaded) {
91 loadingChildren = true;
92 LOG.debug("Loading children");
93
94 Iterator iterator = null;
95 final String filter = this.settings.getFilter();
96
97
98 if (StringUtils.isNotBlank(filter)) {
99 final String resource = ResourceUtils.getString("hql.filter.disc");
100 final String hql = MessageFormat.format(resource, new Object[] { getArtist().getId(), filter });
101 LOG.debug(hql);
102 iterator = HibernateDao.findByQuery(hql).iterator();
103 } else {
104
105 iterator = getArtist().getDiscs().iterator();
106 }
107
108
109 while (iterator.hasNext()) {
110 final Disc disc = (Disc)iterator.next();
111 if (LOG.isDebugEnabled()) {
112 LOG.debug("Loading disc " + disc.getName());
113 }
114 this.add(new DiscNode(this, disc));
115 }
116 loadingChildren = false;
117 childrenLoaded = true;
118 }
119
120 }
121
122 }