Search in sources :

Example 21 with ICommandService

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

the class ApplicationWorkbenchWindowAdvisor method postWindowOpen.

@Override
public void postWindowOpen() {
    IWorkbenchWindow workbenchWindow = getWindowConfigurer().getWindow();
    //		workbenchWindow.getShell().setMaximized(true);
    restorEditorHistory();
    saveEditorHistory();
    final ICommandService commandService = (ICommandService) workbenchWindow.getService(ICommandService.class);
    // 在程序主体窗口打开之前,更新打开工具栏的菜单,让它初始化菜单图片 --robert 2012-03-19
    commandService.refreshElements("net.heartsome.cat.ts.openToolBarCommand", null);
    // 添加监听
    addViewPartVisibleListener(workbenchWindow);
    addWorkplaceListener();
    // 自动检查更新
    automaticCheckUpdate();
    // 设置将文件拖到导航视图时的模式为直接复制
    setDragModle();
    setListenerToPespective(commandService);
    setIdToHelpSystem();
    setProgressIndicatorVisible(false);
    setInitLinkEnable();
    // 处理 hunspell 内置词典内置文件
    try {
        CommonFunction.unZipHunspellDics();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ICommandService(org.eclipse.ui.commands.ICommandService) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 22 with ICommandService

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

the class CommandsPropertyTester method test.

public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
    if (receiver instanceof IServiceLocator && args.length == 1 && args[0] instanceof String) {
        final IServiceLocator locator = (IServiceLocator) receiver;
        if (TOGGLE_PROPERTY_NAME.equals(property)) {
            final String commandId = args[0].toString();
            final ICommandService commandService = (ICommandService) locator.getService(ICommandService.class);
            final Command command = commandService.getCommand(commandId);
            final State state = command.getState(RegistryToggleState.STATE_ID);
            if (state != null) {
                return state.getValue().equals(expectedValue);
            }
        }
    }
    return false;
}
Also used : Command(org.eclipse.core.commands.Command) RegistryToggleState(org.eclipse.ui.handlers.RegistryToggleState) State(org.eclipse.core.commands.State) IServiceLocator(org.eclipse.ui.services.IServiceLocator) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 23 with ICommandService

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

the class OpenStatusBarHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
    boolean oldValue = preferenceStore.getBoolean(TsPreferencesConstant.TS_statusBar_status);
    ApplicationWorkbenchWindowAdvisor configurer = ApplicationWorkbenchAdvisor.WorkbenchWindowAdvisor;
    configurer.setStatusVisible(!oldValue);
    preferenceStore.setValue(TsPreferencesConstant.TS_statusBar_status, !oldValue);
    ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    commandService.refreshElements(event.getCommand().getId(), null);
    return null;
}
Also used : ApplicationWorkbenchWindowAdvisor(net.heartsome.cat.ts.ApplicationWorkbenchWindowAdvisor) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 24 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)

Example 25 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)

Aggregations

ICommandService (org.eclipse.ui.commands.ICommandService)38 Command (org.eclipse.core.commands.Command)24 IHandlerService (org.eclipse.ui.handlers.IHandlerService)8 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)7 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)7 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)6 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)6 ExecutionException (org.eclipse.core.commands.ExecutionException)4 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)4 IEvaluationService (org.eclipse.ui.services.IEvaluationService)4 HashMap (java.util.HashMap)3 NotEnabledException (org.eclipse.core.commands.NotEnabledException)3 NotHandledException (org.eclipse.core.commands.NotHandledException)3 State (org.eclipse.core.commands.State)3 ISelection (org.eclipse.jface.viewers.ISelection)3 StyledText (org.eclipse.swt.custom.StyledText)3 Composite (org.eclipse.swt.widgets.Composite)3 Test (org.junit.Test)3 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)2 IHandler (org.eclipse.core.commands.IHandler)2