KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > contexts > AbstractContextManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.contexts;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.ui.contexts.ContextManagerEvent;
18 import org.eclipse.ui.contexts.IContextManager;
19 import org.eclipse.ui.contexts.IContextManagerListener;
20
21 public abstract class AbstractContextManager implements IContextManager {
22     private List JavaDoc contextManagerListeners;
23
24     protected AbstractContextManager() {
25     }
26
27     public void addContextManagerListener(IContextManagerListener contextManagerListener) {
28         if (contextManagerListener == null)
29             throw new NullPointerException JavaDoc();
30
31         if (contextManagerListeners == null)
32             contextManagerListeners = new ArrayList JavaDoc();
33
34         if (!contextManagerListeners.contains(contextManagerListener))
35             contextManagerListeners.add(contextManagerListener);
36     }
37
38     protected void fireContextManagerChanged(ContextManagerEvent contextManagerEvent) {
39         if (contextManagerEvent == null)
40             throw new NullPointerException JavaDoc();
41
42         if (contextManagerListeners != null)
43             for (int i = 0; i < contextManagerListeners.size(); i++)
44                 (
45                     (IContextManagerListener) contextManagerListeners.get(
46                         i)).contextManagerChanged(
47                     contextManagerEvent);
48     }
49
50     public void removeContextManagerListener(IContextManagerListener contextManagerListener) {
51         if (contextManagerListener == null)
52             throw new NullPointerException JavaDoc();
53
54         if (contextManagerListeners != null)
55             contextManagerListeners.remove(contextManagerListener);
56     }
57 }
58
Popular Tags