View Javadoc

1   package com.melloware.jukes.gui.view.dialogs;
2   
3   import javax.swing.table.AbstractTableModel;
4   
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   
8   import com.jgoodies.uif.application.Application;
9   import com.melloware.jukes.db.orm.Disc;
10  import com.melloware.jukes.gui.tool.Resources;
11  import com.melloware.jukes.gui.view.MainFrame;
12  import com.melloware.jukes.util.MessageUtil;
13  
14  /**
15   * The table model for displaying results in the disc search dialog.
16   * <p>
17   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
18   * @author Emil A. Lefkof III <info@melloware.com>
19   * @version 4.0 AZ 2009
20   */
21  public final class DiscTableModel extends AbstractTableModel {
22  
23     private static final Log LOG = LogFactory.getLog(DiscTableModel.class);
24     private Object[] data;
25     private final String[] columnNames = { Resources.getString("label.artist"), Resources.getString("label.disc"),
26              Resources.getString("label.year"), Resources.getString("label.genre"),
27              Resources.getString("label.bitrate"), Resources.getString("label.notes") };
28  
29     /**
30      * Constructor that takes a collection.
31      */
32     public DiscTableModel() {
33        super();
34        LOG.debug("DiscTableModel created.");
35        this.data = null;
36     }
37  
38     /**
39      * Constructor that takes a collection.
40      */
41     public DiscTableModel(Object[] aData) {
42        super();
43        LOG.debug("DiscTableModel created.");
44        this.data = aData;
45     }
46  
47     /*
48      * (non-Javadoc)
49      * @see javax.swing.table.TableModel#getColumnCount()
50      */
51     public int getColumnCount() {
52        return columnNames.length;
53     }
54  
55     /*
56      * (non-Javadoc)
57      * @see javax.swing.table.AbstractTableModel#getColumnName(int)
58      */
59     @Override
60     public String getColumnName(int col) {
61        return columnNames[col];
62     }
63  
64     /**
65      * Gets the data.
66      * <p>
67      * @return Returns the data.
68      */
69     public Object[] getData() {
70        return this.data;
71     }
72  
73     /*
74      * (non-Javadoc)
75      * @see javax.swing.table.TableModel#getRowCount()
76      */
77     public int getRowCount() {
78        if (data == null) {
79           return 0;
80        } else {
81           return data.length;
82        }
83     }
84  
85     /*
86      * (non-Javadoc)
87      * @see javax.swing.table.TableModel#getValueAt(int, int)
88      */
89     public Object getValueAt(int row, int col) {
90        try {
91           if (data == null) {
92              return "";
93           }
94           if (row >= data.length) {
95              return "";
96           }
97           Disc item = (Disc) data[row];
98           Object value = null;
99           switch (col) {
100          case 0: {
101             value = item.getArtist().getName();
102             break;
103          }
104          case 1: {
105             value = item.getName();
106             break;
107          }
108          case 2: {
109             value = item.getYear();
110             break;
111          }
112          case 3: {
113             value = item.getGenre();
114             break;
115          }
116          case 4: {
117             value = item.getBitrate();
118             break;
119          }
120          case 5: {
121             value = item.getNotes();
122             break;
123          }
124          default: {
125             break;
126          }
127          }
128          return (value == null) ? "" : value;
129       } catch (Exception ex) {
130          final MainFrame mainFrame = (MainFrame) Application.getDefaultParentFrame();
131          final String errorMessage = Resources.getString("messages.ErrorLoadingResults");
132          MessageUtil.showError(mainFrame, errorMessage);
133          LOG.error(errorMessage);
134          return "";
135       }
136    }
137 
138    /**
139     * Sets the data.
140     * <p>
141     * @param aData The data to set.
142     */
143    public void setData(Object[] aData) {
144       this.data = aData;
145    }
146 
147    /*
148     * (non-Javadoc)
149     * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
150     */
151    @Override
152    public boolean isCellEditable(int row, int col) {
153       return false;
154    }
155 }