use of org.eclipse.core.commands.common.NotDefinedException in project dbeaver by serge-rider.
the class ActionUtils method findCommandDescription.
@Nullable
public static String findCommandDescription(String commandId, IServiceLocator serviceLocator, boolean shortcutOnly) {
String commandName = null;
String shortcut = null;
ICommandService commandService = serviceLocator.getService(ICommandService.class);
if (commandService != null) {
Command command = commandService.getCommand(commandId);
if (command != null && command.isDefined()) {
try {
commandName = command.getName();
} catch (NotDefinedException e) {
log.debug(e);
}
}
}
IBindingService bindingService = serviceLocator.getService(IBindingService.class);
if (bindingService != null) {
TriggerSequence sequence = null;
for (Binding b : bindingService.getBindings()) {
ParameterizedCommand parameterizedCommand = b.getParameterizedCommand();
if (parameterizedCommand != null && commandId.equals(parameterizedCommand.getId())) {
sequence = b.getTriggerSequence();
}
}
if (sequence == null) {
sequence = bindingService.getBestActiveBindingFor(commandId);
}
if (sequence != null) {
shortcut = sequence.format();
}
}
if (shortcutOnly) {
return shortcut == null ? "?" : shortcut;
}
if (shortcut == null) {
return commandName;
}
if (commandName == null) {
return shortcut;
}
return commandName + " (" + shortcut + ")";
}
use of org.eclipse.core.commands.common.NotDefinedException in project translationstudio8 by heartsome.
the class KeyController2 method setDefaultBindings.
/**
* Sets the bindings to default.
* @param bindingService
* @throws NotDefinedException
*/
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
// Fix the scheme in the local changes.
final String defaultSchemeId = bindingService.getDefaultSchemeId();
final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
try {
fBindingManager.setActiveScheme(defaultScheme);
} catch (final NotDefinedException e) {
// At least we tried....
}
// Restore any User defined bindings
Binding[] bindings = fBindingManager.getBindings();
for (int i = 0; i < bindings.length; i++) {
ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
String commandId = null;
if (pCommand != null) {
commandId = pCommand.getCommand().getId();
}
if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
fBindingManager.removeBinding(bindings[i]);
}
}
bindingModel.refresh(contextModel, lstRemove);
saveBindings(bindingService);
}
use of org.eclipse.core.commands.common.NotDefinedException in project translationstudio8 by heartsome.
the class BindingModel2 method init.
/**
* The initialization only.
* @param locator
* @param manager
* @param model
*/
public void init(IServiceLocator locator, BindingManager manager, ContextModel model) {
Set cmdsForBindings = new HashSet();
bindingToElement = new HashMap();
commandToElement = new HashMap();
bindingElements = new HashSet();
bindingManager = manager;
Iterator i = manager.getActiveBindingsDisregardingContextFlat().iterator();
while (i.hasNext()) {
Binding b = (Binding) i.next();
BindingElement be = new BindingElement(controller);
be.init(b, model);
be.setParent(this);
bindingElements.add(be);
bindingToElement.put(b, be);
cmdsForBindings.add(b.getParameterizedCommand());
}
ICommandService commandService = (ICommandService) locator.getService(ICommandService.class);
final Collection commandIds = commandService.getDefinedCommandIds();
allParameterizedCommands = new HashSet();
final Iterator commandIdItr = commandIds.iterator();
while (commandIdItr.hasNext()) {
final String currentCommandId = (String) commandIdItr.next();
final Command currentCommand = commandService.getCommand(currentCommandId);
try {
allParameterizedCommands.addAll(ParameterizedCommand.generateCombinations(currentCommand));
} catch (final NotDefinedException e) {
// It is safe to just ignore undefined commands.
}
}
i = allParameterizedCommands.iterator();
while (i.hasNext()) {
ParameterizedCommand cmd = (ParameterizedCommand) i.next();
if (!cmdsForBindings.contains(cmd)) {
BindingElement be = new BindingElement(controller);
be.init(cmd);
be.setParent(this);
bindingElements.add(be);
commandToElement.put(cmd, be);
}
}
}
use of org.eclipse.core.commands.common.NotDefinedException in project translationstudio8 by heartsome.
the class ConverterCommandTrigger method openDialog.
private static void openDialog(IWorkbenchWindow window, IFile file, String commandId) {
IWorkbench workbench = window.getWorkbench();
ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
Command command = commandService.getCommand(commandId);
try {
EvaluationContext context = new EvaluationContext(null, IEvaluationContext.UNDEFINED_VARIABLE);
context.addVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME, window);
if (file != null) {
StructuredSelection selection = new StructuredSelection(file);
context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
}
command.executeWithChecks(new ExecutionEvent(command, Collections.EMPTY_MAP, null, context));
} catch (ExecutionException e) {
LOGGER.error("", e);
} catch (NotDefinedException e) {
LOGGER.error("", e);
} catch (NotEnabledException e) {
LOGGER.error("", e);
} catch (NotHandledException e) {
LOGGER.error("", e);
}
}
use of org.eclipse.core.commands.common.NotDefinedException in project translationstudio8 by heartsome.
the class NewHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
String parameter = event.getParameter("wizardParameter");
Command command = null;
ICommandService commandService = (ICommandService) HandlerUtil.getActiveSite(event).getService(ICommandService.class);
if (parameter == null || parameter.equalsIgnoreCase("project")) {
command = commandService.getCommand("net.heartsome.cat.ts.ui.command.newProject");
} else if (parameter.equalsIgnoreCase("folder")) {
command = commandService.getCommand("net.heartsome.cat.ts.ui.command.newFolder");
} else if (parameter.equalsIgnoreCase("tm")) {
command = commandService.getCommand("net.heartsome.cat.database.ui.tm.command.newTM");
} else if (parameter.equalsIgnoreCase("tb")) {
command = commandService.getCommand("net.heartsome.cat.database.ui.tb.command.newTB");
}
if (command == null) {
return null;
}
IEvaluationService evalService = (IEvaluationService) HandlerUtil.getActiveSite(event).getService(IEvaluationService.class);
IEvaluationContext currentState = evalService.getCurrentState();
ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
try {
command.executeWithChecks(executionEvent);
} catch (NotDefinedException e) {
LOGGER.error("", e);
} catch (NotEnabledException e) {
LOGGER.error("", e);
} catch (NotHandledException e) {
LOGGER.error("", e);
}
return null;
}
Aggregations