Search in sources :

Example 1 with NotDefinedException

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 + ")";
}
Also used : Binding(org.eclipse.jface.bindings.Binding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) IBindingService(org.eclipse.ui.keys.IBindingService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService) Nullable(org.jkiss.code.Nullable)

Example 2 with NotDefinedException

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);
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) Scheme(org.eclipse.jface.bindings.Scheme) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 3 with NotDefinedException

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);
        }
    }
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) Iterator(java.util.Iterator) Collection(java.util.Collection) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService) HashSet(java.util.HashSet)

Example 4 with NotDefinedException

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);
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) NotHandledException(org.eclipse.core.commands.NotHandledException) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) ExecutionException(org.eclipse.core.commands.ExecutionException) NotEnabledException(org.eclipse.core.commands.NotEnabledException) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 5 with NotDefinedException

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;
}
Also used : NotHandledException(org.eclipse.core.commands.NotHandledException) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) NotEnabledException(org.eclipse.core.commands.NotEnabledException) ICommandService(org.eclipse.ui.commands.ICommandService) IEvaluationService(org.eclipse.ui.services.IEvaluationService)

Aggregations

NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)7 Command (org.eclipse.core.commands.Command)5 ICommandService (org.eclipse.ui.commands.ICommandService)4 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)3 Binding (org.eclipse.jface.bindings.Binding)3 HashMap (java.util.HashMap)2 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)2 NotEnabledException (org.eclipse.core.commands.NotEnabledException)2 NotHandledException (org.eclipse.core.commands.NotHandledException)2 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)2 Scheme (org.eclipse.jface.bindings.Scheme)2 KeyBinding (org.eclipse.jface.bindings.keys.KeyBinding)2 IBindingService (org.eclipse.ui.keys.IBindingService)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 CommandManager (org.eclipse.core.commands.CommandManager)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 ContextManager (org.eclipse.core.commands.contexts.ContextManager)1