KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > keys > SchemeWrapper


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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  *******************************************************************************/

11 package org.eclipse.ui.internal.keys;
12
13 import org.eclipse.jface.bindings.BindingManager;
14 import org.eclipse.jface.bindings.Scheme;
15 import org.eclipse.ui.commands.IKeyConfiguration;
16 import org.eclipse.ui.commands.IKeyConfigurationListener;
17 import org.eclipse.ui.commands.NotDefinedException;
18
19 /**
20  * @since 3.1
21  */

22 public final class SchemeWrapper implements IKeyConfiguration {
23
24     /**
25      * The binding manager managing this scheme. This value is never
26      * <code>null</code>.
27      */

28     private final BindingManager bindingManager;
29
30     /**
31      * The wrapped scheme; never <code>null</code>
32      */

33     private final Scheme scheme;
34
35     /**
36      * Constructs a new instance of <code>SchemeWrapper</code>.
37      *
38      * @param scheme
39      * The scheme to be wrapped; must not be <code>null</code>.
40      * @param bindingManager
41      * The binding manager for this scheme; must not be
42      * <code>null</code>.
43      */

44     public SchemeWrapper(final Scheme scheme,
45             final BindingManager bindingManager) {
46         if (scheme == null) {
47             throw new NullPointerException JavaDoc("Cannot wrap a null scheme"); //$NON-NLS-1$
48
}
49
50         if (bindingManager == null) {
51             throw new NullPointerException JavaDoc(
52                     "Cannot wrap a scheme without a binding manager"); //$NON-NLS-1$
53
}
54
55         this.scheme = scheme;
56         this.bindingManager = bindingManager;
57     }
58
59     /*
60      * (non-Javadoc)
61      *
62      * @see org.eclipse.ui.commands.IKeyConfiguration#addKeyConfigurationListener(org.eclipse.ui.commands.IKeyConfigurationListener)
63      */

64     public void addKeyConfigurationListener(
65             IKeyConfigurationListener keyConfigurationListener) {
66         scheme.addSchemeListener(new SchemeListenerWrapper(
67                 keyConfigurationListener, bindingManager));
68     }
69
70     /*
71      * (non-Javadoc)
72      *
73      * @see java.lang.Comparable#compareTo(java.lang.Object)
74      */

75     public int compareTo(Object JavaDoc o) {
76         return scheme.compareTo(o);
77     }
78
79     /*
80      * (non-Javadoc)
81      *
82      * @see org.eclipse.ui.commands.IKeyConfiguration#getDescription()
83      */

84     public String JavaDoc getDescription() throws NotDefinedException {
85         try {
86             return scheme.getDescription();
87         } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
88             throw new NotDefinedException(e);
89         }
90     }
91
92     /*
93      * (non-Javadoc)
94      *
95      * @see org.eclipse.ui.commands.IKeyConfiguration#getId()
96      */

97     public String JavaDoc getId() {
98         return scheme.getId();
99     }
100
101     /*
102      * (non-Javadoc)
103      *
104      * @see org.eclipse.ui.commands.IKeyConfiguration#getName()
105      */

106     public String JavaDoc getName() throws NotDefinedException {
107         try {
108             return scheme.getName();
109         } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
110             throw new NotDefinedException(e);
111         }
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see org.eclipse.ui.commands.IKeyConfiguration#getParentId()
118      */

119     public String JavaDoc getParentId() throws NotDefinedException {
120         try {
121             return scheme.getParentId();
122         } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
123             throw new NotDefinedException(e);
124         }
125     }
126
127     /*
128      * (non-Javadoc)
129      *
130      * @see org.eclipse.ui.commands.IKeyConfiguration#isActive()
131      */

132     public boolean isActive() {
133         return scheme.getId().equals(bindingManager.getActiveScheme().getId());
134     }
135
136     /*
137      * (non-Javadoc)
138      *
139      * @see org.eclipse.ui.commands.IKeyConfiguration#isDefined()
140      */

141     public boolean isDefined() {
142         return scheme.isDefined();
143     }
144
145     /*
146      * (non-Javadoc)
147      *
148      * @see org.eclipse.ui.commands.IKeyConfiguration#removeKeyConfigurationListener(org.eclipse.ui.commands.IKeyConfigurationListener)
149      */

150     public void removeKeyConfigurationListener(
151             IKeyConfigurationListener keyConfigurationListener) {
152         scheme.removeSchemeListener(new SchemeListenerWrapper(
153                 keyConfigurationListener, bindingManager));
154
155     }
156
157 }
158
Popular Tags