Search in sources :

Example 6 with ICommandService

use of org.eclipse.ui.commands.ICommandService in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method changeLayout.

/**
	 * 改变当前布局 ;
	 */
public void changeLayout() {
    isHorizontalLayout = !isHorizontalLayout;
    changeLayout(isHorizontalLayout);
    // 刷新工具栏的改变布局按钮的图片
    ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    commandService.refreshElements("net.heartsome.cat.ts.ui.handlers.ChangeXliffEditorModelCommand", null);
}
Also used : ICommandService(org.eclipse.ui.commands.ICommandService)

Example 7 with ICommandService

use of org.eclipse.ui.commands.ICommandService 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 8 with ICommandService

use of org.eclipse.ui.commands.ICommandService 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 9 with ICommandService

use of org.eclipse.ui.commands.ICommandService in project translationstudio8 by heartsome.

the class AbstractShieldCommandStartup method earlyStartup.

public void earlyStartup() {
    Set<String> unusedCommand = getUnusedCommandSet();
    IWorkbench workbench = PlatformUI.getWorkbench();
    ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
    Command command;
    for (String commandId : unusedCommand) {
        command = commandService.getCommand(commandId);
        command.undefine();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Command(org.eclipse.core.commands.Command) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 10 with ICommandService

use of org.eclipse.ui.commands.ICommandService 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

ICommandService (org.eclipse.ui.commands.ICommandService)15 Command (org.eclipse.core.commands.Command)8 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)5 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)4 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)3 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)3 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 NotEnabledException (org.eclipse.core.commands.NotEnabledException)2 NotHandledException (org.eclipse.core.commands.NotHandledException)2 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)2 Binding (org.eclipse.jface.bindings.Binding)2 IWorkbench (org.eclipse.ui.IWorkbench)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 IEvaluationService (org.eclipse.ui.services.IEvaluationService)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1