Search in sources :

Example 6 with IEvaluationContext

use of org.eclipse.core.expressions.IEvaluationContext 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 7 with IEvaluationContext

use of org.eclipse.core.expressions.IEvaluationContext in project tdi-studio-se by Talend.

the class TalendLaunchShortcutAction method updateEnablement.

/**
     * Since these actions are re-created each time the run/debug as menu is filled, the enablement of this action is
     * static.
     */
private void updateEnablement() {
    // IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow();
    IWorkbenchWindow wb = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    boolean enabled = false;
    if (wb != null) {
        IWorkbenchPage page = wb.getActivePage();
        if (page != null) {
            ISelection selection = page.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                try {
                    // check enablement logic, if any
                    Expression expression = fShortcut.getShortcutEnablementExpression();
                    if (expression == null) {
                        enabled = !structuredSelection.isEmpty();
                    } else {
                        List list = structuredSelection.toList();
                        IEvaluationContext context = new EvaluationContext(null, list);
                        //$NON-NLS-1$
                        context.addVariable("selection", list);
                        enabled = fShortcut.evalEnablementExpression(context, expression);
                    }
                } catch (CoreException e) {
                }
            } else {
                IEditorPart editor = page.getActiveEditor();
                if (editor != null) {
                    enabled = true;
                }
            }
        }
    }
    setEnabled(enabled);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) CoreException(org.eclipse.core.runtime.CoreException) Expression(org.eclipse.core.expressions.Expression) ISelection(org.eclipse.jface.viewers.ISelection) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) IEditorPart(org.eclipse.ui.IEditorPart)

Aggregations

IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)7 ISelection (org.eclipse.jface.viewers.ISelection)5 Command (org.eclipse.core.commands.Command)3 ICommandService (org.eclipse.ui.commands.ICommandService)3 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)2 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)2 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)2 IProject (org.eclipse.core.resources.IProject)2 Repository (org.eclipse.flux.core.Repository)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IEvaluationService (org.eclipse.ui.services.IEvaluationService)2 List (java.util.List)1 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)1 Language (net.heartsome.cat.common.locale.Language)1 ConcordanceSearchDialog (net.heartsome.cat.database.ui.tm.dialog.ConcordanceSearchDialog)1 ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)1 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 NotEnabledException (org.eclipse.core.commands.NotEnabledException)1