KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > rcp > notification > NotificationManager


1 /*
2  * Created on Apr 15, 2005
3  */

4 package com.nightlabs.rcp.notification;
5
6 import org.eclipse.core.runtime.IConfigurationElement;
7 import org.eclipse.swt.widgets.Display;
8
9 import com.nightlabs.notification.Interceptor;
10 import com.nightlabs.notification.NotificationEvent;
11 import com.nightlabs.notification.NotificationListener;
12 import com.nightlabs.rcp.extensionpoint.AbstractEPProcessor;
13 import com.nightlabs.rcp.extensionpoint.EPProcessorException;
14
15 /**
16  * @author Marco Schulze - marco at nightlabs dot de
17  */

18 public abstract class NotificationManager
19 extends com.nightlabs.notification.NotificationManager
20 {
21     private AbstractEPProcessor notificationInterceptorEPProcessor = new AbstractEPProcessor() {
22
23         public String JavaDoc getExtensionPointID()
24         {
25             return "com.nightlabs.base.notificationinterceptor";
26         }
27
28         public void processElement(IConfigurationElement element) throws EPProcessorException
29         {
30             try {
31                 Interceptor interceptor = (Interceptor) element.createExecutableExtension("class");
32                 String JavaDoc name = element.getAttribute("name");
33
34                 addInterceptor(interceptor);
35             } catch (Throwable JavaDoc e) {
36                 throw new EPProcessorException("Extension to "+getExtensionPointID()+" with class "+element.getAttribute("class")+" has errors!", e);
37             }
38         }
39     };
40
41     protected NotificationManager()
42     {
43         try {
44             notificationInterceptorEPProcessor.process();
45         } catch (EPProcessorException e) {
46             throw new RuntimeException JavaDoc(e);
47         }
48     }
49
50     /**
51      * @see com.nightlabs.notification.NotificationManager#getNotificationModeForListener(com.nightlabs.notification.NotificationListener)
52      */

53     protected String JavaDoc getNotificationModeForListener(NotificationListener listener)
54     {
55         if (listener instanceof NotificationListenerSWTThreadSync)
56             return NotificationListenerSWTThreadSync.class.getName();
57
58         if (listener instanceof NotificationListenerSWTThreadAsync)
59             return NotificationListenerSWTThreadAsync.class.getName();
60
61         return super.getNotificationModeForListener(listener);
62     }
63
64     /**
65      * @see com.nightlabs.notification.NotificationManager#performNotification(java.lang.String, com.nightlabs.notification.NotificationListener, com.nightlabs.notification.NotificationEvent)
66      */

67     protected void performNotification(String JavaDoc notificationMode, final NotificationListener listener,
68             final NotificationEvent event)
69     {
70         if (NotificationListenerSWTThreadAsync.class.getName().equals(notificationMode)) {
71             Display.getDefault().asyncExec(new Runnable JavaDoc() {
72                 public void run()
73                 {
74                     listener.notify(event);
75                 }
76             });
77         }
78         else if (NotificationListenerSWTThreadSync.class.getName().equals(notificationMode)) {
79             Display.getDefault().syncExec(new Runnable JavaDoc() {
80                 public void run()
81                 {
82                     listener.notify(event);
83                 }
84             });
85         }
86         else
87             super.performNotification(notificationMode, listener, event);
88     }
89 }
90
Popular Tags