KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > bindings > BindingManagerEvent


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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
12 package org.eclipse.jface.bindings;
13
14 import java.util.Collection JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.commands.ParameterizedCommand;
18 import org.eclipse.core.commands.common.AbstractBitSetEvent;
19 import org.eclipse.jface.util.Util;
20
21 /**
22  * An instance of this class describes changes to an instance of
23  * <code>BindingManager</code>.
24  * <p>
25  * This class is not intended to be extended by clients.
26  * </p>
27  *
28  * @since 3.1
29  * @see IBindingManagerListener#bindingManagerChanged(BindingManagerEvent)
30  */

31 public final class BindingManagerEvent extends AbstractBitSetEvent {
32
33     /**
34      * The bit used to represent whether the map of active bindings has changed.
35      */

36     private static final int CHANGED_ACTIVE_BINDINGS = 1;
37
38     /**
39      * The bit used to represent whether the active scheme has changed.
40      */

41     private static final int CHANGED_ACTIVE_SCHEME = 1 << 1;
42
43     /**
44      * The bit used to represent whether the active locale has changed.
45      */

46     private static final int CHANGED_LOCALE = 1 << 2;
47
48     /**
49      * The bit used to represent whether the active platform has changed.
50      */

51     private static final int CHANGED_PLATFORM = 1 << 3;
52
53     /**
54      * The bit used to represent whether the scheme's defined state has changed.
55      */

56     private static final int CHANGED_SCHEME_DEFINED = 1 << 4;
57
58     /**
59      * The binding manager that has changed; this value is never
60      * <code>null</code>.
61      */

62     private final BindingManager manager;
63
64     /**
65      * The map of triggers (<code>Collection</code> of
66      * <code>TriggerSequence</code>) by parameterized command (<code>ParameterizedCommand</code>)
67      * before the change occurred. This map may be empty and it may be
68      * <code>null</code>.
69      */

70     private final Map JavaDoc previousTriggersByParameterizedCommand;
71
72     /**
73      * The scheme that became defined or undefined. This value may be
74      * <code>null</code> if no scheme changed its defined state.
75      */

76     private final Scheme scheme;
77
78     /**
79      * Creates a new instance of this class.
80      *
81      * @param manager
82      * the instance of the binding manager that changed; must not be
83      * <code>null</code>.
84      * @param activeBindingsChanged
85      * Whether the active bindings have changed.
86      * @param previousTriggersByParameterizedCommand
87      * The map of triggers (<code>TriggerSequence</code>) by
88      * fully-parameterized command (<code>ParameterizedCommand</code>)
89      * before the change occured. This map may be <code>null</code>
90      * or empty.
91      * @param activeSchemeChanged
92      * true, iff the active scheme changed.
93      * @param scheme
94      * The scheme that became defined or undefined; <code>null</code>
95      * if no scheme changed state.
96      * @param schemeDefined
97      * <code>true</code> if the given scheme became defined;
98      * <code>false</code> otherwise.
99      * @param localeChanged
100      * <code>true</code> iff the active locale changed
101      * @param platformChanged
102      * <code>true</code> iff the active platform changed
103      */

104     public BindingManagerEvent(final BindingManager manager,
105             final boolean activeBindingsChanged,
106             final Map JavaDoc previousTriggersByParameterizedCommand,
107             final boolean activeSchemeChanged, final Scheme scheme,
108             final boolean schemeDefined, final boolean localeChanged,
109             final boolean platformChanged) {
110         if (manager == null) {
111             throw new NullPointerException JavaDoc(
112                     "A binding manager event needs a binding manager"); //$NON-NLS-1$
113
}
114         this.manager = manager;
115
116         if (schemeDefined && (scheme == null)) {
117             throw new NullPointerException JavaDoc(
118                     "If a scheme changed defined state, then there should be a scheme identifier"); //$NON-NLS-1$
119
}
120         this.scheme = scheme;
121
122         this.previousTriggersByParameterizedCommand = previousTriggersByParameterizedCommand;
123
124         if (activeBindingsChanged) {
125             changedValues |= CHANGED_ACTIVE_BINDINGS;
126         }
127         if (activeSchemeChanged) {
128             changedValues |= CHANGED_ACTIVE_SCHEME;
129         }
130         if (localeChanged) {
131             changedValues |= CHANGED_LOCALE;
132         }
133         if (platformChanged) {
134             changedValues |= CHANGED_PLATFORM;
135         }
136         if (schemeDefined) {
137             changedValues |= CHANGED_SCHEME_DEFINED;
138         }
139     }
140
141     /**
142      * Returns the instance of the manager that changed.
143      *
144      * @return the instance of the manager that changed. Guaranteed not to be
145      * <code>null</code>.
146      */

147     public final BindingManager getManager() {
148         return manager;
149     }
150
151     /**
152      * Returns the scheme that changed.
153      *
154      * @return The changed scheme
155      */

156     public final Scheme getScheme() {
157         return scheme;
158     }
159
160     /**
161      * Returns whether the active bindings have changed.
162      *
163      * @return <code>true</code> if the active bindings have changed;
164      * <code>false</code> otherwise.
165      */

166     public final boolean isActiveBindingsChanged() {
167         return ((changedValues & CHANGED_ACTIVE_BINDINGS) != 0);
168     }
169
170     /**
171      * Computes whether the active bindings have changed for a given command
172      * identifier.
173      *
174      * @param parameterizedCommand
175      * The fully-parameterized command whose bindings might have
176      * changed; must not be <code>null</code>.
177      * @return <code>true</code> if the active bindings have changed for the
178      * given command identifier; <code>false</code> otherwise.
179      */

180     public final boolean isActiveBindingsChangedFor(
181             final ParameterizedCommand parameterizedCommand) {
182         final TriggerSequence[] currentBindings = manager
183                 .getActiveBindingsFor(parameterizedCommand);
184         final TriggerSequence[] previousBindings;
185         if (previousTriggersByParameterizedCommand != null) {
186             final Collection JavaDoc previousBindingCollection = (Collection JavaDoc) previousTriggersByParameterizedCommand
187                     .get(parameterizedCommand);
188             if (previousBindingCollection == null) {
189                 previousBindings = null;
190             } else {
191                 previousBindings = (TriggerSequence[]) previousBindingCollection
192                         .toArray(new TriggerSequence[previousBindingCollection
193                                 .size()]);
194             }
195         } else {
196             previousBindings = null;
197         }
198
199         return !Util.equals(currentBindings, previousBindings);
200     }
201
202     /**
203      * Returns whether or not the active scheme changed.
204      *
205      * @return true, iff the active scheme property changed.
206      */

207     public final boolean isActiveSchemeChanged() {
208         return ((changedValues & CHANGED_ACTIVE_SCHEME) != 0);
209     }
210
211     /**
212      * Returns whether the locale has changed
213      *
214      * @return <code>true</code> if the locale changed; <code>false</code>
215      * otherwise.
216      */

217     public boolean isLocaleChanged() {
218         return ((changedValues & CHANGED_LOCALE) != 0);
219     }
220
221     /**
222      * Returns whether the platform has changed
223      *
224      * @return <code>true</code> if the platform changed; <code>false</code>
225      * otherwise.
226      */

227     public boolean isPlatformChanged() {
228         return ((changedValues & CHANGED_PLATFORM) != 0);
229     }
230
231     /**
232      * Returns whether the list of defined scheme identifiers has changed.
233      *
234      * @return <code>true</code> if the list of scheme identifiers has
235      * changed; <code>false</code> otherwise.
236      */

237     public final boolean isSchemeChanged() {
238         return (scheme != null);
239     }
240
241     /**
242      * Returns whether or not the scheme became defined
243      *
244      * @return <code>true</code> if the scheme became defined.
245      */

246     public final boolean isSchemeDefined() {
247         return (((changedValues & CHANGED_SCHEME_DEFINED) != 0) && (scheme != null));
248     }
249 }
250
Popular Tags