KickJava   Java API By Example, From Geeks To Geeks.

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


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  * A wrapper around the new {@link Scheme} class, providing supported for the
21  * old {@link IKeyConfiguration} interface.
22  *
23  * @since 3.1
24  */

25 public final class SchemeLegacyWrapper implements IKeyConfiguration {
26
27     /**
28      * The binding manager managing this scheme. This value is never
29      * <code>null</code>.
30      */

31     private final BindingManager bindingManager;
32
33     /**
34      * The wrapped scheme; never <code>null</code>
35      */

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

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

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

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

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

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

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

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

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

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

153     public void removeKeyConfigurationListener(
154             IKeyConfigurationListener keyConfigurationListener) {
155         scheme.removeSchemeListener(new LegacySchemeListenerWrapper(
156                 keyConfigurationListener, bindingManager));
157
158     }
159
160 }
161
Popular Tags