Search in sources :

Example 6 with NotDefinedException

use of org.eclipse.core.commands.common.NotDefinedException in project translationstudio8 by heartsome.

the class KeyController2 method loadModelBackend.

private static BindingManager loadModelBackend(IServiceLocator locator) {
    IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
    BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
    final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
    try {
        Scheme modelActiveScheme = null;
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = bindingManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
            if (definedSchemes[i] == bindingService.getActiveScheme()) {
                modelActiveScheme = copy;
            }
        }
        bindingManager.setActiveScheme(modelActiveScheme);
    } catch (final NotDefinedException e) {
        StatusManager.getManager().handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH, "Keys page found an undefined scheme", //$NON-NLS-1$
        e));
    }
    bindingManager.setLocale(bindingService.getLocale());
    bindingManager.setPlatform(bindingService.getPlatform());
    bindingManager.setBindings(bindingService.getBindings());
    return bindingManager;
}
Also used : BindingManager(org.eclipse.jface.bindings.BindingManager) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CommandManager(org.eclipse.core.commands.CommandManager) Scheme(org.eclipse.jface.bindings.Scheme) ContextManager(org.eclipse.core.commands.contexts.ContextManager) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) IBindingService(org.eclipse.ui.keys.IBindingService)

Example 7 with NotDefinedException

use of org.eclipse.core.commands.common.NotDefinedException in project azure-tools-for-java by Microsoft.

the class AzureAbstractHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Map<String, String> properties = new HashMap<>();
    try {
        final Command cmd = event.getCommand();
        String handlerName = this.getClass().getSimpleName();
        final Collection<?> callingMenus = HandlerUtil.getActiveMenus(event);
        boolean fromProjectMenu = callingMenus != null && callingMenus.contains("org.eclipse.ui.navigator.ProjectExplorer#PopupMenu");
        properties.put("FromProjectMenu", String.valueOf(fromProjectMenu));
        if (cmd != null) {
            properties.put("CategoryId", cmd.getCategory().getId());
            properties.put("Category", cmd.getCategory().getName());
            properties.put("CommandId", cmd.getId());
            properties.put("Text", cmd.getName());
            if (null == handlerName || handlerName.isEmpty()) {
                handlerName = cmd.getName();
            }
        }
        AppInsightsClient.createByType(AppInsightsClient.EventType.Action, handlerName, null, properties);
    } catch (NotDefinedException ignore) {
    }
    return onExecute(event);
}
Also used : HashMap(java.util.HashMap) Command(org.eclipse.core.commands.Command) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException)

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