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.melloware.jukes.gui.tool.Resources;
11 import com.melloware.jukes.gui.view.MainFrame;
12 import com.melloware.jukes.util.MessageUtil;
13 import com.melloware.jukes.ws.AmazonItem;
14
15
16
17
18
19
20
21
22 public final class WebSearchTableModel
23 extends AbstractTableModel {
24
25 private static final Log LOG = LogFactory.getLog(WebSearchTableModel.class);
26 private Object[] data;
27 private final String[] columnNames = { Resources.getString("label.artist"),
28 Resources.getString("label.disc"), Resources.getString("label.year"),
29 Resources.getString("label.tracks"), Resources.getString("label.cover") };
30
31
32
33
34 public WebSearchTableModel() {
35 super();
36 LOG.debug("WebSearchTableModel created.");
37 this.data = null;
38 }
39
40
41
42
43 public WebSearchTableModel(Object[] aData) {
44 super();
45 LOG.debug("WebSearchTableModel created.");
46 this.data = aData;
47 }
48
49
50
51
52 public int getColumnCount() {
53 return columnNames.length;
54 }
55
56
57
58
59 public String getColumnName(int col) {
60 return columnNames[col];
61 }
62
63
64
65
66
67
68 public Object[] getData() {
69 return this.data;
70 }
71
72
73
74
75 public int getRowCount() {
76 if (data == null) {
77 return 0;
78 } else {
79 return data.length;
80 }
81 }
82
83
84
85
86 public Object getValueAt(int row, int col) {
87 try {
88 if (data == null) {
89 return "";
90 }
91 if (row >= data.length) {
92 return "";
93 }
94 AmazonItem item = (AmazonItem)data[row];
95 Object value = null;
96 switch (col) {
97 case 0: {
98 value = item.getArtist();
99 break;
100 }
101 case 1: {
102 value = item.getDisc();
103 break;
104 }
105 case 2: {
106 value = item.getReleaseYear();
107 break;
108 }
109 case 3: {
110 if (item.getTracks().isEmpty()) {
111 value = "No";
112 } else {
113 value = "Yes";
114 }
115 break;
116 }
117 case 4: {
118 if (StringUtils.isNotBlank(item.getBestImageUrl())) {
119 value = Integer.toString(item.getBestImageWidth()) + "x"
120 + Integer.toString(item.getBestImageHeight());
121 } else {
122 value = "";
123 }
124 break;
125 }
126 default: {
127 break;
128 }
129 }
130 return (value == null) ? "" : value;
131 } catch (Exception ex) {
132 final MainFrame mainFrame = (MainFrame) Application.getDefaultParentFrame();
133 final String errorMessage = Resources.getString("messages.ErrorLoadingResults");
134 MessageUtil.showError(mainFrame, errorMessage);
135 LOG.error(errorMessage);
136 return "";
137 }
138 }
139
140
141
142
143
144
145 public void setData(Object[] aData) {
146 this.data = aData;
147 }
148
149
150
151
152 public boolean isCellEditable(int row, int col) {
153 return false;
154 }
155 }