解除键绑定期间发生异常

时间:2019-04-24 14:22:58

标签: eclipse-plugin

在我的透视插件中,我写了一些代码来解除F2键的绑定。但是激活bindingManager或保存活动绑定会引发此异常:

Cannot get the parent identifier from an undefined scheme. org.eclipse.ui.defaultAcceleratorConfiguration

我的代码:

ContextManager contextManager = new ContextManager(); 

BindingManager bindingManager = new BindingManager(contextManager, 
                            commandManager); 
IBindingService bindingService = (IBindingService) PlatformUI.
getWorkbench().getAdapter(IBindingService.class);
Binding[] bindings = bindingService.getBindings();
for (Binding binding : bindings) {
             if(binding.getTriggerSequence().format().equals("F2"))
            {
                            KeyBinding keyBinding = (KeyBinding) binding;
                            String contextId = binding.getContextId();
                            String schemeId = binding.getSchemeId();
                            KeySequence triggerSequence = keyBinding.getKeySequence();

                            ParameterizedCommand parameterizedCommand = binding
                            .getParameterizedCommand();
                            Command command = parameterizedCommand.getCommand();
                            KeyBinding deleteBinding = new KeyBinding(triggerSequence,
                                                            null, schemeId, contextId, null, null, null,
                                                            Binding.USER);

                            bindingManager.addBinding(deleteBinding);
}
}
try {

bindingManager 
.setActiveScheme(bindingService.getActiveScheme());
} catch (final NotDefinedException e) {
throw new Error(
"Error"); //$NON-NLS-1$
}
try {
bindingService.savePreferences(
bindingManager .getActiveScheme(), bindingManager 
.getBindings());
} catch (IOException e) {
e.printStackTrace();
}

0 个答案:

没有答案