Lines 17-22
Link Here
|
17 |
import org.eclipse.core.runtime.CoreException; |
17 |
import org.eclipse.core.runtime.CoreException; |
18 |
import org.eclipse.core.runtime.ILogListener; |
18 |
import org.eclipse.core.runtime.ILogListener; |
19 |
import org.eclipse.core.runtime.IStatus; |
19 |
import org.eclipse.core.runtime.IStatus; |
|
|
20 |
import org.eclipse.core.runtime.ListenerList; |
20 |
import org.eclipse.core.runtime.Platform; |
21 |
import org.eclipse.core.runtime.Platform; |
21 |
import org.eclipse.core.runtime.Status; |
22 |
import org.eclipse.core.runtime.Status; |
22 |
import org.eclipse.jface.dialogs.Dialog; |
23 |
import org.eclipse.jface.dialogs.Dialog; |
Lines 25-32
Link Here
|
25 |
import org.eclipse.ui.internal.WorkbenchErrorHandlerProxy; |
26 |
import org.eclipse.ui.internal.WorkbenchErrorHandlerProxy; |
26 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
27 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
27 |
import org.eclipse.ui.internal.misc.StatusUtil; |
28 |
import org.eclipse.ui.internal.misc.StatusUtil; |
28 |
import org.eclipse.ui.internal.progress.FinishedJobs; |
|
|
29 |
import org.eclipse.ui.internal.progress.StatusAdapterHelper; |
30 |
import org.eclipse.ui.internal.statushandlers.StatusHandlerRegistry; |
29 |
import org.eclipse.ui.internal.statushandlers.StatusHandlerRegistry; |
31 |
import org.eclipse.ui.progress.IProgressConstants; |
30 |
import org.eclipse.ui.progress.IProgressConstants; |
32 |
|
31 |
|
Lines 110-119
Link Here
|
110 |
|
109 |
|
111 |
private static StatusManager MANAGER; |
110 |
private static StatusManager MANAGER; |
112 |
|
111 |
|
113 |
private AbstractStatusHandler workbenchHandler; |
112 |
private AbstractStatusHandler statusHandler; |
114 |
|
113 |
|
115 |
private List loggedStatuses = new ArrayList(); |
114 |
private List loggedStatuses = new ArrayList(); |
116 |
|
115 |
|
|
|
116 |
private ListenerList listeners = new ListenerList(); |
117 |
|
117 |
/** |
118 |
/** |
118 |
* Returns StatusManager singleton instance. |
119 |
* Returns StatusManager singleton instance. |
119 |
* |
120 |
* |
Lines 130-146
Link Here
|
130 |
Platform.addLogListener(new StatusManagerLogListener()); |
131 |
Platform.addLogListener(new StatusManagerLogListener()); |
131 |
} |
132 |
} |
132 |
|
133 |
|
133 |
/** |
134 |
private AbstractStatusHandler getStatusHandler(){ |
134 |
* @return the workbench status handler |
135 |
if(statusHandler == null && StatusHandlerRegistry.getDefault() |
135 |
*/ |
136 |
.getDefaultHandlerDescriptor() != null){ |
136 |
private AbstractStatusHandler getWorkbenchHandler() { |
137 |
try { |
137 |
if (workbenchHandler == null) { |
138 |
statusHandler = StatusHandlerRegistry.getDefault() |
138 |
workbenchHandler = new WorkbenchErrorHandlerProxy(); |
139 |
.getDefaultHandlerDescriptor().getStatusHandler(); |
|
|
140 |
} catch (CoreException ex) { |
141 |
logError("Errors during the default handler creating", ex); //$NON-NLS-1$ |
142 |
} |
139 |
} |
143 |
} |
140 |
|
144 |
if(statusHandler == null){ |
141 |
return workbenchHandler; |
145 |
statusHandler = new WorkbenchErrorHandlerProxy(); |
|
|
146 |
} |
147 |
return statusHandler; |
142 |
} |
148 |
} |
143 |
|
|
|
144 |
/** |
149 |
/** |
145 |
* Handles the given status adapter due to the style. Because the facility |
150 |
* Handles the given status adapter due to the style. Because the facility |
146 |
* depends on Workbench, this method will log the status, if Workbench isn't |
151 |
* depends on Workbench, this method will log the status, if Workbench isn't |
Lines 180-221
Link Here
|
180 |
return; |
185 |
return; |
181 |
} |
186 |
} |
182 |
|
187 |
|
183 |
// tries to handle the problem with default (product) handler |
|
|
184 |
if (StatusHandlerRegistry.getDefault() |
185 |
.getDefaultHandlerDescriptor() != null) { |
186 |
try { |
187 |
StatusHandlerRegistry.getDefault() |
188 |
.getDefaultHandlerDescriptor().getStatusHandler() |
189 |
.handle(statusAdapter, style); |
190 |
// if statuses are shown, all finished jobs with error will |
191 |
// be removed, |
192 |
// we should remove it from the status manager, when error |
193 |
// icon |
194 |
// will be part of handlers not ProgressAnimationItem |
195 |
if (((style & StatusManager.SHOW) == StatusManager.SHOW || (style & StatusManager.BLOCK) == StatusManager.BLOCK) |
196 |
&& statusAdapter |
197 |
.getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY) != Boolean.TRUE) { |
198 |
FinishedJobs.getInstance().removeErrorJobs(); |
199 |
StatusAdapterHelper.getInstance().clear(); |
200 |
} |
201 |
return; |
202 |
} catch (CoreException ex) { |
203 |
logError("Errors during the default handler creating", ex); //$NON-NLS-1$ |
204 |
} |
205 |
} |
206 |
|
207 |
// delegates the problem to workbench handler |
188 |
// delegates the problem to workbench handler |
208 |
getWorkbenchHandler().handle(statusAdapter, style); |
189 |
getStatusHandler().handle(statusAdapter, style); |
209 |
|
190 |
|
210 |
// if statuses are shown, all finished jobs with error will be |
191 |
// if attached status handler is not able to notify StatusManager |
211 |
// removed, |
192 |
// about particular event, use the default policy and fake the |
212 |
// we should remove it from the status manager, when error icon |
193 |
// notification |
213 |
// will be part of handlers not ProgressAnimationItem |
194 |
if (!getStatusHandler().supportsNotification( |
214 |
if (((style & StatusManager.SHOW) == StatusManager.SHOW || (style & StatusManager.BLOCK) == StatusManager.BLOCK) |
195 |
INotificationType.HANDLED)) { |
215 |
&& statusAdapter |
196 |
generateFakeNotification(statusAdapter, style); |
216 |
.getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY) != Boolean.TRUE) { |
|
|
217 |
FinishedJobs.getInstance().removeErrorJobs(); |
218 |
} |
197 |
} |
|
|
198 |
|
219 |
} catch (Throwable ex) { |
199 |
} catch (Throwable ex) { |
220 |
// The used status handler failed |
200 |
// The used status handler failed |
221 |
logError(statusAdapter.getStatus()); |
201 |
logError(statusAdapter.getStatus()); |
Lines 329-332
Link Here
|
329 |
} |
309 |
} |
330 |
} |
310 |
} |
331 |
} |
311 |
} |
|
|
312 |
|
313 |
/** |
314 |
* This method should be called by custom status handlers when an event |
315 |
* occurs. This method will have no effect if statushandler does not declare |
316 |
* that particular event type is supported. |
317 |
* |
318 |
* @param type |
319 |
* - type of the event. |
320 |
* @param adapters |
321 |
* - array of affected {@link StatusAdapter}s. |
322 |
* @see IStatusAdapterConstants |
323 |
* @since 3.5 |
324 |
*/ |
325 |
public void fireNotification(int type, StatusAdapter[] adapters){ |
326 |
if(getStatusHandler().supportsNotification(type)){ |
327 |
doFireNotification(type, adapters); |
328 |
} |
329 |
} |
330 |
|
331 |
private void doFireNotification(int type, StatusAdapter[] adapters) { |
332 |
Object[] oListeners = listeners.getListeners(); |
333 |
for (int i = 0; i < oListeners.length; i++) { |
334 |
if (oListeners[i] instanceof INotificationListener) { |
335 |
((INotificationListener) oListeners[i]) |
336 |
.statusManagerNotified(type, adapters); |
337 |
} |
338 |
} |
339 |
} |
340 |
|
341 |
private void generateFakeNotification(StatusAdapter statusAdapter, int style) { |
342 |
if (((style & StatusManager.SHOW) == StatusManager.SHOW || (style & StatusManager.BLOCK) == StatusManager.BLOCK) |
343 |
&& statusAdapter |
344 |
.getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY) != Boolean.TRUE) { |
345 |
doFireNotification(INotificationType.HANDLED, |
346 |
new StatusAdapter[] { statusAdapter }); |
347 |
} |
348 |
} |
349 |
|
350 |
/** |
351 |
* Adds a listener to the StatusManager. |
352 |
* |
353 |
* @param listener |
354 |
* - a listener to be added. |
355 |
* @since 3.5 |
356 |
*/ |
357 |
public void addListener(INotificationListener listener) { |
358 |
this.listeners.add(listener); |
359 |
} |
360 |
|
361 |
/** |
362 |
* Removes a listener from StatusManager. |
363 |
* |
364 |
* @param listener |
365 |
* - a listener to be removed. |
366 |
* @since 3.5 |
367 |
*/ |
368 |
public void removeListener(INotificationListener listener){ |
369 |
this.listeners.remove(listener); |
370 |
} |
371 |
|
372 |
/** |
373 |
* This interface allows for listening to status handling framework changes. |
374 |
* Currently it is possible to be notified when: |
375 |
* <ul> |
376 |
* <li>all statuses has been handled</li>. |
377 |
* </ul> |
378 |
* @since 3.5 |
379 |
* |
380 |
*/ |
381 |
public interface INotificationListener{ |
382 |
/** |
383 |
* |
384 |
* @param type |
385 |
* - a type of notification. |
386 |
* @param adapters |
387 |
* - affected {@link StatusAdapter}s |
388 |
*/ |
389 |
public void statusManagerNotified(int type, StatusAdapter[] adapters); |
390 |
} |
391 |
|
392 |
/** |
393 |
* This interface declares types of notification. |
394 |
* |
395 |
* @since 3.5 |
396 |
* @noextend This interface is not intended to be extended by clients. |
397 |
* @noimplement This interface is not intended to be implemented by clients. |
398 |
* |
399 |
*/ |
400 |
public interface INotificationType { |
401 |
|
402 |
/** |
403 |
* This type notifications are used when a particular |
404 |
* {@link StatusAdapter} was handled. |
405 |
*/ |
406 |
public static final int HANDLED = 0x01; |
407 |
|
408 |
} |
332 |
} |
409 |
} |