1 11 12 package org.eclipse.core.commands.common; 13 14 import org.eclipse.core.runtime.ListenerList; 15 16 28 public abstract class EventManager { 29 30 34 private static final Object [] EMPTY_ARRAY = new Object [0]; 35 36 40 private transient ListenerList listenerList = null; 41 42 49 protected synchronized final void addListenerObject(final Object listener) { 50 if (listenerList == null) { 51 listenerList = new ListenerList(ListenerList.IDENTITY); 52 } 53 54 listenerList.add(listener); 55 } 56 57 60 protected synchronized final void clearListeners() { 61 if (listenerList != null) { 62 listenerList.clear(); 63 } 64 } 65 66 72 protected final Object [] getListeners() { 73 final ListenerList list = listenerList; 74 if (list == null) { 75 return EMPTY_ARRAY; 76 } 77 78 return list.getListeners(); 79 } 80 81 87 protected final boolean isListenerAttached() { 88 return listenerList != null; 89 } 90 91 97 protected synchronized final void removeListenerObject(final Object listener) { 98 if (listenerList != null) { 99 listenerList.remove(listener); 100 101 if (listenerList.isEmpty()) { 102 listenerList = null; 103 } 104 } 105 } 106 } 107 | Popular Tags |