|
Added
Link Here
|
| 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.tests.dynamicplugins; |
| 12 |
|
| 13 |
import org.eclipse.core.commands.common.NotDefinedException; |
| 14 |
import org.eclipse.jface.bindings.Binding; |
| 15 |
import org.eclipse.jface.bindings.Scheme; |
| 16 |
import org.eclipse.jface.bindings.TriggerSequence; |
| 17 |
import org.eclipse.jface.bindings.keys.KeySequence; |
| 18 |
import org.eclipse.jface.bindings.keys.ParseException; |
| 19 |
import org.eclipse.jface.contexts.IContextIds; |
| 20 |
import org.eclipse.ui.internal.IWorkbenchConstants; |
| 21 |
import org.eclipse.ui.keys.IBindingService; |
| 22 |
|
| 23 |
public class BindingsExtensionDynamicTest extends DynamicTestCase { |
| 24 |
|
| 25 |
public BindingsExtensionDynamicTest(String testName) { |
| 26 |
super(testName); |
| 27 |
} |
| 28 |
|
| 29 |
protected String getExtensionId() { |
| 30 |
return "bindingsExtensionDynamicTest.testDynamicBindingAddition"; |
| 31 |
} |
| 32 |
|
| 33 |
protected String getExtensionPoint() { |
| 34 |
return IWorkbenchConstants.PL_BINDINGS; |
| 35 |
} |
| 36 |
|
| 37 |
protected String getInstallLocation() { |
| 38 |
return "data/org.eclipse.bindingsExtensionDynamicTest"; |
| 39 |
} |
| 40 |
|
| 41 |
public void testBinding() throws ParseException { |
| 42 |
final IBindingService bindingService = (IBindingService) getWorkbench() |
| 43 |
.getAdapter(IBindingService.class); |
| 44 |
final TriggerSequence triggerSequence = KeySequence.getInstance("M1+W"); |
| 45 |
Binding[] bindings; |
| 46 |
Scheme scheme; |
| 47 |
boolean found; |
| 48 |
|
| 49 |
found = false; |
| 50 |
bindings = bindingService.getBindings(); |
| 51 |
if (bindings != null) { |
| 52 |
for (int i = 0; i < bindings.length; i++) { |
| 53 |
final Binding binding = bindings[i]; |
| 54 |
if ("monkey".equals(binding.getSchemeId()) |
| 55 |
&& IContextIds.CONTEXT_ID_WINDOW.equals(binding |
| 56 |
.getContextId()) |
| 57 |
&& "org.eclipse.ui.views.showView".equals(binding |
| 58 |
.getParameterizedCommand().getId()) |
| 59 |
&& binding.getParameterizedCommand().getParameterMap() |
| 60 |
.containsKey( |
| 61 |
"org.eclipse.ui.views.showView.viewId") |
| 62 |
&& binding.getPlatform() == null |
| 63 |
&& binding.getLocale() == null |
| 64 |
&& binding.getType() == Binding.SYSTEM |
| 65 |
&& triggerSequence.equals(binding.getTriggerSequence())) { |
| 66 |
found = true; |
| 67 |
|
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
assertTrue(!found); |
| 72 |
scheme = bindingService.getScheme("monkey"); |
| 73 |
try { |
| 74 |
scheme.getName(); |
| 75 |
fail(); |
| 76 |
} catch (final NotDefinedException e) { |
| 77 |
assertTrue(true); |
| 78 |
} |
| 79 |
|
| 80 |
getBundle(); |
| 81 |
|
| 82 |
found = false; |
| 83 |
bindings = bindingService.getBindings(); |
| 84 |
if (bindings != null) { |
| 85 |
for (int i = 0; i < bindings.length; i++) { |
| 86 |
final Binding binding = bindings[i]; |
| 87 |
if ("monkey".equals(binding.getSchemeId()) |
| 88 |
&& IContextIds.CONTEXT_ID_WINDOW.equals(binding |
| 89 |
.getContextId()) |
| 90 |
&& "org.eclipse.ui.views.showView".equals(binding |
| 91 |
.getParameterizedCommand().getId()) |
| 92 |
&& binding.getParameterizedCommand().getParameterMap() |
| 93 |
.containsKey( |
| 94 |
"org.eclipse.ui.views.showView.viewId") |
| 95 |
&& binding.getPlatform() == null |
| 96 |
&& binding.getLocale() == null |
| 97 |
&& binding.getType() == Binding.SYSTEM |
| 98 |
&& triggerSequence.equals(binding.getTriggerSequence())) { |
| 99 |
found = true; |
| 100 |
|
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
assertTrue(found); |
| 105 |
scheme = bindingService.getScheme("monkey"); |
| 106 |
try { |
| 107 |
assertTrue("Monkey".equals(scheme.getName())); |
| 108 |
} catch (final NotDefinedException e) { |
| 109 |
fail(); |
| 110 |
} |
| 111 |
|
| 112 |
removeBundle(); |
| 113 |
|
| 114 |
found = false; |
| 115 |
bindings = bindingService.getBindings(); |
| 116 |
if (bindings != null) { |
| 117 |
for (int i = 0; i < bindings.length; i++) { |
| 118 |
final Binding binding = bindings[i]; |
| 119 |
if ("monkey".equals(binding.getSchemeId()) |
| 120 |
&& IContextIds.CONTEXT_ID_WINDOW.equals(binding |
| 121 |
.getContextId()) |
| 122 |
&& "org.eclipse.ui.views.showView".equals(binding |
| 123 |
.getParameterizedCommand().getId()) |
| 124 |
&& binding.getParameterizedCommand().getParameterMap() |
| 125 |
.containsKey( |
| 126 |
"org.eclipse.ui.views.showView.viewId") |
| 127 |
&& binding.getPlatform() == null |
| 128 |
&& binding.getLocale() == null |
| 129 |
&& binding.getType() == Binding.SYSTEM |
| 130 |
&& triggerSequence.equals(binding.getTriggerSequence())) { |
| 131 |
found = true; |
| 132 |
|
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
assertTrue(!found); |
| 137 |
scheme = bindingService.getScheme("monkey"); |
| 138 |
try { |
| 139 |
scheme.getName(); |
| 140 |
fail(); |
| 141 |
} catch (final NotDefinedException e) { |
| 142 |
assertTrue(true); |
| 143 |
} |
| 144 |
} |
| 145 |
} |