|
Lines 30-35
Link Here
|
| 30 |
import org.eclipse.ui.internal.ExceptionHandler; |
30 |
import org.eclipse.ui.internal.ExceptionHandler; |
| 31 |
import org.eclipse.ui.internal.Workbench; |
31 |
import org.eclipse.ui.internal.Workbench; |
| 32 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
32 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
|
|
33 |
import org.eclipse.ui.internal.util.BundleUtility; |
| 34 |
import org.eclipse.ui.progress.IJobErrorInfo; |
| 35 |
import org.eclipse.ui.progress.IJobErrorNotificationManager; |
| 33 |
import org.eclipse.ui.progress.IProgressConstants; |
36 |
import org.eclipse.ui.progress.IProgressConstants; |
| 34 |
import org.eclipse.ui.progress.WorkbenchJob; |
37 |
import org.eclipse.ui.progress.WorkbenchJob; |
| 35 |
|
38 |
|
|
Lines 37-43
Link Here
|
| 37 |
* The ErrorNotificationManager is the class that manages the display of |
40 |
* The ErrorNotificationManager is the class that manages the display of |
| 38 |
* error information. |
41 |
* error information. |
| 39 |
*/ |
42 |
*/ |
| 40 |
public class ErrorNotificationManager { |
43 |
public class ErrorNotificationManager implements IJobErrorNotificationManager { |
| 41 |
|
44 |
|
| 42 |
private static final String ERROR_JOB = "errorstate.gif"; //$NON-NLS-1$ |
45 |
private static final String ERROR_JOB = "errorstate.gif"; //$NON-NLS-1$ |
| 43 |
|
46 |
|
|
Lines 51-65
Link Here
|
| 51 |
* Create a new instance of the receiver. |
54 |
* Create a new instance of the receiver. |
| 52 |
*/ |
55 |
*/ |
| 53 |
public ErrorNotificationManager() { |
56 |
public ErrorNotificationManager() { |
| 54 |
//No special initialization |
57 |
try { |
|
|
58 |
setUpImages(); |
| 59 |
} catch (MalformedURLException e) { |
| 60 |
ProgressManagerUtil.logException(e); |
| 61 |
} |
| 55 |
} |
62 |
} |
| 56 |
|
63 |
|
| 57 |
/** |
64 |
/** |
| 58 |
* Set up any images the error management needs. |
65 |
* Set up any images the error management needs. |
| 59 |
* @param iconsRoot |
|
|
| 60 |
* @throws MalformedURLException |
66 |
* @throws MalformedURLException |
| 61 |
*/ |
67 |
*/ |
| 62 |
void setUpImages(URL iconsRoot) throws MalformedURLException { |
68 |
void setUpImages() throws MalformedURLException { |
|
|
69 |
URL iconsRoot = BundleUtility.find(PlatformUI.PLUGIN_ID, |
| 70 |
ProgressManager.PROGRESS_FOLDER); |
| 71 |
|
| 63 |
JFaceResources.getImageRegistry().put(ERROR_JOB_KEY, |
72 |
JFaceResources.getImageRegistry().put(ERROR_JOB_KEY, |
| 64 |
ImageDescriptor.createFromURL(new URL(iconsRoot, ERROR_JOB))); |
73 |
ImageDescriptor.createFromURL(new URL(iconsRoot, ERROR_JOB))); |
| 65 |
} |
74 |
} |
|
Lines 69-75
Link Here
|
| 69 |
* @param status |
78 |
* @param status |
| 70 |
* @param job |
79 |
* @param job |
| 71 |
*/ |
80 |
*/ |
| 72 |
void addError(IStatus status, Job job) { |
81 |
public void addError(IStatus status, Job job) { |
| 73 |
|
82 |
|
| 74 |
//Handle out of memory errors via the workbench |
83 |
//Handle out of memory errors via the workbench |
| 75 |
final Throwable exception = status.getException(); |
84 |
final Throwable exception = status.getException(); |
|
Lines 85-91
Link Here
|
| 85 |
|
94 |
|
| 86 |
return; |
95 |
return; |
| 87 |
} |
96 |
} |
| 88 |
ErrorInfo errorInfo = new ErrorInfo(status, job); |
97 |
IJobErrorInfo errorInfo = new ErrorInfo(status, job); |
| 89 |
showError(errorInfo); |
98 |
showError(errorInfo); |
| 90 |
} |
99 |
} |
| 91 |
|
100 |
|
|
Lines 94-100
Link Here
|
| 94 |
* ensure that no errors are dropped. |
103 |
* ensure that no errors are dropped. |
| 95 |
* @param errorInfo the error to be displayed |
104 |
* @param errorInfo the error to be displayed |
| 96 |
*/ |
105 |
*/ |
| 97 |
private void showError(final ErrorInfo errorInfo) { |
106 |
private void showError(final IJobErrorInfo errorInfo) { |
| 98 |
|
107 |
|
| 99 |
if (!PlatformUI.isWorkbenchRunning()) { |
108 |
if (!PlatformUI.isWorkbenchRunning()) { |
| 100 |
//We are shutdown so just log |
109 |
//We are shutdown so just log |
|
Lines 129-139
Link Here
|
| 129 |
job.schedule(); |
138 |
job.schedule(); |
| 130 |
} |
139 |
} |
| 131 |
|
140 |
|
| 132 |
/** |
141 |
/* |
| 133 |
* Get the currently registered errors in the receiver. |
142 |
* (non-Javadoc) |
| 134 |
* @return Collection of ErrorInfo |
143 |
* @see org.eclipse.ui.progress.IJobErrorNotificationManager#getErrors() |
| 135 |
*/ |
144 |
*/ |
| 136 |
Collection getErrors() { |
145 |
public Collection getErrors() { |
| 137 |
return errors; |
146 |
return errors; |
| 138 |
} |
147 |
} |
| 139 |
|
148 |
|
|
Lines 145-151
Link Here
|
| 145 |
* @param errorInfo The info the dialog is being opened for. |
154 |
* @param errorInfo The info the dialog is being opened for. |
| 146 |
* @return IStatus |
155 |
* @return IStatus |
| 147 |
*/ |
156 |
*/ |
| 148 |
private IStatus openErrorDialog(String title, String msg, final ErrorInfo errorInfo) { |
157 |
private IStatus openErrorDialog(String title, String msg, final IJobErrorInfo errorInfo) { |
| 149 |
IWorkbench workbench = PlatformUI.getWorkbench(); |
158 |
IWorkbench workbench = PlatformUI.getWorkbench(); |
| 150 |
|
159 |
|
| 151 |
//Abort on shutdown |
160 |
//Abort on shutdown |
|
Lines 172-182
Link Here
|
| 172 |
* Remove all of the errors from the finished jobs |
181 |
* Remove all of the errors from the finished jobs |
| 173 |
* @param errorsToRemove The ErrorInfos that will be deleted. |
182 |
* @param errorsToRemove The ErrorInfos that will be deleted. |
| 174 |
*/ |
183 |
*/ |
| 175 |
private void removeFromFinishedJobs(Collection errorsToRemove) { |
184 |
public static void removeFromFinishedJobs(Collection errorsToRemove) { |
| 176 |
Iterator errorIterator = errorsToRemove.iterator(); |
185 |
Iterator errorIterator = errorsToRemove.iterator(); |
| 177 |
Set errorStatuses = new HashSet(); |
186 |
Set errorStatuses = new HashSet(); |
| 178 |
while(errorIterator.hasNext()){ |
187 |
while(errorIterator.hasNext()){ |
| 179 |
ErrorInfo next = (ErrorInfo) errorIterator.next(); |
188 |
IJobErrorInfo next = (IJobErrorInfo) errorIterator.next(); |
| 180 |
errorStatuses.add(next.getErrorStatus()); |
189 |
errorStatuses.add(next.getErrorStatus()); |
| 181 |
} |
190 |
} |
| 182 |
|
191 |
|
|
Lines 188-220
Link Here
|
| 188 |
FinishedJobs.getInstance().remove(info); |
197 |
FinishedJobs.getInstance().remove(info); |
| 189 |
} |
198 |
} |
| 190 |
} |
199 |
} |
| 191 |
|
|
|
| 192 |
} |
200 |
} |
| 193 |
|
201 |
|
| 194 |
/** |
202 |
/** |
| 195 |
* Clear all of the errors held onto by the receiver. |
203 |
* Clear all of the errors held onto by the receiver. |
| 196 |
*/ |
204 |
*/ |
| 197 |
private void clearAllErrors() { |
205 |
public void clearAllErrors() { |
| 198 |
removeFromFinishedJobs(errors); |
206 |
removeFromFinishedJobs(errors); |
| 199 |
errors.clear(); |
207 |
errors.clear(); |
| 200 |
} |
208 |
} |
| 201 |
|
209 |
|
| 202 |
/** |
210 |
/* (non-Javadoc) |
| 203 |
* Display the error for the given job and any other errors |
211 |
* @see org.eclipse.ui.internal.progress.IJobErrorNotificationManager#showErrorFor(org.eclipse.core.runtime.jobs.Job, java.lang.String, java.lang.String) |
| 204 |
* that have been accumulated. This method must be invoked |
212 |
*/ |
| 205 |
* from the UI thread. |
|
|
| 206 |
* @param job the job whose error should be displayed |
| 207 |
* @param title The title for the dialog |
| 208 |
* @param msg The message for the dialog. |
| 209 |
* @return <code>true</code> if the info for the job was found and the error |
| 210 |
* displayed and <code>false</code> otherwise. |
| 211 |
*/ |
| 212 |
public boolean showErrorFor(Job job, String title, String msg) { |
213 |
public boolean showErrorFor(Job job, String title, String msg) { |
| 213 |
if (dialog != null) { |
214 |
if (dialog != null) { |
| 214 |
// The dialog is already open so the error is being displayed |
215 |
// The dialog is already open so the error is being displayed |
| 215 |
return true; |
216 |
return true; |
| 216 |
} |
217 |
} |
| 217 |
ErrorInfo info = getErrorInfo(job); |
218 |
IJobErrorInfo info = getErrorInfo(job); |
| 218 |
if (job == null) { |
219 |
if (job == null) { |
| 219 |
info = getMostRecentError(); |
220 |
info = getMostRecentError(); |
| 220 |
} else { |
221 |
} else { |
|
Lines 230-236
Link Here
|
| 230 |
/* |
231 |
/* |
| 231 |
* Return the most recent error. |
232 |
* Return the most recent error. |
| 232 |
*/ |
233 |
*/ |
| 233 |
private ErrorInfo getMostRecentError() { |
234 |
private IJobErrorInfo getMostRecentError() { |
| 234 |
ErrorInfo mostRecentInfo = null; |
235 |
ErrorInfo mostRecentInfo = null; |
| 235 |
for (Iterator iter = errors.iterator(); iter.hasNext();) { |
236 |
for (Iterator iter = errors.iterator(); iter.hasNext();) { |
| 236 |
ErrorInfo info = (ErrorInfo) iter.next(); |
237 |
ErrorInfo info = (ErrorInfo) iter.next(); |
|
Lines 244-252
Link Here
|
| 244 |
/* |
245 |
/* |
| 245 |
* Return the error info for the given job |
246 |
* Return the error info for the given job |
| 246 |
*/ |
247 |
*/ |
| 247 |
private ErrorInfo getErrorInfo(Job job) { |
248 |
private IJobErrorInfo getErrorInfo(Job job) { |
| 248 |
for (Iterator iter = errors.iterator(); iter.hasNext();) { |
249 |
for (Iterator iter = errors.iterator(); iter.hasNext();) { |
| 249 |
ErrorInfo info = (ErrorInfo) iter.next(); |
250 |
IJobErrorInfo info = (IJobErrorInfo) iter.next(); |
| 250 |
if (info.getJob() == job) { |
251 |
if (info.getJob() == job) { |
| 251 |
return info; |
252 |
return info; |
| 252 |
} |
253 |
} |
|
Lines 254-273
Link Here
|
| 254 |
return null; |
255 |
return null; |
| 255 |
} |
256 |
} |
| 256 |
|
257 |
|
| 257 |
/** |
258 |
/* (non-Javadoc) |
| 258 |
* Return whether the manager has errors to report. |
259 |
* @see org.eclipse.ui.internal.progress.IJobErrorNotificationManager#hasErrors() |
| 259 |
* @return whether the manager has errors to report |
260 |
*/ |
| 260 |
*/ |
|
|
| 261 |
public boolean hasErrors() { |
261 |
public boolean hasErrors() { |
| 262 |
return !errors.isEmpty(); |
262 |
return !errors.isEmpty(); |
| 263 |
} |
263 |
} |
| 264 |
|
264 |
|
| 265 |
/** |
265 |
/** |
| 266 |
* The error dialog has been closed. Clear the list of errors and |
266 |
* The error dialog has been closed. Clear the stored dialog. |
| 267 |
* the stored dialog. |
267 |
*/ |
| 268 |
*/ |
|
|
| 269 |
public void dialogClosed() { |
268 |
public void dialogClosed() { |
| 270 |
dialog = null; |
269 |
dialog = null; |
| 271 |
clearAllErrors(); |
270 |
clearAllErrors(); |
| 272 |
} |
271 |
} |
|
|
272 |
|
| 273 |
/** |
| 274 |
* @see IJobErrorNotificationManager#clearErrors() |
| 275 |
*/ |
| 276 |
public void clearErrors() { |
| 277 |
clearAllErrors(); |
| 278 |
} |
| 273 |
} |
279 |
} |