1 package com.melloware.jukes.gui.view.dialogs;
2
3 import javax.swing.table.AbstractTableModel;
4
5 import org.apache.commons.lang.StringUtils;
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8
9 import com.jgoodies.uif.application.Application;
10 import com.jgoodies.uif.util.ResourceUtils;
11 import com.melloware.jukes.db.orm.Track;
12 import com.melloware.jukes.gui.tool.Resources;
13 import com.melloware.jukes.gui.view.MainFrame;
14 import com.melloware.jukes.util.MessageUtil;
15
16
17
18
19
20
21
22
23 public final class SearchTableModel extends AbstractTableModel {
24
25 private static final Log LOG = LogFactory.getLog(SearchTableModel.class);
26 private Object[] data;
27 private final String[] columnNames = { Resources.getString("label.artist"), Resources.getString("label.disc"),
28 Resources.getString("label.track"), Resources.getString("label.year"), Resources.getString("label.genre"),
29 Resources.getString("label.bitrate"), Resources.getString("label.notes") };
30
31
32
33
34 public SearchTableModel() {
35 super();
36 LOG.debug("SearchTableModel created.");
37 this.data = null;
38 }
39
40
41
42
43 public SearchTableModel(Object[] aData) {
44 super();
45 LOG.debug("SearchTableModel created.");
46 this.data = aData;
47 }
48
49
50
51
52
53 public int getColumnCount() {
54 return columnNames.length;
55 }
56
57
58
59
60
61 @Override
62 public String getColumnName(int col) {
63 return columnNames[col];
64 }
65
66
67
68
69
70
71 public Object[] getData() {
72 return this.data;
73 }
74
75
76
77
78
79 public int getRowCount() {
80 if (data == null) {
81 return 0;
82 } else {
83 return data.length;
84 }
85 }
86
87
88
89
90
91 public Object getValueAt(int row, int col) {
92 try {
93 if (data == null) {
94 return "";
95 }
96 if (row >= data.length) {
97 return "";
98 }
99 Track item = (Track) data[row];
100 Object value = null;
101 switch (col) {
102 case 0: {
103 value = item.getDisc().getArtist().getName();
104 break;
105 }
106 case 1: {
107 value = item.getDisc().getName();
108 break;
109 }
110 case 2: {
111 value = item.getName();
112 break;
113 }
114 case 3: {
115 value = item.getDisc().getYear();
116 break;
117 }
118 case 4: {
119 value = item.getDisc().getGenre();
120 break;
121 }
122 case 5: {
123 value = item.getBitrate();
124 break;
125 }
126 case 6: {
127 final StringBuffer sb = new StringBuffer();
128 sb.append(StringUtils.defaultIfEmpty(item.getComment(), "")).append(' ');
129 sb.append(StringUtils.defaultIfEmpty(item.getDisc().getNotes(), "")).append(' ');
130 sb.append(StringUtils.defaultIfEmpty(item.getDisc().getArtist().getNotes(), ""));
131 value = sb.toString();
132 break;
133 }
134 default: {
135 break;
136 }
137 }
138 return (value == null) ? "" : value;
139 } catch (Exception ex) {
140 final MainFrame mainFrame = (MainFrame) Application.getDefaultParentFrame();
141 final String errorMessage = ResourceUtils.getString("messages.ErrorLoadingResults");
142 MessageUtil.showError(mainFrame, errorMessage);
143 LOG.error(errorMessage);
144 return "";
145 }
146 }
147
148
149
150
151
152
153 public void setData(Object[] aData) {
154 this.data = aData;
155 }
156
157
158
159
160
161 @Override
162 public boolean isCellEditable(int row, int col) {
163 return false;
164 }
165 }