1 11 12 package org.eclipse.jface.bindings; 13 14 import java.util.Collection ; 15 import java.util.Map ; 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 31 public final class BindingManagerEvent extends AbstractBitSetEvent { 32 33 36 private static final int CHANGED_ACTIVE_BINDINGS = 1; 37 38 41 private static final int CHANGED_ACTIVE_SCHEME = 1 << 1; 42 43 46 private static final int CHANGED_LOCALE = 1 << 2; 47 48 51 private static final int CHANGED_PLATFORM = 1 << 3; 52 53 56 private static final int CHANGED_SCHEME_DEFINED = 1 << 4; 57 58 62 private final BindingManager manager; 63 64 70 private final Map previousTriggersByParameterizedCommand; 71 72 76 private final Scheme scheme; 77 78 104 public BindingManagerEvent(final BindingManager manager, 105 final boolean activeBindingsChanged, 106 final Map 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 ( 112 "A binding manager event needs a binding manager"); } 114 this.manager = manager; 115 116 if (schemeDefined && (scheme == null)) { 117 throw new NullPointerException ( 118 "If a scheme changed defined state, then there should be a scheme identifier"); } 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 147 public final BindingManager getManager() { 148 return manager; 149 } 150 151 156 public final Scheme getScheme() { 157 return scheme; 158 } 159 160 166 public final boolean isActiveBindingsChanged() { 167 return ((changedValues & CHANGED_ACTIVE_BINDINGS) != 0); 168 } 169 170 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 previousBindingCollection = (Collection ) 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 207 public final boolean isActiveSchemeChanged() { 208 return ((changedValues & CHANGED_ACTIVE_SCHEME) != 0); 209 } 210 211 217 public boolean isLocaleChanged() { 218 return ((changedValues & CHANGED_LOCALE) != 0); 219 } 220 221 227 public boolean isPlatformChanged() { 228 return ((changedValues & CHANGED_PLATFORM) != 0); 229 } 230 231 237 public final boolean isSchemeChanged() { 238 return (scheme != null); 239 } 240 241 246 public final boolean isSchemeDefined() { 247 return (((changedValues & CHANGED_SCHEME_DEFINED) != 0) && (scheme != null)); 248 } 249 } 250 | Popular Tags |