|
Lines 23-29
Link Here
|
| 23 |
import org.eclipse.core.runtime.IStatus; |
23 |
import org.eclipse.core.runtime.IStatus; |
| 24 |
import org.eclipse.core.runtime.Platform; |
24 |
import org.eclipse.core.runtime.Platform; |
| 25 |
import org.eclipse.core.runtime.Status; |
25 |
import org.eclipse.core.runtime.Status; |
| 26 |
import org.eclipse.core.runtime.jobs.Job; |
|
|
| 27 |
import org.eclipse.jface.resource.ImageDescriptor; |
26 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 28 |
import org.eclipse.jface.resource.JFaceResources; |
27 |
import org.eclipse.jface.resource.JFaceResources; |
| 29 |
import org.eclipse.osgi.util.NLS; |
28 |
import org.eclipse.osgi.util.NLS; |
|
Lines 33-39
Link Here
|
| 33 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
32 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
| 34 |
import org.eclipse.ui.internal.progress.ProgressManagerUtil; |
33 |
import org.eclipse.ui.internal.progress.ProgressManagerUtil; |
| 35 |
import org.eclipse.ui.internal.progress.ProgressMessages; |
34 |
import org.eclipse.ui.internal.progress.ProgressMessages; |
| 36 |
import org.eclipse.ui.progress.IProgressConstants; |
|
|
| 37 |
import org.eclipse.ui.progress.WorkbenchJob; |
35 |
import org.eclipse.ui.progress.WorkbenchJob; |
| 38 |
|
36 |
|
| 39 |
import com.ibm.icu.text.DateFormat; |
37 |
import com.ibm.icu.text.DateFormat; |
|
Lines 89-118
Link Here
|
| 89 |
/** |
87 |
/** |
| 90 |
* Add a new error to the list for the supplied job. |
88 |
* Add a new error to the list for the supplied job. |
| 91 |
* |
89 |
* |
| 92 |
* @param status |
90 |
* @param statusAdapter |
| 93 |
*/ |
91 |
*/ |
| 94 |
void addError(IStatus status, Object extension) { |
92 |
public void addStatusAdapter(StatusAdapter statusAdapter) { |
| 95 |
|
93 |
StatusAdapterInfo statusAdapterInfo = new StatusAdapterInfo( |
| 96 |
// Handle out of memory errors via the workbench |
94 |
statusAdapter); |
| 97 |
final Throwable exception = status.getException(); |
95 |
showError(statusAdapterInfo); |
| 98 |
if (exception != null && exception instanceof OutOfMemoryError) { |
|
|
| 99 |
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { |
| 100 |
//TODO change !!! possible invocation loops |
| 101 |
/* |
| 102 |
* (non-Javadoc) |
| 103 |
* |
| 104 |
* @see java.lang.Runnable#run() |
| 105 |
*/ |
| 106 |
public void run() { |
| 107 |
// is it really needed |
| 108 |
//ExceptionHandler.getInstance().handleException(exception); |
| 109 |
} |
| 110 |
}); |
| 111 |
|
| 112 |
return; |
| 113 |
} |
| 114 |
StatusInfo errorInfo = new StatusInfo(status, extension); |
| 115 |
showError(errorInfo); |
| 116 |
} |
96 |
} |
| 117 |
|
97 |
|
| 118 |
/** |
98 |
/** |
|
Lines 122-132
Link Here
|
| 122 |
* @param statusInfo |
102 |
* @param statusInfo |
| 123 |
* the error to be displayed |
103 |
* the error to be displayed |
| 124 |
*/ |
104 |
*/ |
| 125 |
private void showError(final StatusInfo statusInfo) { |
105 |
private void showError(final StatusAdapterInfo statusAdapterInfo) { |
| 126 |
|
106 |
|
| 127 |
if (!PlatformUI.isWorkbenchRunning()) { |
107 |
if (!PlatformUI.isWorkbenchRunning()) { |
| 128 |
// we are shuttting down, so just log |
108 |
// we are shuttting down, so just log |
| 129 |
WorkbenchPlugin.log(statusInfo.getStatus()); |
109 |
WorkbenchPlugin.log(statusAdapterInfo.getStatusAdapter() |
|
|
110 |
.getStatus()); |
| 130 |
return; |
111 |
return; |
| 131 |
} |
112 |
} |
| 132 |
|
113 |
|
|
Lines 138-155
Link Here
|
| 138 |
|
119 |
|
| 139 |
// Add the error in the UI thread to ensure thread safety in the |
120 |
// Add the error in the UI thread to ensure thread safety in the |
| 140 |
// dialog |
121 |
// dialog |
| 141 |
errors.add(statusInfo); |
122 |
errors.add(statusAdapterInfo); |
| 142 |
if (dialog != null) { |
123 |
if (dialog != null) { |
| 143 |
dialog.refresh(); |
124 |
dialog.refresh(); |
| 144 |
} else if (Platform.isRunning()) { |
125 |
} else if (Platform.isRunning()) { |
| 145 |
// Delay prompting if the job property is set |
126 |
// Delay prompting if the job property is set |
| 146 |
Object noPromptProperty = null; |
127 |
Object noPromptProperty = null; |
| 147 |
Object extension = statusInfo.getExtension(); |
128 |
// Object extension = statusAdapterInfo.getExtension(); |
| 148 |
|
129 |
|
| 149 |
if (extension != null && extension instanceof Job) { |
130 |
// if (extension != null && extension instanceof Job) { |
| 150 |
noPromptProperty = ((Job) extension) |
131 |
// noPromptProperty = ((Job) extension) |
| 151 |
.getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY); |
132 |
// .getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY); |
| 152 |
} |
133 |
// } |
| 153 |
|
134 |
|
| 154 |
boolean prompt = true; |
135 |
boolean prompt = true; |
| 155 |
if (noPromptProperty instanceof Boolean) { |
136 |
if (noPromptProperty instanceof Boolean) { |
|
Lines 158-164
Link Here
|
| 158 |
|
139 |
|
| 159 |
if (prompt) { |
140 |
if (prompt) { |
| 160 |
return openErrorDialog(null /* use default title */, |
141 |
return openErrorDialog(null /* use default title */, |
| 161 |
null /* use default message */, statusInfo); |
142 |
null /* use default message */, statusAdapterInfo); |
| 162 |
} |
143 |
} |
| 163 |
} |
144 |
} |
| 164 |
return Status.OK_STATUS; |
145 |
return Status.OK_STATUS; |
|
Lines 190-196
Link Here
|
| 190 |
* @return IStatus |
171 |
* @return IStatus |
| 191 |
*/ |
172 |
*/ |
| 192 |
private IStatus openErrorDialog(String title, String msg, |
173 |
private IStatus openErrorDialog(String title, String msg, |
| 193 |
final StatusInfo statusInfo) { |
174 |
final StatusAdapterInfo statusAdapterInfo) { |
| 194 |
IWorkbench workbench = PlatformUI.getWorkbench(); |
175 |
IWorkbench workbench = PlatformUI.getWorkbench(); |
| 195 |
|
176 |
|
| 196 |
// Abort on shutdown |
177 |
// Abort on shutdown |
|
Lines 199-205
Link Here
|
| 199 |
return Status.CANCEL_STATUS; |
180 |
return Status.CANCEL_STATUS; |
| 200 |
} |
181 |
} |
| 201 |
dialog = new StatusDialog(ProgressManagerUtil.getDefaultParent(), |
182 |
dialog = new StatusDialog(ProgressManagerUtil.getDefaultParent(), |
| 202 |
title, msg, statusInfo, IStatus.OK | IStatus.INFO |
183 |
title, msg, statusAdapterInfo, IStatus.OK | IStatus.INFO |
| 203 |
| IStatus.WARNING | IStatus.ERROR); |
184 |
| IStatus.WARNING | IStatus.ERROR); |
| 204 |
|
185 |
|
| 205 |
dialog.open(); |
186 |
dialog.open(); |
|
Lines 229-236
Link Here
|
| 229 |
Iterator errorIterator = errorsToRemove.iterator(); |
210 |
Iterator errorIterator = errorsToRemove.iterator(); |
| 230 |
Set errorStatuses = new HashSet(); |
211 |
Set errorStatuses = new HashSet(); |
| 231 |
while (errorIterator.hasNext()) { |
212 |
while (errorIterator.hasNext()) { |
| 232 |
StatusInfo next = (StatusInfo) errorIterator.next(); |
213 |
StatusAdapterInfo next = (StatusAdapterInfo) errorIterator.next(); |
| 233 |
errorStatuses.add(next.getStatus()); |
214 |
errorStatuses.add(next.getStatusAdapter().getStatus()); |
| 234 |
} |
215 |
} |
| 235 |
|
216 |
|
| 236 |
// TODO those classes have default access modifier :/ |
217 |
// TODO those classes have default access modifier :/ |
|
Lines 258-324
Link Here
|
| 258 |
} |
239 |
} |
| 259 |
|
240 |
|
| 260 |
/** |
241 |
/** |
| 261 |
* Display the error for the given job and any other errors that have been |
|
|
| 262 |
* accumulated. This method must be invoked from the UI thread. |
| 263 |
* |
| 264 |
* @param job |
| 265 |
* the job whose error should be displayed |
| 266 |
* @param title |
| 267 |
* The title for the dialog |
| 268 |
* @param msg |
| 269 |
* The message for the dialog. |
| 270 |
* @return <code>true</code> if the info for the job was found and the |
| 271 |
* error displayed and <code>false</code> otherwise. |
| 272 |
*/ |
| 273 |
public boolean showErrorFor(Job job, String title, String msg) { |
| 274 |
if (dialog != null) { |
| 275 |
// The dialog is already open so the error is being displayed |
| 276 |
return true; |
| 277 |
} |
| 278 |
StatusInfo info = null; |
| 279 |
if (job == null) { |
| 280 |
info = getMostRecentJobError(); |
| 281 |
} else { |
| 282 |
info = getErrorInfo(job); |
| 283 |
} |
| 284 |
if (info != null) { |
| 285 |
openErrorDialog(title, msg, info); |
| 286 |
return true; |
| 287 |
} |
| 288 |
return false; |
| 289 |
} |
| 290 |
|
| 291 |
/* |
| 292 |
* Return the most recent error. |
| 293 |
*/ |
| 294 |
private StatusInfo getMostRecentJobError() { |
| 295 |
StatusInfo mostRecentInfo = null; |
| 296 |
for (Iterator iter = errors.iterator(); iter.hasNext();) { |
| 297 |
StatusInfo info = (StatusInfo) iter.next(); |
| 298 |
if ((mostRecentInfo == null || info.getTimestamp() > mostRecentInfo |
| 299 |
.getTimestamp()) |
| 300 |
&& info.getExtension() != null |
| 301 |
&& info.getExtension() instanceof Job) { |
| 302 |
mostRecentInfo = info; |
| 303 |
} |
| 304 |
} |
| 305 |
return mostRecentInfo; |
| 306 |
} |
| 307 |
|
| 308 |
/* |
| 309 |
* Return the error info for the given job |
| 310 |
*/ |
| 311 |
private StatusInfo getErrorInfo(Job job) { |
| 312 |
for (Iterator iter = errors.iterator(); iter.hasNext();) { |
| 313 |
StatusInfo info = (StatusInfo) iter.next(); |
| 314 |
if (info.getExtension() == job) { |
| 315 |
return info; |
| 316 |
} |
| 317 |
} |
| 318 |
return null; |
| 319 |
} |
| 320 |
|
| 321 |
/** |
| 322 |
* Return whether the manager has errors to report. |
242 |
* Return whether the manager has errors to report. |
| 323 |
* |
243 |
* |
| 324 |
* @return whether the manager has errors to report |
244 |
* @return whether the manager has errors to report |
|
Lines 340-384
Link Here
|
| 340 |
* A wrapper class for statuses displayed in the dialog. |
260 |
* A wrapper class for statuses displayed in the dialog. |
| 341 |
* |
261 |
* |
| 342 |
*/ |
262 |
*/ |
| 343 |
protected static class StatusInfo implements Comparable { |
263 |
protected static class StatusAdapterInfo implements Comparable { |
| 344 |
|
264 |
|
| 345 |
private final IStatus status; |
265 |
private final StatusAdapter statusAdapter; |
| 346 |
|
266 |
|
| 347 |
private final long timestamp; |
267 |
private final long timestamp; |
| 348 |
|
268 |
|
| 349 |
private final Object extension; |
|
|
| 350 |
|
| 351 |
/** |
| 352 |
* Constructs a simple <code>StatusInfo</code>, without any |
| 353 |
* extensions. |
| 354 |
* |
| 355 |
* @param status |
| 356 |
* the root status for this status info |
| 357 |
*/ |
| 358 |
public StatusInfo(IStatus status) { |
| 359 |
this(status, null); |
| 360 |
} |
| 361 |
|
| 362 |
/** |
269 |
/** |
| 363 |
* Constructs a <code>StatusInfo</code> with a extension (used to |
270 |
* Constructs a <code>StatusInfo</code> with a extension (used to |
| 364 |
* retrieve extra properties). |
271 |
* retrieve extra properties). |
| 365 |
* |
272 |
* |
| 366 |
* @param status |
273 |
* @param statusAdapter |
| 367 |
* the root status for this status info |
274 |
* the root status adapter for this info |
| 368 |
* @param extension |
|
|
| 369 |
* the extension |
| 370 |
*/ |
275 |
*/ |
| 371 |
public StatusInfo(IStatus status, Object extension) { |
276 |
public StatusAdapterInfo(StatusAdapter statusAdapter) { |
| 372 |
this.status = status; |
277 |
this.statusAdapter = statusAdapter; |
| 373 |
timestamp = System.currentTimeMillis(); |
278 |
timestamp = System.currentTimeMillis(); |
| 374 |
this.extension = extension; |
|
|
| 375 |
} |
279 |
} |
| 376 |
|
280 |
|
| 377 |
String getDisplayString() { |
281 |
String getDisplayString() { |
| 378 |
String text = status.getMessage(); |
282 |
String text = statusAdapter.getStatus().getMessage(); |
| 379 |
if (this.extension != null && this.extension instanceof Job) { |
283 |
|
| 380 |
text = ((Job) extension).getName(); |
284 |
// if (this.extension != null && this.extension instanceof Job) { |
| 381 |
} |
285 |
// text = ((Job) extension).getName(); |
|
|
286 |
// } |
| 382 |
|
287 |
|
| 383 |
return NLS.bind(ProgressMessages.JobInfo_Error, (new Object[] { |
288 |
return NLS.bind(ProgressMessages.JobInfo_Error, (new Object[] { |
| 384 |
text, |
289 |
text, |
|
Lines 401-434
Link Here
|
| 401 |
* @see java.lang.Comparable#compareTo(T) |
306 |
* @see java.lang.Comparable#compareTo(T) |
| 402 |
*/ |
307 |
*/ |
| 403 |
public int compareTo(Object arg0) { |
308 |
public int compareTo(Object arg0) { |
| 404 |
if (arg0 instanceof StatusInfo) { |
309 |
if (arg0 instanceof StatusAdapterInfo) { |
| 405 |
// Order ErrorInfo by time received |
310 |
// Order StatusAdapterInfo by time received |
| 406 |
long otherTimestamp = ((StatusInfo) arg0).timestamp; |
311 |
long otherTimestamp = ((StatusAdapterInfo) arg0).timestamp; |
| 407 |
if (timestamp < otherTimestamp) { |
312 |
if (timestamp < otherTimestamp) { |
| 408 |
return -1; |
313 |
return -1; |
| 409 |
} else if (timestamp > otherTimestamp) { |
314 |
} else if (timestamp > otherTimestamp) { |
| 410 |
return 1; |
315 |
return 1; |
| 411 |
} else { |
316 |
} else { |
| 412 |
return getDisplayString().compareTo( |
317 |
return getDisplayString().compareTo( |
| 413 |
((StatusInfo) arg0).getDisplayString()); |
318 |
((StatusAdapterInfo) arg0).getDisplayString()); |
| 414 |
} |
319 |
} |
| 415 |
} |
320 |
} |
| 416 |
return 0; |
321 |
return 0; |
| 417 |
} |
322 |
} |
| 418 |
|
323 |
|
| 419 |
/** |
324 |
/** |
| 420 |
* @return Returns the status. |
325 |
* @return Returns the status adapter. |
| 421 |
*/ |
326 |
*/ |
| 422 |
public IStatus getStatus() { |
327 |
public StatusAdapter getStatusAdapter() { |
| 423 |
return status; |
328 |
return statusAdapter; |
| 424 |
} |
329 |
} |
| 425 |
|
|
|
| 426 |
/** |
| 427 |
* @return Returns the extension. |
| 428 |
*/ |
| 429 |
public Object getExtension() { |
| 430 |
return extension; |
| 431 |
} |
| 432 |
|
| 433 |
} |
330 |
} |
| 434 |
} |
331 |
} |