1 11 package org.eclipse.update.core; 12 13 import java.util.Stack ; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.update.internal.core.Messages; 18 19 31 public class InstallMonitor implements IProgressMonitor { 32 33 protected IProgressMonitor monitor; 34 protected Stack tasks; 35 36 protected String taskString; 37 protected String subTaskString; 38 protected boolean showDetails; 39 protected long totalCopyCount; 40 protected long currentCount = 0; 41 42 protected class MonitorState { 43 44 private String taskString; 45 private String subTaskString; 46 private boolean showDetails; 47 private long totalCopyCount; 48 private long currentCount; 49 50 private MonitorState( 51 String taskString, 52 String subTaskString, 53 boolean showDetails, 54 long currentCount, 55 long totalCopyCount) { 56 this.taskString = taskString; 57 this.subTaskString = subTaskString; 58 this.showDetails = showDetails; 59 this.currentCount = currentCount; 60 this.totalCopyCount = totalCopyCount; 61 } 62 63 private String getTaskString() { 64 return this.taskString; 65 } 66 67 private String getSubTaskString() { 68 return this.subTaskString; 69 } 70 71 private boolean getShowDetails() { 72 return this.showDetails; 73 } 74 75 private long getCurrentCount() { 76 return this.currentCount; 77 } 78 79 private long getTotalCopyCount() { 80 return this.totalCopyCount; 81 } 82 } 83 84 protected InstallMonitor() { 85 } 86 87 93 public InstallMonitor(IProgressMonitor monitor) { 94 this.monitor = monitor; 95 this.tasks = new Stack (); 96 this.taskString = ""; this.subTaskString = ""; this.showDetails = false; 99 this.totalCopyCount = 0; 100 } 101 102 108 public void beginTask(String name, int totalWork) { 109 taskString = name; 110 monitor.beginTask(name, totalWork); 111 } 112 113 119 public void done() { 120 monitor.done(); 121 } 122 123 129 public void internalWorked(double work) { 130 monitor.internalWorked(work); 131 } 132 133 139 public boolean isCanceled() { 140 return monitor.isCanceled(); 141 } 142 143 149 public void setCanceled(boolean value) { 150 monitor.setCanceled(value); 151 } 152 153 159 public void setTaskName(String name) { 160 this.taskString = name; 161 this.subTaskString = ""; this.showDetails = false; 163 this.totalCopyCount = 0; 164 monitor.subTask(""); monitor.setTaskName(name); 166 } 167 168 174 public void subTask(String name) { 175 this.subTaskString = name; 176 this.showDetails = false; 177 this.totalCopyCount = 0; 178 monitor.subTask(name); 179 } 180 181 187 public void worked(int work) { 188 monitor.worked(work); 189 } 190 191 199 public void saveState() { 200 tasks.push( 201 new MonitorState(taskString, subTaskString, showDetails, currentCount, totalCopyCount)); 202 } 203 204 210 public void restoreState() { 211 if (tasks.size() > 0) { 212 MonitorState state = (MonitorState) tasks.pop(); 213 setTaskName(state.getTaskString()); 214 subTask(state.getSubTaskString()); 215 this.showDetails = state.getShowDetails(); 216 this.currentCount = state.getCurrentCount(); 217 this.totalCopyCount = state.getTotalCopyCount(); 218 } 219 } 220 221 231 public void showCopyDetails(boolean setting) { 232 this.showDetails = setting; 233 } 234 235 243 public void setTotalCount(long count) { 244 this.totalCopyCount = count; 245 } 246 247 255 public void setCopyCount(long count) { 256 if (showDetails && count > 0) { 257 currentCount = count; 258 long countK = count / 1024; 259 long totalK = totalCopyCount / 1024; 260 String msg = 261 (totalK <= 0) 262 ? NLS.bind(Messages.InstallMonitor_DownloadSize, (new String [] { Long.toString(countK) })) 263 : NLS.bind(Messages.InstallMonitor_DownloadSizeLong, (new String [] { Long.toString(countK), Long.toString(totalK) })); 264 monitor.subTask(subTaskString + msg); 265 } 266 } 267 268 274 public void incrementCount(long increment) { 275 setCopyCount(currentCount + increment); 276 } 277 } 278 | Popular Tags |