KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > commands > AbstractCommandRegistry


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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.commands;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Collections JavaDoc;
16 import java.util.List JavaDoc;
17
18 abstract class AbstractCommandRegistry implements ICommandRegistry {
19
20     protected List JavaDoc activeKeyConfigurationDefinitions = Collections.EMPTY_LIST;
21     protected List JavaDoc categoryDefinitions = Collections.EMPTY_LIST;
22     protected List JavaDoc commandDefinitions = Collections.EMPTY_LIST;
23
24     private CommandRegistryEvent commandRegistryEvent;
25     private List JavaDoc commandRegistryListeners;
26     protected List JavaDoc handlers = Collections.EMPTY_LIST;
27     protected List JavaDoc imageBindingDefinitions = Collections.EMPTY_LIST;
28     protected List JavaDoc keyConfigurationDefinitions = Collections.EMPTY_LIST;
29     protected List JavaDoc keySequenceBindingDefinitions = Collections.EMPTY_LIST;
30
31     protected AbstractCommandRegistry() {
32         // Do nothing
33
}
34
35     public void addCommandRegistryListener(ICommandRegistryListener commandRegistryListener) {
36         if (commandRegistryListener == null)
37             throw new NullPointerException JavaDoc();
38
39         if (commandRegistryListeners == null)
40             commandRegistryListeners = new ArrayList JavaDoc();
41
42         if (!commandRegistryListeners.contains(commandRegistryListener))
43             commandRegistryListeners.add(commandRegistryListener);
44     }
45
46     protected void fireCommandRegistryChanged() {
47         if (commandRegistryListeners != null) {
48             for (int i = 0; i < commandRegistryListeners.size(); i++) {
49                 if (commandRegistryEvent == null)
50                     commandRegistryEvent = new CommandRegistryEvent(this);
51
52                 (
53                     (ICommandRegistryListener) commandRegistryListeners.get(
54                         i)).commandRegistryChanged(
55                     commandRegistryEvent);
56             }
57         }
58     }
59
60     public List JavaDoc getActiveKeyConfigurationDefinitions() {
61         return activeKeyConfigurationDefinitions;
62     }
63
64     public List JavaDoc getCategoryDefinitions() {
65         return categoryDefinitions;
66     }
67
68     public List JavaDoc getCommandDefinitions() {
69         return commandDefinitions;
70     }
71
72     /**
73      * An accessor for the handlers read into this registry.
74      *
75      * @return The list of handlers; this value may be empty, but it is never
76      * <code>null</code>.
77      */

78     public List JavaDoc getHandlers() {
79         return handlers;
80     }
81
82     public List JavaDoc getImageBindingDefinitions() {
83         return imageBindingDefinitions;
84     }
85
86     public List JavaDoc getKeyConfigurationDefinitions() {
87         return keyConfigurationDefinitions;
88     }
89
90     public List JavaDoc getKeySequenceBindingDefinitions() {
91         return keySequenceBindingDefinitions;
92     }
93
94     public void removeCommandRegistryListener(ICommandRegistryListener commandRegistryListener) {
95         if (commandRegistryListener == null)
96             throw new NullPointerException JavaDoc();
97
98         if (commandRegistryListeners != null)
99             commandRegistryListeners.remove(commandRegistryListener);
100     }
101 }
102
Popular Tags