|
@@ -22,13 +22,15 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.ui_swing.dialogs.updater;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.updater.Update;
|
|
25
|
+import com.dmdirc.updater.UpdateChecker;
|
26
|
26
|
import com.dmdirc.updater.UpdateComponent;
|
27
|
|
-import com.dmdirc.updater.UpdateListener;
|
28
|
|
-import com.dmdirc.updater.UpdateStatus;
|
|
27
|
+import com.dmdirc.updater.manager.CachingUpdateManager;
|
|
28
|
+import com.dmdirc.updater.manager.UpdateStatus;
|
|
29
|
+import com.dmdirc.updater.manager.UpdateStatusListener;
|
29
|
30
|
|
30
|
31
|
import java.text.NumberFormat;
|
31
|
32
|
import java.util.ArrayList;
|
|
33
|
+import java.util.Collections;
|
32
|
34
|
import java.util.HashMap;
|
33
|
35
|
import java.util.List;
|
34
|
36
|
import java.util.Map;
|
|
@@ -38,7 +40,7 @@ import javax.swing.table.AbstractTableModel;
|
38
|
40
|
/**
|
39
|
41
|
* Update table model.
|
40
|
42
|
*/
|
41
|
|
-public class UpdateTableModel extends AbstractTableModel implements UpdateListener {
|
|
43
|
+public class UpdateTableModel extends AbstractTableModel implements UpdateStatusListener {
|
42
|
44
|
|
43
|
45
|
/**
|
44
|
46
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -46,26 +48,35 @@ public class UpdateTableModel extends AbstractTableModel implements UpdateListen
|
46
|
48
|
* objects being unserialized with the new class).
|
47
|
49
|
*/
|
48
|
50
|
private static final long serialVersionUID = 3;
|
|
51
|
+ /** The update manager to use. */
|
|
52
|
+ private final CachingUpdateManager updateManager;
|
49
|
53
|
/** Data list. */
|
50
|
|
- private List<Update> updates;
|
|
54
|
+ private final List<UpdateComponent> updates = new ArrayList<UpdateComponent>();
|
51
|
55
|
/** Enabled list. */
|
52
|
|
- private Map<Update, Boolean> enabled;
|
|
56
|
+ private final List<UpdateComponent> enabled = new ArrayList<UpdateComponent>();
|
|
57
|
+ /** Cached progress for each component. */
|
|
58
|
+ private final Map<UpdateComponent, Double> progress = new HashMap<UpdateComponent, Double>();
|
53
|
59
|
/** Number formatter. */
|
54
|
60
|
private NumberFormat formatter;
|
55
|
61
|
|
56
|
62
|
/** Creates a new instance of UpdateTableModel. */
|
57
|
63
|
public UpdateTableModel() {
|
58
|
|
- this(new ArrayList<Update>());
|
|
64
|
+ this(UpdateChecker.getManager(), Collections.<UpdateComponent>emptyList());
|
59
|
65
|
}
|
60
|
66
|
|
61
|
67
|
/**
|
62
|
68
|
* Creates a new instance of UpdateTableModel.
|
63
|
69
|
*
|
64
|
|
- * @param updates List of updates
|
|
70
|
+ * @param updateManager The update manager to use
|
|
71
|
+ * @param updates List of components to display
|
65
|
72
|
*/
|
66
|
|
- public UpdateTableModel(final List<Update> updates) {
|
|
73
|
+ public UpdateTableModel(final CachingUpdateManager updateManager,
|
|
74
|
+ final List<UpdateComponent> updates) {
|
67
|
75
|
super();
|
68
|
76
|
|
|
77
|
+ this.updateManager = updateManager;
|
|
78
|
+ this.updateManager.addUpdateStatusListener(this);
|
|
79
|
+
|
69
|
80
|
setUpdates(updates);
|
70
|
81
|
formatter = NumberFormat.getNumberInstance();
|
71
|
82
|
formatter.setMaximumFractionDigits(1);
|
|
@@ -77,14 +88,12 @@ public class UpdateTableModel extends AbstractTableModel implements UpdateListen
|
77
|
88
|
*
|
78
|
89
|
* @param updates List of updates
|
79
|
90
|
*/
|
80
|
|
- public void setUpdates(final List<Update> updates) {
|
81
|
|
- this.updates = new ArrayList<Update>(updates);
|
82
|
|
- this.enabled = new HashMap<Update, Boolean>();
|
83
|
|
-
|
84
|
|
- for (Update update : updates) {
|
85
|
|
- update.addUpdateListener(this);
|
86
|
|
- enabled.put(update, true);
|
87
|
|
- }
|
|
91
|
+ public void setUpdates(final List<UpdateComponent> updates) {
|
|
92
|
+ this.updates.clear();
|
|
93
|
+ this.updates.addAll(updates);
|
|
94
|
+ this.enabled.clear();
|
|
95
|
+ this.enabled.addAll(updates);
|
|
96
|
+ this.progress.clear();
|
88
|
97
|
|
89
|
98
|
fireTableDataChanged();
|
90
|
99
|
}
|
|
@@ -153,20 +162,24 @@ public class UpdateTableModel extends AbstractTableModel implements UpdateListen
|
153
|
162
|
if (rowIndex < 0) {
|
154
|
163
|
throw new IllegalArgumentException("Must specify a positive integer");
|
155
|
164
|
}
|
|
165
|
+
|
|
166
|
+ final UpdateComponent component = updates.get(rowIndex);
|
|
167
|
+
|
156
|
168
|
switch (columnIndex) {
|
157
|
169
|
case 0:
|
158
|
|
- return enabled.get(updates.get(rowIndex));
|
|
170
|
+ return enabled.contains(component);
|
159
|
171
|
case 1:
|
160
|
|
- return updates.get(rowIndex).getComponent();
|
|
172
|
+ return component;
|
161
|
173
|
case 2:
|
162
|
|
- return updates.get(rowIndex).getRemoteVersion();
|
|
174
|
+ return updateManager.getCheckResult(component).getUpdatedVersionName();
|
163
|
175
|
case 3:
|
164
|
|
- if (updates.get(rowIndex).getStatus().equals(UpdateStatus.DOWNLOADING)) {
|
165
|
|
- return updates.get(rowIndex).getStatus() + " ("
|
166
|
|
- + formatter.format(updates.get(rowIndex).getProgress()) + "%)";
|
167
|
|
- } else {
|
168
|
|
- return updates.get(rowIndex).getStatus();
|
169
|
|
- }
|
|
176
|
+ final UpdateStatus status = updateManager.getStatus(component);
|
|
177
|
+ final boolean hasProgress = progress.containsKey(component)
|
|
178
|
+ && progress.get(component) > 0;
|
|
179
|
+
|
|
180
|
+ return status.getDescription() + (hasProgress
|
|
181
|
+ ? " (" + formatter.format(progress.get(component)) + "%)"
|
|
182
|
+ : "");
|
170
|
183
|
default:
|
171
|
184
|
throw new IllegalArgumentException("Unknown column: "
|
172
|
185
|
+ columnIndex);
|
|
@@ -186,7 +199,7 @@ public class UpdateTableModel extends AbstractTableModel implements UpdateListen
|
186
|
199
|
}
|
187
|
200
|
switch (columnIndex) {
|
188
|
201
|
case 0:
|
189
|
|
- enabled.put(updates.get(rowIndex), (Boolean) aValue);
|
|
202
|
+ enabled.add(updates.get(rowIndex));
|
190
|
203
|
break;
|
191
|
204
|
default:
|
192
|
205
|
throw new IllegalArgumentException("Unknown column: "
|
|
@@ -202,7 +215,7 @@ public class UpdateTableModel extends AbstractTableModel implements UpdateListen
|
202
|
215
|
*
|
203
|
216
|
* @return Specified Update
|
204
|
217
|
*/
|
205
|
|
- public Update getUpdate(final int rowIndex) {
|
|
218
|
+ public UpdateComponent getUpdate(final int rowIndex) {
|
206
|
219
|
return updates.get(rowIndex);
|
207
|
220
|
}
|
208
|
221
|
|
|
@@ -211,8 +224,8 @@ public class UpdateTableModel extends AbstractTableModel implements UpdateListen
|
211
|
224
|
*
|
212
|
225
|
* @return Update list
|
213
|
226
|
*/
|
214
|
|
- public List<Update> getUpdates() {
|
215
|
|
- return new ArrayList<Update>(updates);
|
|
227
|
+ public List<UpdateComponent> getUpdates() {
|
|
228
|
+ return Collections.unmodifiableList(updates);
|
216
|
229
|
}
|
217
|
230
|
|
218
|
231
|
/**
|
|
@@ -222,8 +235,8 @@ public class UpdateTableModel extends AbstractTableModel implements UpdateListen
|
222
|
235
|
*
|
223
|
236
|
* @return true iif the component needs to be updated
|
224
|
237
|
*/
|
225
|
|
- public boolean isEnabled(final Update update) {
|
226
|
|
- return enabled.get(update);
|
|
238
|
+ public boolean isEnabled(final UpdateComponent update) {
|
|
239
|
+ return enabled.contains(update);
|
227
|
240
|
}
|
228
|
241
|
|
229
|
242
|
/**
|
|
@@ -242,9 +255,8 @@ public class UpdateTableModel extends AbstractTableModel implements UpdateListen
|
242
|
255
|
*
|
243
|
256
|
* @param update Update to add
|
244
|
257
|
*/
|
245
|
|
- public void addRow(final Update update) {
|
|
258
|
+ public void addRow(final UpdateComponent update) {
|
246
|
259
|
updates.add(update);
|
247
|
|
- update.addUpdateListener(this);
|
248
|
260
|
fireTableRowsInserted(updates.indexOf(update), updates.indexOf(update));
|
249
|
261
|
}
|
250
|
262
|
|
|
@@ -254,7 +266,6 @@ public class UpdateTableModel extends AbstractTableModel implements UpdateListen
|
254
|
266
|
* @param row Row to remove
|
255
|
267
|
*/
|
256
|
268
|
public void removeRow(final int row) {
|
257
|
|
- updates.get(row).removeUpdateListener(this);
|
258
|
269
|
updates.remove(row);
|
259
|
270
|
fireTableRowsDeleted(row, row);
|
260
|
271
|
}
|
|
@@ -266,20 +277,16 @@ public class UpdateTableModel extends AbstractTableModel implements UpdateListen
|
266
|
277
|
*
|
267
|
278
|
* @return Index of the update or -1 if not found.
|
268
|
279
|
*/
|
269
|
|
- public int indexOf(final Update update) {
|
|
280
|
+ public int indexOf(final UpdateComponent update) {
|
270
|
281
|
return updates.indexOf(update);
|
271
|
282
|
}
|
272
|
283
|
|
273
|
284
|
/** {@inheritDoc} */
|
274
|
285
|
@Override
|
275
|
|
- public void updateStatusChange(final Update update, final UpdateStatus status) {
|
276
|
|
- fireTableCellUpdated(updates.indexOf(update), 3);
|
277
|
|
- }
|
278
|
|
-
|
279
|
|
- /** {@inheritDoc} */
|
280
|
|
- @Override
|
281
|
|
- public void updateProgressChange(final Update update, final float progress) {
|
282
|
|
- fireTableCellUpdated(updates.indexOf(update), 3);
|
|
286
|
+ public void updateStatusChanged(final UpdateComponent component,
|
|
287
|
+ final UpdateStatus status, final double progress) {
|
|
288
|
+ this.progress.put(component, progress);
|
|
289
|
+ fireTableCellUpdated(updates.indexOf(component), 3);
|
283
|
290
|
}
|
284
|
291
|
}
|
285
|
292
|
|