View | Details | Raw Unified | Return to bug 220557 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/statushandlers/AbstractStatusHandler.java (+18 lines)
Lines 136-139 Link Here
136
	public void setId(String id) {
136
	public void setId(String id) {
137
		this.id = id;
137
		this.id = id;
138
	}
138
	}
139
140
	/**
141
	 * This methods indicates if the status handler supports specific kind of
142
	 * notification. If some kind of notification is supported, then
143
	 * {@link StatusManager#fireNotification(int, StatusAdapter[])} has to be
144
	 * called when particular event occurs. Only known notification types should
145
	 * be accepted, whereas unkown types should be always rejected, because it
146
	 * is possible that more types will be introduced over time.
147
	 * 
148
	 * @param type
149
	 *            - a notification type that should be checked.
150
	 * @return true if particular event notification is supported, false
151
	 *         otherwise
152
	 * @since 3.5
153
	 */
154
	public boolean supportsNotification(int type){
155
		return false;
156
	}
139
}
157
}
(-)Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java (+7 lines)
Lines 95-100 Link Here
95
import org.eclipse.ui.internal.statushandlers.DefaultDetailsArea;
95
import org.eclipse.ui.internal.statushandlers.DefaultDetailsArea;
96
import org.eclipse.ui.internal.statushandlers.StackTraceSupportArea;
96
import org.eclipse.ui.internal.statushandlers.StackTraceSupportArea;
97
import org.eclipse.ui.progress.IProgressConstants;
97
import org.eclipse.ui.progress.IProgressConstants;
98
import org.eclipse.ui.statushandlers.StatusManager.INotificationType;
98
99
99
import com.ibm.icu.text.DateFormat;
100
import com.ibm.icu.text.DateFormat;
100
101
Lines 1227-1232 Link Here
1227
			modals.put(statusAdapter, new Boolean(modal));
1228
			modals.put(statusAdapter, new Boolean(modal));
1228
			// Delay prompting if the status adapter property is set
1229
			// Delay prompting if the status adapter property is set
