KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > handlers > LegacyHandlerListenerWrapper


1 /*******************************************************************************
2  * Copyright (c) 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.handlers;
12
13 import org.eclipse.core.commands.IHandler;
14 import org.eclipse.ui.commands.HandlerEvent;
15 import org.eclipse.ui.commands.IHandlerListener;
16 import org.eclipse.ui.internal.commands.ILegacyAttributeNames;
17
18 /**
19  * A wrapper so that the new handler listener can work with legacy handlers.
20  * This class is only intended for backward compatibility with Eclipse 3.0.
21  *
22  * @since 3.1
23  */

24 public final class LegacyHandlerListenerWrapper implements IHandlerListener {
25
26     /**
27      * The handler on which this listener is listening; never <code>null</code>.
28      */

29     private final IHandler handler;
30
31     /**
32      * The wrapped listener; never <code>null</code>.
33      */

34     private final org.eclipse.core.commands.IHandlerListener listener;
35
36     /**
37      * Constructs a new instance of <code>LegacyHandlerListenerWrapper</code>.
38      *
39      * @param listener
40      * The listener to wrap; must not be <code>null</code>.
41      */

42     public LegacyHandlerListenerWrapper(final IHandler handler,
43             final org.eclipse.core.commands.IHandlerListener listener) {
44         if (handler == null) {
45             throw new NullPointerException JavaDoc(
46                     "A listener wrapper cannot be created on a null handler"); //$NON-NLS-1$
47
}
48
49         if (listener == null) {
50             throw new NullPointerException JavaDoc(
51                     "A listener wrapper cannot be created on a null listener"); //$NON-NLS-1$
52
}
53
54         this.handler = handler;
55         this.listener = listener;
56     }
57
58     /*
59      * (non-Javadoc)
60      *
61      * @see org.eclipse.ui.commands.IHandlerListener#handlerChanged(org.eclipse.ui.commands.HandlerEvent)
62      */

63     public void handlerChanged(HandlerEvent event) {
64         final boolean enabledChanged = ((Boolean JavaDoc) event
65                 .getPreviousAttributeValuesByName().get(
66                         ILegacyAttributeNames.ENABLED)).booleanValue() != handler
67                 .isEnabled();
68         final boolean handledChanged = ((Boolean JavaDoc) event
69                 .getPreviousAttributeValuesByName().get(
70                         ILegacyAttributeNames.HANDLED)).booleanValue() != handler
71                 .isHandled();
72         listener.handlerChanged(new org.eclipse.core.commands.HandlerEvent(
73                 handler, enabledChanged, handledChanged));
74     }
75 }
76
Popular Tags