1   /**
2    * Distribution License:
3    * BibleDesktop is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU General Public License, version 2 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/gpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: BookNode.java 2091 2011-03-07 04:15:31Z dmsmith $
21   */
22  package org.crosswire.bibledesktop.book.install;
23  
24  import java.util.Set;
25  
26  import javax.swing.tree.DefaultMutableTreeNode;
27  
28  import org.crosswire.jsword.book.Book;
29  import org.crosswire.jsword.book.BookSet;
30  
31  /**
32   * A Node for a book in a tree. It may be a property of a BookMetaData or the
33   * BookMetaData itself.
34   * 
35   * @see gnu.gpl.License for license details.<br>
36   *      The copyright to this program is held by it's authors.
37   * @author DM Smith [dmsmith555 at yahoo dot com]
38   */
39  public class BookNode extends DefaultMutableTreeNode {
40  
41      public BookNode(Object node, BookSet books, int level, Object... grouping) {
42          setUserObject(node);
43          if (level < grouping.length) {
44              String key = (String) grouping[level];
45              Set<Object> group = books.getGroup(key);
46              for (Object value : group) {
47                  BookSet subBooks = books.filter(key, value);
48                  add(new BookNode(value, subBooks, level + 1, grouping));
49              }
50          } else if (books != null) {
51              for (Book book : books) {
52                  add(new BookNode(book, null, level + 1, grouping));
53              }
54          }
55      }
56  
57      /**
58       * Serialization ID
59       */
60      private static final long serialVersionUID = 3256442525387602231L;
61  }
62