1 package com.melloware.jukes.gui.view.node;
2
3 import java.util.Iterator;
4
5 import javax.swing.Icon;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9
10 import com.melloware.jukes.db.orm.Artist;
11 import com.melloware.jukes.db.orm.Catalog;
12
13 /**
14 * Describes the root node in the Jukes navigation tree.
15 * <p>
16 * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
17 * @author Emil A. Lefkof III <info@melloware.com>
18 * @version 4.0
19 */
20 public final class RootNode
21 extends AbstractTreeNode {
22
23 private static final Log LOG = LogFactory.getLog(RootNode.class);
24
25 private final Catalog catalog;
26
27 /**
28 * Creates a root node for the specified catalog.
29 *
30 * @param aCatalog the associated catalog
31 */
32 public RootNode(Catalog aCatalog) {
33 super(null, aCatalog);
34 LOG.debug("Created RootNode");
35 this.catalog = aCatalog;
36 }
37
38 /**
39 * Returns this node's associated Catalog instance.
40 *
41 * @return this node's associated Description instance.
42 * @see NavigationNode#getModel()
43 */
44 public Catalog getCatalog() {
45 return (Catalog)getModel();
46 }
47
48 /**
49 * Returns this node's icon. Since the root node will be hidden
50 * by the tree, we can return <code>null</code>.
51 *
52 * @return null
53 */
54 public Icon getIcon(boolean sel) {
55 return null;
56 }
57
58 /**
59 * Returns this node's name. Since the root node will be hidden
60 * by the tree, we can return <code>null</code>.
61 *
62 * @return null
63 */
64 public String getName() {
65 return null;
66 }
67
68
69 /**
70 * Loads all the artists in the collection sorted by name ascending.
71 */
72 public void loadChildren() {
73 if (!childrenLoaded) {
74 loadingChildren = true;
75 LOG.debug("Loading artists");
76 Iterator iter = catalog.getArtists().iterator();
77 while (iter.hasNext()) {
78 Artist artist = (Artist)iter.next();
79 if (LOG.isDebugEnabled()) {
80 LOG.debug("Loading artist: "+artist.getName());
81 }
82 ArtistNode node = new ArtistNode(this, artist);
83 this.add(node);
84 }
85 loadingChildren = false;
86 childrenLoaded = true;
87 }
88 }
89
90 }