1 11 package org.eclipse.compare.internal; 12 13 import org.eclipse.compare.IContentChangeListener; 14 import org.eclipse.compare.IContentChangeNotifier; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.swt.widgets.Display; 17 18 21 public class ContentChangeNotifier implements IContentChangeNotifier { 22 23 private ListenerList fListenerList; 24 private final IContentChangeNotifier element; 25 26 public ContentChangeNotifier(IContentChangeNotifier element) { 27 this.element = element; 28 } 29 30 33 public void addContentChangeListener(IContentChangeListener listener) { 34 if (fListenerList == null) 35 fListenerList= new ListenerList(); 36 fListenerList.add(listener); 37 } 38 39 42 public void removeContentChangeListener(IContentChangeListener listener) { 43 if (fListenerList != null) { 44 fListenerList.remove(listener); 45 if (fListenerList.isEmpty()) 46 fListenerList= null; 47 } 48 } 49 50 53 public void fireContentChanged() { 54 if (isEmpty()) { 55 return; 56 } 57 Runnable runnable = new Runnable () { 59 public void run() { 60 Object [] listeners= fListenerList.getListeners(); 61 for (int i= 0; i < listeners.length; i++) { 62 final IContentChangeListener contentChangeListener = (IContentChangeListener)listeners[i]; 63 SafeRunner.run(new ISafeRunnable() { 64 public void run() throws Exception { 65 (contentChangeListener).contentChanged(element); 66 } 67 public void handleException(Throwable exception) { 68 } 70 }); 71 } 72 } 73 }; 74 if (Display.getCurrent() == null) { 75 Display.getDefault().syncExec(runnable); 76 } else { 77 runnable.run(); 78 } 79 } 80 81 85 public boolean isEmpty() { 86 return fListenerList == null || fListenerList.isEmpty(); 87 } 88 89 } 90 | Popular Tags |