1 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 18 public abstract class NotificationManager 19 extends com.nightlabs.notification.NotificationManager 20 { 21 private AbstractEPProcessor notificationInterceptorEPProcessor = new AbstractEPProcessor() { 22 23 public String 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 name = element.getAttribute("name"); 33 34 addInterceptor(interceptor); 35 } catch (Throwable 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 (e); 47 } 48 } 49 50 53 protected String 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 67 protected void performNotification(String notificationMode, final NotificationListener listener, 68 final NotificationEvent event) 69 { 70 if (NotificationListenerSWTThreadAsync.class.getName().equals(notificationMode)) { 71 Display.getDefault().asyncExec(new Runnable () { 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 () { 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 |