use of org.eclipse.e4.ui.bindings.EBindingService in project jbosstools-jst by jbosstools.
the class KeyBindingsTest method doTestKeyBindingsOnPage.
private void doTestKeyBindingsOnPage(String pageName) {
openEditor(pageName);
try {
PartSite partSite = (PartSite) (editorPart.getEditorSite() instanceof PartSite ? editorPart.getEditorSite() : null);
assertNotNull("Cannot get PartSite instance for " + pageName, partSite);
IEclipseContext context = partSite.getContext();
assertNotNull("Cannot get EclipseContext instance for " + pageName, context);
EBindingService bindingService = (EBindingService) context.get(EBindingService.class.getName());
assertNotNull("Cannot get BindingService instance for " + pageName, bindingService);
for (KeyCombination key : keys) {
Event event = createKeyCombinationEvent(key.mask, key.key);
List<KeyStroke> keyStrokes = KeyBindingDispatcher.generatePossibleKeyStrokes(event);
boolean found = false;
KeySequence sequenceBeforeKeyStroke = KeySequence.getInstance();
for (Iterator<KeyStroke> iterator = keyStrokes.iterator(); iterator.hasNext(); ) {
KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, iterator.next());
if (isPerfectMatch(bindingService, sequenceAfterKeyStroke)) {
final ParameterizedCommand cmd = getPerfectMatch(bindingService, sequenceAfterKeyStroke);
assertNotNull("Command not found for 'Perfect Match' keystroke " + sequenceAfterKeyStroke, cmd);
assertNotNull("Command found but cannot be executed for 'Perfect Match' keystroke " + sequenceAfterKeyStroke, HandlerServiceImpl.lookUpHandler(context, cmd.getId()));
found = true;
break;
}
}
assertTrue("Command not found for key combination " + key.mask + "/" + key.key, found);
}
} finally {
closeEditor();
}
}
use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.
the class KeyAssistDialog method getActiveBindings.
private Collection<Binding> getActiveBindings() {
EBindingService bindingService = context.getActiveLeaf().get(EBindingService.class);
Iterator<Binding> iter, matchesIter;
Binding binding, bindingToAdd;
Collection<Binding> matchesForCommand;
Collection<Binding> activeBindings = bindingService.getActiveBindings();
Collection<Binding> conflictBindings = bindingService.getAllConflicts();
Collection<Binding> sortedMatches = new TreeSet<>((binding1, binding2) -> {
ParameterizedCommand cmdA = binding1.getParameterizedCommand();
ParameterizedCommand cmdB = binding2.getParameterizedCommand();
int result = 0;
try {
result = cmdA.getName().compareTo(cmdB.getName());
} catch (NotDefinedException e) {
// whaaa?
}
return result;
});
// different schemes, then we need to handle which one should be displayed in the dialog
if (activeBindings != null) {
iter = activeBindings.iterator();
while (iter.hasNext()) {
binding = iter.next();
matchesForCommand = bindingService.getBindingsFor(binding.getParameterizedCommand());
// belong to the default scheme, then arbitrarily choose one
if (matchesForCommand != null && matchesForCommand.size() > 1) {
bindingToAdd = null;
matchesIter = matchesForCommand.iterator();
while (matchesIter.hasNext()) {
bindingToAdd = matchesIter.next();
if (!bindingToAdd.getSchemeId().equals(EBindingService.DEFAULT_SCHEME_ID)) {
sortedMatches.add(bindingToAdd);
break;
}
}
// if they're all the same, arbitrarily choose one
if (bindingToAdd != null) {
sortedMatches.add(bindingToAdd);
}
} else // if there is only one match, then just add it
if (matchesForCommand != null && matchesForCommand.size() == 1) {
sortedMatches.addAll(matchesForCommand);
}
}
}
if (conflictBindings != null) {
iter = conflictBindings.iterator();
while (iter.hasNext()) {
binding = iter.next();
sortedMatches.add(binding);
}
}
return sortedMatches;
}
use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.
the class CustomizePerspectiveDialog method getToolTipText.
private String getToolTipText(MItem item) {
String text = item.getLocalizedTooltip();
if (item instanceof MHandledItem) {
MHandledItem handledItem = (MHandledItem) item;
EBindingService bs = context.get(EBindingService.class);
ParameterizedCommand cmd = handledItem.getWbCommand();
if (cmd == null) {
cmd = generateParameterizedCommand(handledItem, context);
}
TriggerSequence sequence = bs.getBestSequenceFor(handledItem.getWbCommand());
if (sequence != null) {
if (text == null) {
try {
text = cmd.getName();
} catch (NotDefinedException e) {
return null;
}
}
// $NON-NLS-1$
text = text + " (" + sequence.format() + ')';
}
return text;
} else if (OpaqueElementUtil.isOpaqueMenuItem(item)) {
Object opaque = OpaqueElementUtil.getOpaqueItem(item);
if (opaque instanceof ActionContributionItem) {
return ((ActionContributionItem) opaque).getAction().getText();
}
} else if (OpaqueElementUtil.isOpaqueToolItem(item)) {
Object opaque = OpaqueElementUtil.getOpaqueItem(item);
if (opaque instanceof ActionContributionItem) {
return ((ActionContributionItem) opaque).getAction().getToolTipText();
}
}
return text;
}
use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.
the class BindingLookupTest method testLookupAllShortcuts.
@Test
public void testLookupAllShortcuts() {
ECommandService cs = workbenchContext.get(ECommandService.class);
ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null);
EBindingService bs = workbenchContext.get(EBindingService.class);
TriggerSequence seq2 = bs.createSequence("ALT+5 X");
Binding db2 = createDefaultBinding(bs, seq2, cmd, ID_DIALOG_AND_WINDOW);
bs.activateBinding(db2);
TriggerSequence seq = bs.createSequence("CTRL+5 T");
Binding db = createDefaultBinding(bs, seq, cmd, ID_DIALOG_AND_WINDOW);
bs.activateBinding(db);
// the list will always be ordered
ArrayList<TriggerSequence> list = new ArrayList<>();
list.add(seq);
list.add(seq2);
assertEquals(list, bs.getSequencesFor(cmd));
}
use of org.eclipse.e4.ui.bindings.EBindingService in project eclipse.platform.ui by eclipse-platform.
the class BindingLookupTest method testMultipleBindings.
@Test
public void testMultipleBindings() {
ECommandService cs = workbenchContext.get(ECommandService.class);
ParameterizedCommand cmd = cs.createCommand(TEST_ID1, null);
EBindingService bs = workbenchContext.get(EBindingService.class);
TriggerSequence seq = bs.createSequence("CTRL+5 T");
TriggerSequence seq2 = bs.createSequence("CTRL+2 X");
Binding db = createDefaultBinding(bs, seq, cmd, ID_DIALOG_AND_WINDOW);
bs.activateBinding(db);
db = createDefaultBinding(bs, seq2, cmd, ID_DIALOG_AND_WINDOW);
bs.activateBinding(db);
assertEquals(cmd, bs.getPerfectMatch(seq).getParameterizedCommand());
assertEquals(cmd, bs.getPerfectMatch(seq2).getParameterizedCommand());
}
Aggregations