List of usage examples for org.eclipse.jface.bindings Binding equals
@Override public final boolean equals(final Object object)
From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java
License:Open Source License
/** * <p>/*from w w w.ja v a 2s . c o m*/ * Tests whether two identical bindings lead to a conflict. * </p> * * @throws NotDefinedException * If the scheme we try to activate is not defined. */ public void testConflict() throws NotDefinedException { final Context context = contextManager.getContext("na"); context.define("name", "description", null); final Scheme scheme = bindingManager.getScheme("na"); scheme.define("name", "description", null); bindingManager.setActiveScheme(scheme); final Set activeContextIds = new HashSet(); activeContextIds.add("na"); contextManager.setActiveContextIds(activeContextIds); final Binding binding1 = new TestBinding("conflict1", "na", "na", null, null, Binding.SYSTEM, null); bindingManager.addBinding(binding1); final Binding binding2 = new TestBinding("conflict2", "na", "na", null, null, Binding.SYSTEM, null); bindingManager.addBinding(binding2); TriggerSequence[] activeBindings = bindingManager.getActiveBindingsFor(binding1.getParameterizedCommand()); assertFalse(binding1.equals(binding2)); assertTrue("Neither binding should be active", activeBindings.length == 0); activeBindings = bindingManager.getActiveBindingsFor(binding2.getParameterizedCommand()); assertTrue("Neither binding should be active", activeBindings.length == 0); }
From source file:org.eclipse.e4.ui.keybinding.tests.Bug189167Test.java
License:Open Source License
public void testHashCodeEquals() { Binding one = createTestBinding(); Binding two = createTestBinding(); Binding b3 = new TestBinding("commandID", "schemeID", "contextID", "locale", "platform", 1, null); assertEquals(one, two);/*from w ww . ja va 2s .com*/ assertEquals(one.hashCode(), two.hashCode()); assertFalse(one.equals(b3)); }
From source file:org.eclipse.ui.internal.keys.BindingService.java
License:Open Source License
static public MKeyBinding createORupdateMKeyBinding(MApplication application, MBindingTable table, Binding binding) { boolean addToTable = false; ParameterizedCommand parmCmd = binding.getParameterizedCommand(); String id = parmCmd.getId();//from w w w . j a v a 2 s. c om MCommand cmd = null; for (MCommand appCommand : application.getCommands()) { if (id.equals(appCommand.getElementId())) { cmd = appCommand; break; } } if (cmd == null) { return null; } MKeyBinding keyBinding = null; for (MKeyBinding existingBinding : table.getBindings()) { Binding b = (Binding) existingBinding.getTransientData().get(EBindingService.MODEL_TO_BINDING_KEY); if (binding.equals(b)) { keyBinding = existingBinding; break; } if (isSameBinding(existingBinding, cmd, binding)) { keyBinding = existingBinding; break; } } if (keyBinding == null) { addToTable = true; keyBinding = CommandsFactoryImpl.eINSTANCE.createKeyBinding(); keyBinding.setCommand(cmd); keyBinding.setKeySequence(binding.getTriggerSequence().toString()); for (Object obj : parmCmd.getParameterMap().entrySet()) { @SuppressWarnings({ "unchecked" }) Map.Entry<String, String> entry = (Map.Entry<String, String>) obj; String paramID = entry.getKey(); if (paramID == null) continue; List<MParameter> bindingParams = keyBinding.getParameters(); MParameter p = null; for (MParameter param : bindingParams) { if (paramID.equals(param.getElementId())) { p = param; break; } } if (p == null) { p = CommandsFactoryImpl.eINSTANCE.createParameter(); p.setElementId(entry.getKey()); keyBinding.getParameters().add(p); } p.setName(entry.getKey()); p.setValue(entry.getValue()); } List<String> tags = keyBinding.getTags(); // just add the 'schemeId' tag if the binding is for anything other // than // the default scheme if (binding.getSchemeId() != null && !binding.getSchemeId().equals(BindingPersistence.getDefaultSchemeId())) { tags.add(EBindingService.SCHEME_ID_ATTR_TAG + ":" + binding.getSchemeId()); //$NON-NLS-1$ } if (binding.getLocale() != null) { tags.add(EBindingService.LOCALE_ATTR_TAG + ":" + binding.getLocale()); //$NON-NLS-1$ } if (binding.getPlatform() != null) { tags.add(EBindingService.PLATFORM_ATTR_TAG + ":" + binding.getPlatform()); //$NON-NLS-1$ } // just add the 'type' tag if it's a user binding if (binding.getType() == Binding.USER) { tags.add(EBindingService.TYPE_ATTR_TAG + ":user"); //$NON-NLS-1$ } } keyBinding.getTransientData().put(EBindingService.MODEL_TO_BINDING_KEY, binding); if (addToTable) { table.getBindings().add(keyBinding); } return keyBinding; }
From source file:org.eclipse.ui.internal.keys.BindingService.java
License:Open Source License
private MKeyBinding findMKeyBinding(MBindingTable table, Binding binding) { List<MKeyBinding> mBindings = table.getBindings(); String bindingSchemeId = binding.getSchemeId() == null ? IBindingService.DEFAULT_DEFAULT_ACTIVE_SCHEME_ID : binding.getSchemeId();/* ww w. j a va2s . c o m*/ if (binding.getParameterizedCommand() != null) { String commandId = binding.getParameterizedCommand().getId(); for (MKeyBinding curr : mBindings) { Binding transientBinding = (Binding) curr.getTransientData() .get(EBindingService.MODEL_TO_BINDING_KEY); if (transientBinding != null) { if (binding.equals(transientBinding)) { return curr; } continue; } // check equality if (curr.getKeySequence().equals(binding.getTriggerSequence().toString()) && curr.getCommand() != null && curr.getCommand().getElementId().equals(commandId)) { String schemeId = IBindingService.DEFAULT_DEFAULT_ACTIVE_SCHEME_ID; List<String> tags = curr.getTags(); // grab the scheme id from the tags for (String tag : tags) { if (tag.startsWith(EBindingService.SCHEME_ID_ATTR_TAG)) { schemeId = tag.substring(9); break; } } // if the scheme ids are the same, then we found the // MKeyBinding if (schemeId.equals(bindingSchemeId)) { return curr; } } } } return null; }