KickJava   Java API By Example, From Geeks To Geeks.

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


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.commands;
12
13 import org.eclipse.core.commands.CommandEvent;
14 import org.eclipse.core.commands.ICommandListener;
15 import org.eclipse.jface.bindings.BindingManager;
16 import org.eclipse.ui.commands.ICommand;
17
18 /**
19  * Wraps a legacy listener in a new listener interface. This simply forwards
20  * incoming events through to the old interface.
21  *
22  * @since 3.1
23  */

24 final class CommandListenerWrapper implements ICommandListener {
25
26     /**
27      * The supporting binding manager; never <code>null</code>.
28      */

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

35     private final org.eclipse.ui.commands.ICommandListener listener;
36
37     /**
38      * Constructs a new instance of <code>CommandListenerWrapper</code> around
39      * a legacy listener.
40      *
41      * @param listener
42      * The listener to be wrapped; must not be <code>null</code>.
43      */

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

65     public final void commandChanged(final CommandEvent commandEvent) {
66         final ICommand command = new CommandWrapper(commandEvent.getCommand(),
67                 bindingManager);
68         final boolean definedChanged = commandEvent.isDefinedChanged();
69         final boolean descriptionChanged = commandEvent.isDescriptionChanged();
70         final boolean handledChanged = commandEvent.isHandledChanged();
71         final boolean nameChanged = commandEvent.isNameChanged();
72
73         listener.commandChanged(new org.eclipse.ui.commands.CommandEvent(
74                 command, false, false, definedChanged, descriptionChanged,
75                 handledChanged, false, nameChanged, null));
76
77     }
78
79     public final boolean equals(final Object JavaDoc object) {
80         if (object instanceof CommandListenerWrapper) {
81             final CommandListenerWrapper wrapper = (CommandListenerWrapper) object;
82             return listener.equals(wrapper.listener);
83         }
84
85         if (object instanceof org.eclipse.ui.commands.ICommandListener) {
86             final org.eclipse.ui.commands.ICommandListener other = (org.eclipse.ui.commands.ICommandListener) object;
87             return listener.equals(other);
88         }
89
90         return false;
91     }
92
93     public final int hashCode() {
94         return listener.hashCode();
95     }
96 }
97
Popular Tags