01: /*******************************************************************************
02: * Copyright (c) 2004, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.keys;
11:
12: import org.eclipse.jface.bindings.BindingManager;
13: import org.eclipse.jface.bindings.ISchemeListener;
14: import org.eclipse.jface.bindings.SchemeEvent;
15: import org.eclipse.ui.commands.IKeyConfiguration;
16: import org.eclipse.ui.commands.IKeyConfigurationListener;
17: import org.eclipse.ui.commands.KeyConfigurationEvent;
18:
19: /**
20: * A wrapper for old-style listeners to be hooked on to new style schemes.
21: *
22: * @since 3.1
23: */
24: final class LegacySchemeListenerWrapper implements ISchemeListener {
25:
26: /**
27: * The binding manager; never <code>null</code>.
28: */
29: private final BindingManager bindingManager;
30:
31: /**
32: * The listener that is being wrapped. This value is never <code>null</code>.
33: */
34: private final IKeyConfigurationListener listener;
35:
36: /**
37: * Constructs a new instance of <code>SchemeListenerWrapper</code> with
38: * the given listener.
39: *
40: * @param listener
41: * The listener to be wrapped; must mot be <code>null</code>.
42: */
43: LegacySchemeListenerWrapper(
44: final IKeyConfigurationListener listener,
45: final BindingManager bindingManager) {
46: if (listener == null) {
47: throw new NullPointerException(
48: "Cannot wrap a null listener"); //$NON-NLS-1$
49: }
50:
51: if (bindingManager == null) {
52: throw new NullPointerException(
53: "Cannot wrap a listener without a binding manager"); //$NON-NLS-1$
54: }
55:
56: this .listener = listener;
57: this .bindingManager = bindingManager;
58: }
59:
60: public final boolean equals(final Object object) {
61: if (object instanceof LegacySchemeListenerWrapper) {
62: final LegacySchemeListenerWrapper wrapper = (LegacySchemeListenerWrapper) object;
63: return listener.equals(wrapper.listener);
64: }
65:
66: if (object instanceof IKeyConfigurationListener) {
67: final IKeyConfigurationListener other = (IKeyConfigurationListener) object;
68: return listener.equals(other);
69: }
70:
71: return false;
72: }
73:
74: public final int hashCode() {
75: return listener.hashCode();
76: }
77:
78: /*
79: * (non-Javadoc)
80: *
81: * @see org.eclipse.jface.bindings.ISchemeListener#schemeChanged(org.eclipse.jface.bindings.SchemeEvent)
82: */
83: public final void schemeChanged(final SchemeEvent schemeEvent) {
84: final IKeyConfiguration keyConfiguration = new SchemeLegacyWrapper(
85: schemeEvent.getScheme(), bindingManager);
86: final boolean definedChanged = schemeEvent.isDefinedChanged();
87: final boolean nameChanged = schemeEvent.isNameChanged();
88: final boolean parentIdChanged = schemeEvent.isParentIdChanged();
89:
90: listener.keyConfigurationChanged(new KeyConfigurationEvent(
91: keyConfiguration, false, definedChanged, nameChanged,
92: parentIdChanged));
93: }
94: }
|