KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
16 import java.util.List JavaDoc;
17
18 abstract class AbstractContextRegistry implements IContextRegistry {
19     protected List JavaDoc contextContextBindingDefinitions = Collections.EMPTY_LIST;
20     protected List JavaDoc contextDefinitions = Collections.EMPTY_LIST;
21     private ContextRegistryEvent contextRegistryEvent;
22     private List JavaDoc contextRegistryListeners;
23
24     protected AbstractContextRegistry() {
25     }
26
27     public void addContextRegistryListener(IContextRegistryListener contextRegistryListener) {
28         if (contextRegistryListener == null)
29             throw new NullPointerException JavaDoc();
30
31         if (contextRegistryListeners == null)
32             contextRegistryListeners = new ArrayList JavaDoc();
33
34         if (!contextRegistryListeners.contains(contextRegistryListener))
35             contextRegistryListeners.add(contextRegistryListener);
36     }
37
38     protected void fireContextRegistryChanged() {
39         if (contextRegistryListeners != null) {
40             for (int i = 0; i < contextRegistryListeners.size(); i++) {
41                 if (contextRegistryEvent == null)
42                     contextRegistryEvent = new ContextRegistryEvent(this);
43
44                 (
45                     (IContextRegistryListener) contextRegistryListeners.get(
46                         i)).contextRegistryChanged(
47                     contextRegistryEvent);
48             }
49         }
50     }
51
52     public List JavaDoc getContextContextBindingDefinitions() {
53         return contextContextBindingDefinitions;
54     }
55
56     public List JavaDoc getContextDefinitions() {
57         return contextDefinitions;
58     }
59
60     public void removeContextRegistryListener(IContextRegistryListener contextRegistryListener) {
61         if (contextRegistryListener == null)
62             throw new NullPointerException JavaDoc();
63
64         if (contextRegistryListeners != null)
65             contextRegistryListeners.remove(contextRegistryListener);
66     }
67 }
68
Popular Tags