Bladeren bron

Support for the new updater

Change-Id: Iab5db6ba7738102fbe45e37670f6cfd3c705fd9c
Depends-On: Ia92ef9058621aa0a3cb67dc1fb30a13642580303
Reviewed-on: http://gerrit.dmdirc.com/2382
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.7rc1
Chris Smith 12 jaren geleden
bovenliggende
commit
10688b17c9

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/addonbrowser/AddonInfo.java Bestand weergeven

@@ -135,7 +135,7 @@ public class AddonInfo {
135 135
      * @return true iff installed
136 136
      */
137 137
     public boolean isInstalled() {
138
-        for (final UpdateComponent comp : UpdateChecker.getComponents()) {
138
+        for (UpdateComponent comp : UpdateChecker.getManager().getComponents()) {
139 139
             if (comp.getName().equals("addon-" + getId())) {
140 140
                 return true;
141 141
             }

+ 8
- 5
src/com/dmdirc/addons/ui_swing/components/addonpanel/AddonToggle.java Bestand weergeven

@@ -29,6 +29,7 @@ import com.dmdirc.ui.themes.Theme;
29 29
 import com.dmdirc.ui.themes.ThemeManager;
30 30
 import com.dmdirc.updater.UpdateChecker;
31 31
 import com.dmdirc.updater.UpdateComponent;
32
+import com.dmdirc.updater.manager.UpdateStatus;
32 33
 import com.dmdirc.util.collections.ListenerList;
33 34
 
34 35
 /**
@@ -41,8 +42,6 @@ public final class AddonToggle {
41 42
     private final PluginInfo pi;
42 43
     /** The Theme object we're wrapping. */
43 44
     private final Theme theme;
44
-    /** Update component. */
45
-    private final UpdateComponent updateComponent;
46 45
     /** Addon state. */
47 46
     private boolean state;
48 47
     /** Whether or nor the addon update state should be toggled. */
@@ -74,9 +73,13 @@ public final class AddonToggle {
74 73
         } else {
75 74
             state = pi.isLoaded();
76 75
         }
77
-        updateComponent = UpdateChecker.findComponent("addon-" + getID());
78
-        if (updateComponent != null) {
79
-            updateState = UpdateChecker.isEnabled(updateComponent);
76
+
77
+        for (UpdateComponent comp : UpdateChecker.getManager().getComponents()) {
78
+            if (comp.getName().equals("addon-" + getID())) {
79
+                updateState = UpdateChecker.getManager().getStatus(comp)
80
+                        != UpdateStatus.CHECKING_NOT_PERMITTED;
81
+                break;
82
+            }
80 83
         }
81 84
     }
82 85
 

+ 2
- 2
src/com/dmdirc/addons/ui_swing/components/renderers/UpdateStatusTableCellRenderer.java Bestand weergeven

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.components.renderers;
24 24
 
25
-import com.dmdirc.updater.UpdateStatus;
25
+import com.dmdirc.updater.manager.UpdateStatus;
26 26
 
27 27
 import java.awt.Component;
28 28
 
@@ -51,7 +51,7 @@ public class UpdateStatusTableCellRenderer extends DefaultTableCellRenderer {
51 51
         if (value == null) {
52 52
             setValue("Unknown");
53 53
         } else if (value instanceof UpdateStatus) {
54
-            setValue(((UpdateStatus) value).toString());
54
+            setValue(((UpdateStatus) value).getDescription());
55 55
         } else {
56 56
             setValue(value.toString());
57 57
         }

+ 22
- 21
src/com/dmdirc/addons/ui_swing/components/statusbar/UpdaterLabel.java Bestand weergeven

@@ -28,8 +28,9 @@ import com.dmdirc.addons.ui_swing.dialogs.updater.SwingUpdaterDialog;
28 28
 import com.dmdirc.interfaces.ui.StatusBarComponent;
29 29
 import com.dmdirc.ui.IconManager;
30 30
 import com.dmdirc.updater.UpdateChecker;
31
-import com.dmdirc.updater.UpdateChecker.STATE;
32
-import com.dmdirc.updater.UpdateCheckerListener;
31
+import com.dmdirc.updater.manager.UpdateManager;
32
+import com.dmdirc.updater.manager.UpdateManagerListener;
33
+import com.dmdirc.updater.manager.UpdateManagerStatus;
33 34
 
34 35
 import java.awt.event.MouseEvent;
35 36
 
@@ -41,7 +42,7 @@ import javax.swing.JLabel;
41 42
  * status bar.
42 43
  */
43 44
 public class UpdaterLabel extends StatusbarPopupPanel<JLabel> implements
44
-        StatusBarComponent, UpdateCheckerListener {
45
+        StatusBarComponent, UpdateManagerListener {
45 46
 
46 47
     /**
47 48
      * A version number for this class. It should be changed whenever the class
@@ -63,7 +64,7 @@ public class UpdaterLabel extends StatusbarPopupPanel<JLabel> implements
63 64
 
64 65
         this.controller = controller;
65 66
         setBorder(BorderFactory.createEtchedBorder());
66
-        UpdateChecker.addListener(this);
67
+        UpdateChecker.getManager().addUpdateManagerListener(this);
67 68
         setVisible(false);
68 69
         label.setText(null);
69 70
     }
@@ -78,41 +79,41 @@ public class UpdaterLabel extends StatusbarPopupPanel<JLabel> implements
78 79
         super.mouseClicked(mouseEvent);
79 80
 
80 81
         if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
81
-            if (UpdateChecker.getStatus().equals(
82
-                    UpdateChecker.STATE.RESTART_REQUIRED)) {
82
+            if (UpdateChecker.getManager().getManagerStatus()
83
+                    == UpdateManagerStatus.IDLE_RESTART_NEEDED) {
83 84
                 controller.showDialog(SwingRestartDialog.class);
84
-            } else if (!UpdateChecker.getStatus().equals(
85
-                    UpdateChecker.STATE.CHECKING)) {
86
-                controller.showDialog(SwingUpdaterDialog.class, UpdateChecker
87
-                        .getAvailableUpdates());
85
+            } else {
86
+                controller.showDialog(SwingUpdaterDialog.class,
87
+                        UpdateChecker.getManager());
88 88
             }
89 89
         }
90 90
     }
91 91
 
92 92
     /** {@inheritDoc} */
93 93
     @Override
94
-    public void statusChanged(final STATE newStatus) {
95
-        if (newStatus.equals(STATE.IDLE)) {
94
+    protected StatusbarPopupWindow getWindow() {
95
+        return new UpdaterPopup(controller, this, controller.getMainFrame());
96
+    }
97
+
98
+    /** {@inheritDoc} */
99
+    @Override
100
+    public void updateManagerStatusChanged(final UpdateManager manager,
101
+            final UpdateManagerStatus status) {
102
+        if (status == UpdateManagerStatus.IDLE) {
96 103
             setVisible(false);
97 104
         } else {
98 105
             setVisible(true);
99 106
         }
100 107
 
101
-        if (newStatus.equals(STATE.CHECKING)) {
108
+        if (status == UpdateManagerStatus.WORKING) {
102 109
             label.setIcon(new IconManager(controller.getGlobalConfig())
103 110
                     .getIcon("hourglass"));
104
-        } else if (newStatus.equals(STATE.UPDATES_AVAILABLE)) {
111
+        } else if (status == UpdateManagerStatus.IDLE_UPDATE_AVAILABLE) {
105 112
             label.setIcon(new IconManager(controller.getGlobalConfig())
106 113
                     .getIcon("update"));
107
-        } else if (newStatus.equals(STATE.RESTART_REQUIRED)) {
114
+        } else if (status == UpdateManagerStatus.IDLE_RESTART_NEEDED) {
108 115
             label.setIcon(new IconManager(controller.getGlobalConfig())
109 116
                     .getIcon("restart-needed"));
110 117
         }
111 118
     }
112
-
113
-    /** {@inheritDoc} */
114
-    @Override
115
-    protected StatusbarPopupWindow getWindow() {
116
-        return new UpdaterPopup(controller, this, controller.getMainFrame());
117
-    }
118 119
 }

+ 8
- 28
src/com/dmdirc/addons/ui_swing/components/statusbar/UpdaterPopup.java Bestand weergeven

@@ -23,15 +23,14 @@
23 23
 package com.dmdirc.addons.ui_swing.components.statusbar;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.SwingController;
26
-import com.dmdirc.updater.Update;
27 26
 import com.dmdirc.updater.UpdateChecker;
27
+import com.dmdirc.updater.UpdateComponent;
28
+import com.dmdirc.updater.manager.UpdateStatus;
28 29
 
29 30
 import java.awt.Window;
30
-import java.util.List;
31 31
 
32 32
 import javax.swing.JLabel;
33 33
 import javax.swing.JPanel;
34
-import javax.swing.JSeparator;
35 34
 
36 35
 /**
37 36
  * Information popup for the updater label.
@@ -62,33 +61,14 @@ public class UpdaterPopup extends StatusbarPopupWindow {
62 61
     /** {@inheritDoc} */
63 62
     @Override
64 63
     protected void initContent(final JPanel panel) {
65
-        final UpdateChecker.STATE state = UpdateChecker.getStatus();
64
+        for (UpdateComponent component : UpdateChecker.getManager().getComponents()) {
65
+            final UpdateStatus status = UpdateChecker.getManager().getStatus(component);
66 66
 
67
-        if (state.equals(UpdateChecker.STATE.CHECKING)) {
68
-            panel.add(new JLabel("Checking for updates..."));
69
-        } else {
70
-            final List<Update> updates = UpdateChecker.getAvailableUpdates();
71
-
72
-            if (state.equals(UpdateChecker.STATE.RESTART_REQUIRED)) {
73
-                panel.add(new JLabel("A restart is required to install updates."),
74
-                        "span,wrap");
75
-            } else if (state.equals(UpdateChecker.STATE.UPDATING)) {
76
-                panel.add(new JLabel("Update in progress..."), "span,wrap");
77
-            } else {
78
-                panel.add(new JLabel(updates.size() == 1
79
-                        ? "There is one update available" : "There are "
80
-                        + updates.size() + " updates available"), "span,wrap");
81
-            }
82
-
83
-            panel.add(new JSeparator(), "span, growx, pushx, wrap");
84
-
85
-            for (final Update update : updates) {
86
-                panel.add(new JLabel(update.getComponent().getFriendlyName()),
67
+            if (status != UpdateStatus.IDLE && status != UpdateStatus.CHECKING_NOT_PERMITTED) {
68
+                panel.add(new JLabel(component.getFriendlyName()),
69
+                        "growx, pushx");
70
+                panel.add(new JLabel(status.getDescription()),
87 71
                         "growx, pushx");
88
-                panel.add(new JLabel(update.getRemoteVersion(), JLabel.CENTER),
89
-                        "growx, pushx, al center");
90
-                panel.add(new JLabel(update.getStatus().toString(), JLabel.RIGHT),
91
-                        "growx, pushx, al right, wrap");
92 72
             }
93 73
         }
94 74
     }

+ 1
- 1
src/com/dmdirc/addons/ui_swing/dialogs/prefs/UpdateConfigPanel.java Bestand weergeven

@@ -112,7 +112,7 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
112 112
         final ConfigManager config = controller.getGlobalConfig();
113 113
         enable = new JCheckBox();
114 114
         scrollPane = new JScrollPane();
115
-        tableModel = new UpdateTableModel(UpdateChecker.getComponents());
115
+        tableModel = new UpdateTableModel(UpdateChecker.getManager().getComponents());
116 116
         table = new PackingTable(tableModel, scrollPane);
117 117
         checkNow = new JButton("Check now");
118 118
         checkNow.setEnabled(config.getOptionBool("updater", "enable"));

+ 6
- 2
src/com/dmdirc/addons/ui_swing/dialogs/prefs/UpdateTableModel.java Bestand weergeven

@@ -24,8 +24,10 @@ package com.dmdirc.addons.ui_swing.dialogs.prefs;
24 24
 
25 25
 import com.dmdirc.updater.UpdateChecker;
26 26
 import com.dmdirc.updater.UpdateComponent;
27
+import com.dmdirc.updater.manager.UpdateStatus;
27 28
 
28 29
 import java.util.ArrayList;
30
+import java.util.Collection;
29 31
 import java.util.HashMap;
30 32
 import java.util.List;
31 33
 import java.util.Map;
@@ -60,14 +62,16 @@ public class UpdateTableModel extends AbstractTableModel {
60 62
      *
61 63
      * @param updates Update components to show
62 64
      */
63
-    public UpdateTableModel(final List<UpdateComponent> updates) {
65
+    public UpdateTableModel(final Collection<UpdateComponent> updates) {
64 66
         super();
65 67
 
66 68
         this.updates = new ArrayList<UpdateComponent>(updates);
67 69
         this.enabled = new HashMap<UpdateComponent, Boolean>();
68 70
 
69 71
         for (UpdateComponent update : this.updates) {
70
-            enabled.put(update, UpdateChecker.isEnabled(update));
72
+            enabled.put(update,
73
+                    UpdateChecker.getManager().getStatus(update)
74
+                    != UpdateStatus.CHECKING_NOT_PERMITTED);
71 75
         }
72 76
     }
73 77
 

+ 37
- 27
src/com/dmdirc/addons/ui_swing/dialogs/updater/SwingUpdaterDialog.java Bestand weergeven

@@ -30,14 +30,18 @@ import com.dmdirc.addons.ui_swing.components.renderers.UpdateComponentTableCellR
30 30
 import com.dmdirc.addons.ui_swing.components.renderers.UpdateStatusTableCellRenderer;
31 31
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
32 32
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
33
-import com.dmdirc.updater.Update;
34 33
 import com.dmdirc.updater.UpdateChecker;
35
-import com.dmdirc.updater.UpdateChecker.STATE;
36
-import com.dmdirc.updater.UpdateCheckerListener;
34
+import com.dmdirc.updater.UpdateComponent;
35
+import com.dmdirc.updater.manager.CachingUpdateManager;
36
+import com.dmdirc.updater.manager.UpdateManager;
37
+import com.dmdirc.updater.manager.UpdateManagerListener;
38
+import com.dmdirc.updater.manager.UpdateManagerStatus;
39
+import com.dmdirc.updater.manager.UpdateStatus;
37 40
 
38 41
 import java.awt.Dimension;
39 42
 import java.awt.event.ActionEvent;
40 43
 import java.awt.event.ActionListener;
44
+import java.util.ArrayList;
41 45
 import java.util.List;
42 46
 
43 47
 import javax.swing.JButton;
@@ -54,10 +58,12 @@ import net.miginfocom.swing.MigLayout;
54 58
  * and walks them through the process of downloading the update.
55 59
  */
56 60
 public final class SwingUpdaterDialog extends StandardDialog implements
57
-        ActionListener, UpdateCheckerListener {
61
+        ActionListener, UpdateManagerListener {
58 62
 
59 63
     /** Serial version UID. */
60 64
     private static final long serialVersionUID = 3;
65
+    /** The update manager to use. */
66
+    private final CachingUpdateManager updateManager;
61 67
     /** Update table. */
62 68
     private JTable table;
63 69
     /** Table scrollpane. */
@@ -72,18 +78,19 @@ public final class SwingUpdaterDialog extends StandardDialog implements
72 78
     /**
73 79
      * Creates a new instance of the updater dialog.
74 80
      *
75
-     * @param updates A list of updates that are available.
81
+     * @param updateManager The update manager to use for information
76 82
      * @param controller Swing controller
77 83
      */
78
-    public SwingUpdaterDialog(final List<Update> updates,
84
+    public SwingUpdaterDialog(final CachingUpdateManager updateManager,
79 85
             final SwingController controller) {
80 86
         super(controller, ModalityType.MODELESS);
81 87
 
82
-        initComponents(updates);
83
-        layoutComponents();
88
+        this.updateManager = updateManager;
84 89
 
85
-        UpdateChecker.addListener(this);
90
+        initComponents();
91
+        layoutComponents();
86 92
 
93
+        updateManager.addUpdateManagerListener(this);
87 94
         getOkButton().addActionListener(this);
88 95
         getCancelButton().addActionListener(this);
89 96
 
@@ -96,7 +103,7 @@ public final class SwingUpdaterDialog extends StandardDialog implements
96 103
      *
97 104
      * @param updates The updates that are available
98 105
      */
99
-    private void initComponents(final List<Update> updates) {
106
+    private void initComponents() {
100 107
         setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
101 108
         updateStatusRenderer = new UpdateStatusTableCellRenderer();
102 109
         updateComponentRenderer = new UpdateComponentTableCellRenderer();
@@ -104,8 +111,16 @@ public final class SwingUpdaterDialog extends StandardDialog implements
104 111
         header = new TextLabel("An update is available for one or more "
105 112
                 + "components of DMDirc:");
106 113
 
114
+        final List<UpdateComponent> updates = new ArrayList<UpdateComponent>();
115
+        for (UpdateComponent component : updateManager.getComponents()) {
116
+            if (updateManager.getStatus(component) != UpdateStatus.IDLE
117
+                    && updateManager.getStatus(component) != UpdateStatus.CHECKING_NOT_PERMITTED) {
118
+                updates.add(component);
119
+            }
120
+        }
121
+
107 122
         scrollPane = new JScrollPane();
108
-        table = new PackingTable(new UpdateTableModel(updates), scrollPane) {
123
+        table = new PackingTable(new UpdateTableModel(updateManager, updates), scrollPane) {
109 124
 
110 125
             /** Serialisation version ID. */
111 126
             private static final long serialVersionUID = 1;
@@ -165,23 +180,21 @@ public final class SwingUpdaterDialog extends StandardDialog implements
165 180
 
166 181
             header.setText("DMDirc is updating the following components:");
167 182
 
168
-            for (Update update : ((UpdateTableModel) table.getModel()).getUpdates()) {
169
-                if (!((UpdateTableModel) table.getModel()).isEnabled(update)) {
170
-                    UpdateChecker.removeUpdate(update);
171
-                }
172
-            }
173
-
174 183
             new LoggingSwingWorker<Void, Void>() {
175 184
 
176 185
                 /** {@inheritDoc} */
177 186
                 @Override
178 187
                 protected Void doInBackground() {
179
-                    UpdateChecker.applyUpdates();
188
+                    for (UpdateComponent update : ((UpdateTableModel) table.getModel()).getUpdates()) {
189
+                        if (((UpdateTableModel) table.getModel()).isEnabled(update)) {
190
+                            updateManager.install(update);
191
+                        }
192
+                    }
180 193
                     return null;
181 194
                 }
182 195
             }.executeInExecutor();
183 196
 
184
-            if (UpdateChecker.getStatus() == STATE.RESTART_REQUIRED) {
197
+            if (UpdateChecker.getManager().getManagerStatus() == UpdateManagerStatus.IDLE_RESTART_NEEDED) {
185 198
                 getController().showDialog(SwingRestartDialog.class);
186 199
                 dispose();
187 200
             }
@@ -199,19 +212,16 @@ public final class SwingUpdaterDialog extends StandardDialog implements
199 212
 
200 213
     /** {@inheritDoc} */
201 214
     @Override
202
-    public void statusChanged(final STATE newStatus) {
215
+    public void updateManagerStatusChanged(final UpdateManager manager,
216
+            final UpdateManagerStatus status) {
203 217
         UIUtilities.invokeLater(new Runnable() {
204 218
 
205 219
             /** {@inheritDoc} */
206 220
             @Override
207 221
             public void run() {
208
-                if (newStatus == STATE.UPDATING) {
209
-                    getOkButton().setEnabled(false);
210
-                } else {
211
-                    getOkButton().setEnabled(true);
212
-                }
213
-                if (newStatus == STATE.RESTART_REQUIRED) {
214
-                    getCancelButton().setVisible(false);
222
+                getOkButton().setEnabled(status != UpdateManagerStatus.WORKING);
223
+
224
+                if (status == UpdateManagerStatus.IDLE_RESTART_NEEDED) {
215 225
                     dispose();
216 226
                 } else {
217 227
                     getCancelButton().setVisible(true);

+ 51
- 44
src/com/dmdirc/addons/ui_swing/dialogs/updater/UpdateTableModel.java Bestand weergeven

@@ -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
 

Laden…
Annuleren
Opslaan