KickJava   Java API By Example, From Geeks To Geeks.

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


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.ISchemeListener;
15 import org.eclipse.jface.bindings.SchemeEvent;
16 import org.eclipse.ui.commands.IKeyConfiguration;
17 import org.eclipse.ui.commands.IKeyConfigurationListener;
18 import org.eclipse.ui.commands.KeyConfigurationEvent;
19
20 /**
21  * A wrapper for old-style listeners to be hooked on to new style schemes.
22  *
23  * @since 3.1
24  */

25 final class SchemeListenerWrapper implements ISchemeListener {
26
27     /**
28      * The binding manager; never <code>null</code>.
29      */

30     private final BindingManager bindingManager;
31
32     /**
33      * The listener that is being wrapped. This value is never <code>null</code>.
34      */

35     private final IKeyConfigurationListener listener;
36
37     /**
38      * Constructs a new instance of <code>SchemeListenerWrapper</code> with
39      * the given listener.
40      *
41      * @param listener
42      * The listener to be wrapped; must mot be <code>null</code>.
43      */

44     SchemeListenerWrapper(final IKeyConfigurationListener listener,
45             final BindingManager bindingManager) {
46         if (listener == null) {
47             throw new NullPointerException JavaDoc("Cannot wrap a null listener"); //$NON-NLS-1$
48
}
49
50         if (bindingManager == null) {
51             throw new NullPointerException JavaDoc(
52                     "Cannot wrap a listener without a binding manager"); //$NON-NLS-1$
53
}
54
55         this.listener = listener;
56         this.bindingManager = bindingManager;
57     }
58     
59     public final boolean equals(final Object JavaDoc object) {
60         if (object instanceof SchemeListenerWrapper) {
61             final SchemeListenerWrapper wrapper = (SchemeListenerWrapper) object;
62             return listener.equals(wrapper.listener);
63         }
64         
65         if (object instanceof IKeyConfigurationListener) {
66             final IKeyConfigurationListener other = (IKeyConfigurationListener) object;
67             return listener.equals(other);
68         }
69         
70         return false;
71     }
72     
73     public final int hashCode() {
74         return listener.hashCode();
75     }
76
77     /*
78      * (non-Javadoc)
79      *
80      * @see org.eclipse.jface.bindings.ISchemeListener#schemeChanged(org.eclipse.jface.bindings.SchemeEvent)
81      */

82     public final void schemeChanged(final SchemeEvent schemeEvent) {
83         final IKeyConfiguration keyConfiguration = new SchemeWrapper(
84                 schemeEvent.getScheme(), bindingManager);
85         final boolean definedChanged = schemeEvent.isDefinedChanged();
86         final boolean nameChanged = schemeEvent.isNameChanged();
87         final boolean parentIdChanged = schemeEvent.isParentIdChanged();
88
89         listener.keyConfigurationChanged(new KeyConfigurationEvent(
90                 keyConfiguration, false, definedChanged, nameChanged,
91                 parentIdChanged));
92     }
93 }
94
Popular Tags