1229
			if (shouldPrompt(statusAdapter)) {
1230
			if (shouldPrompt(statusAdapter)) {
1231
				StatusManager.getManager()
1232
						.fireNotification(INotificationType.HANDLED,
1233
								new StatusAdapter[] {});
1230
				if (dialog == null) {
1234
				if (dialog == null) {
1231
					dialog = new InternalDialog(getParentShell(),
1235
					dialog = new InternalDialog(getParentShell(),
1232
							WorkbenchStatusDialogManager.this, shouldBeModal());
1236
							WorkbenchStatusDialogManager.this, shouldBeModal());
Lines 1242-1247 Link Here
1242
			}
1246
			}
1243
1247
1244
		} else {
1248
		} else {
1249
			StatusManager.getManager().fireNotification(
1250
					INotificationType.HANDLED,
1251
					new StatusAdapter[] { statusAdapter });
1245
			if (statusAdapter
1252
			if (statusAdapter
1246
					.getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY) != null) {
1253
					.getProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY) != null) {
1247
				statusAdapter.setProperty(
1254
				statusAdapter.setProperty(
(-)Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchErrorHandler.java (+11 lines)
Lines 18-23 Link Here
18
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.PlatformUI;
19
import org.eclipse.ui.application.WorkbenchAdvisor;
19
import org.eclipse.ui.application.WorkbenchAdvisor;
20
import org.eclipse.ui.internal.WorkbenchPlugin;
20
import org.eclipse.ui.internal.WorkbenchPlugin;
21
import org.eclipse.ui.statushandlers.StatusManager.INotificationType;
21
22
22
/**
23
/**
23
 * This is a default workbench error handler.
24
 * This is a default workbench error handler.
Lines 27-32 Link Here
27
 */
28
 */
28
public class WorkbenchErrorHandler extends AbstractStatusHandler {
29
public class WorkbenchErrorHandler extends AbstractStatusHandler {
29
30
31
	/* (non-Javadoc)
32
	 * @see org.eclipse.ui.statushandlers.AbstractStatusHandler#supportsNotification(int)
33
	 */
34
	public boolean supportsNotification(int type) {
35
		if (type == INotificationType.HANDLED) {
36
			return true;
37
		}
38
		return super.supportsNotification(type);
39
	}
40
30
	private WorkbenchStatusDialogManager statusDialogManager;
41
	private WorkbenchStatusDialogManager statusDialogManager;
31
42
32
	/*
43
	/*
(-)Eclipse UI/org/eclipse/ui/statushandlers/StatusManager.java (-46 / +123 lines)
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
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchErrorHandlerProxy.java (+9 lines)
Lines 36-39 Link Here
36
		Workbench.getInstance().getAdvisor().getWorkbenchErrorHandler().handle(
36
		Workbench.getInstance().getAdvisor().getWorkbenchErrorHandler().handle(
37
				statusAdapter, style);
37
				statusAdapter, style);
38
	}
38
	}
39
40
	/* (non-Javadoc)
41
	 * @see org.eclipse.ui.statushandlers.AbstractStatusHandler#supportsNotification(int)
42
	 */
43
	public boolean supportsNotification(int type) {
44
		return Workbench.getInstance().getAdvisor().getWorkbenchErrorHandler()
45
				.supportsNotification(type);
46
	}
47
	
39
}
48
}
(-)Eclipse UI/org/eclipse/ui/internal/progress/ProgressManager.java (+11 lines)
Lines 67-72 Link Here
67
import org.eclipse.ui.progress.WorkbenchJob;
67
import org.eclipse.ui.progress.WorkbenchJob;
68
import org.eclipse.ui.statushandlers.StatusAdapter;
68
import org.eclipse.ui.statushandlers.StatusAdapter;
69
import org.eclipse.ui.statushandlers.StatusManager;
69
import org.eclipse.ui.statushandlers.StatusManager;
70
import org.eclipse.ui.statushandlers.StatusManager.INotificationType;
70
71
71
/**
72
/**
72
 * JobProgressManager provides the progress monitor to the job manager and
73
 * JobProgressManager provides the progress monitor to the job manager and
Lines 370-375 Link Here
370
		} catch (MalformedURLException e) {
371
		} catch (MalformedURLException e) {
371
			ProgressManagerUtil.logException(e);
372
			ProgressManagerUtil.logException(e);
372
		}
373
		}
374
		StatusManager.getManager().addListener(new StatusManager.INotificationListener(){
375
376
			public void statusManagerNotified(int type, StatusAdapter[] adapters) {
377
				if(type == INotificationType.HANDLED){
378
					FinishedJobs.getInstance().removeErrorJobs();
379
					StatusAdapterHelper.getInstance().clear();
380
				}
381
			}
382
			
383
		});
373
	}
384
	}
374
385
375
	/**
386
	/**
(-)Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/StatusHandlingConfigurationTest.java (+21 lines)
Lines 13-21 Link Here
13
13
14
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
15
import org.eclipse.core.runtime.Status;
16
import org.eclipse.ui.progress.IProgressConstants;
16
import org.eclipse.ui.statushandlers.AbstractStatusHandler;
17
import org.eclipse.ui.statushandlers.AbstractStatusHandler;
17
import org.eclipse.ui.statushandlers.StatusAdapter;
18
import org.eclipse.ui.statushandlers.StatusAdapter;
18
import org.eclipse.ui.statushandlers.StatusManager;
19
import org.eclipse.ui.statushandlers.StatusManager;
20
import org.eclipse.ui.statushandlers.StatusManager.INotificationType;
19
21
20
import junit.framework.TestCase;
22
import junit.framework.TestCase;
21
23
Lines 38-41 Link Here
38
		StatusManager.getManager().handle(adapter);
40
		StatusManager.getManager().handle(adapter);
39
		assertEquals(true, called[0]);
41
		assertEquals(true, called[0]);
40
	}
42
	}
43
	
44
	public void testDefaultNotification(){
45
		final StatusAdapter adapter = new StatusAdapter(new Status(IStatus.ERROR,"fakeplugin","testmessage"));
46
		adapter.setProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.TRUE);
47
		final StatusAdapter adapter2 = new StatusAdapter(new Status(IStatus.ERROR,"fakeplugin2","testmessage2"));
48
		final boolean[] called = new boolean[]{false};
49
		StatusManager.getManager().addListener(new StatusManager.INotificationListener(){
50
					public void statusManagerNotified(int type,
51
							StatusAdapter[] adapters) {
52
						if (type == INotificationType.HANDLED)
53
							called[0] = true;
54
					}
55
		});
56
		StatusManager.getManager().handle(adapter, StatusManager.SHOW);
57
		assertEquals(false, called[0]);
58
		StatusManager.getManager().handle(adapter2, StatusManager.SHOW);
59
		assertEquals(true, called[0]);
60
		
61
	}
41
}
62
}

Return to bug 220557