Mercurial > projects > dwt2
comparison org.eclipse.core.commands/src/org/eclipse/core/commands/common/EventManager.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2005, 2006 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 | |
14 module org.eclipse.core.commands.common.EventManager; | |
15 | |
16 import org.eclipse.core.runtime.ListenerList; | |
17 | |
18 /** | |
19 * <p> | |
20 * A manager to which listeners can be attached. This handles the management of | |
21 * a list of listeners -- optimizing memory and performance. All the methods on | |
22 * this class are guaranteed to be thread-safe. | |
23 * </p> | |
24 * <p> | |
25 * Clients may extend. | |
26 * </p> | |
27 * | |
28 * @since 3.2 | |
29 */ | |
30 public abstract class EventManager { | |
31 | |
32 /** | |
33 * An empty array that can be returned from a call to | |
34 * {@link #getListeners()} when {@link #listenerList} is <code>null</code>. | |
35 */ | |
36 private static const Object[] EMPTY_ARRAY = null; | |
37 | |
38 /** | |
39 * A collection of objects listening to changes to this manager. This | |
40 * collection is <code>null</code> if there are no listeners. | |
41 */ | |
42 private /+transient+/ ListenerList listenerList = null; | |
43 | |
44 /** | |
45 * Adds a listener to this manager that will be notified when this manager's | |
46 * state changes. | |
47 * | |
48 * @param listener | |
49 * The listener to be added; must not be <code>null</code>. | |
50 */ | |
51 protected synchronized final void addListenerObject(Object listener) { | |
52 if (listenerList is null) { | |
53 listenerList = new ListenerList(ListenerList.IDENTITY); | |
54 } | |
55 | |
56 listenerList.add(listener); | |
57 } | |
58 | |
59 /** | |
60 * Clears all of the listeners from the listener list. | |
61 */ | |
62 protected synchronized final void clearListeners() { | |
63 if (listenerList !is null) { | |
64 listenerList.clear(); | |
65 } | |
66 } | |
67 | |
68 /** | |
69 * Returns the listeners attached to this event manager. | |
70 * | |
71 * @return The listeners currently attached; may be empty, but never | |
72 * <code>null</code> | |
73 */ | |
74 protected final Object[] getListeners() { | |
75 ListenerList list = listenerList; | |
76 if (list is null) { | |
77 return EMPTY_ARRAY; | |
78 } | |
79 | |
80 return list.getListeners(); | |
81 } | |
82 | |
83 /** | |
84 * Whether one or more listeners are attached to the manager. | |
85 * | |
86 * @return <code>true</code> if listeners are attached to the manager; | |
87 * <code>false</code> otherwise. | |
88 */ | |
89 protected final bool isListenerAttached() { | |
90 return listenerList !is null; | |
91 } | |
92 | |
93 /** | |
94 * Removes a listener from this manager. | |
95 * | |
96 * @param listener | |
97 * The listener to be removed; must not be <code>null</code>. | |
98 */ | |
99 protected synchronized final void removeListenerObject(Object listener) { | |
100 if (listenerList !is null) { | |
101 listenerList.remove(listener); | |
102 | |
103 if (listenerList.isEmpty()) { | |
104 listenerList = null; | |
105 } | |
106 } | |
107 } | |
108 } |