Search in sources :

Example 46 with IEvaluationContext

use of org.eclipse.core.expressions.IEvaluationContext in project egit by eclipse.

the class GitActionContributor method createItem.

private CommandContributionItem createItem(String itemAction) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    CommandContributionItemParameter itemParam = new CommandContributionItemParameter(workbench, null, itemAction, STYLE_PUSH);
    IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
    IHandlerService hsr = CommonUtils.getService(activeWorkbenchWindow, IHandlerService.class);
    IEvaluationContext ctx = hsr.getCurrentState();
    ctx.addVariable(ACTIVE_MENU_SELECTION_NAME, getContext().getSelection());
    return new CommandContributionItem(itemParam);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IHandlerService(org.eclipse.ui.handlers.IHandlerService) CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 47 with IEvaluationContext

use of org.eclipse.core.expressions.IEvaluationContext in project egit by eclipse.

the class RebaseCurrentRefCommand method setEnabled.

@Override
public void setEnabled(Object evaluationContext) {
    if (evaluationContext instanceof IEvaluationContext) {
        IEvaluationContext ctx = (IEvaluationContext) evaluationContext;
        Repository repo = SelectionUtils.getRepository(ctx);
        if (repo != null) {
            boolean enabled = isEnabledForState(repo, repo.getRepositoryState());
            setBaseEnabled(enabled);
        } else {
            setBaseEnabled(false);
        }
        return;
    }
    setBaseEnabled(true);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext)

Example 48 with IEvaluationContext

use of org.eclipse.core.expressions.IEvaluationContext in project core by jcryptool.

the class AlgorithmTreeViewer method makeAndAssignActions.

/**
 * creates the actions according to the algorithm extension point and assigns them to the
 * viewers double click listener
 */
private void makeAndAssignActions() {
    doubleClickHandler = new AbstractHandler() {

        public Object execute(ExecutionEvent event) {
            TreeObject treeObject = (TreeObject) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
            if (editorReferences.length == 0 && (!treeObject.getParent().getName().equals(org.jcryptool.core.Messages.applicationActionBarAdvisor_Menu_Algorithms_PRNG))) {
                AlgorithmView.showMessage(Messages.AlgorithmView_warning_message_no_active_editor);
            } else {
                final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
                Iterator<CommandInfo> it9 = algorithmList.iterator();
                CommandInfo commandInfo = null;
                while (it9.hasNext()) {
                    commandInfo = it9.next();
                    ShadowAlgorithmHandler handler = (ShadowAlgorithmHandler) commandInfo.getHandler();
                    String commandId = commandInfo.getCommandId();
                    if (commandId != null && treeObject.getName().equals(handler.getText())) {
                        Command command = commandService.getCommand(commandId);
                        try {
                            return command.executeWithChecks(event);
                        } catch (Exception ex) {
                            LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
                            return (null);
                        }
                    }
                }
            }
            return (null);
        }
    };
    addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(final DoubleClickEvent event) {
            Object obj = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (obj instanceof TreeParent) {
                if (viewer.getTree().getSelection()[0].getExpanded()) {
                    viewer.collapseToLevel(obj, 1);
                } else {
                    viewer.expandToLevel(obj, 1);
                }
            } else if (obj instanceof TreeObject) {
                try {
                    final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
                    IEvaluationContext evaluationContext = handlerService.createContextSnapshot(true);
                    ExecutionEvent executionEvent = new ExecutionEvent(null, Collections.EMPTY_MAP, null, evaluationContext);
                    // run assigned action
                    doubleClickHandler.execute(executionEvent);
                } catch (ExecutionException ex) {
                    LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
                }
            }
        }
    });
    addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(final SelectionChangedEvent event) {
            Object treeObject = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (treeObject instanceof TreeParent) {
                // $NON-NLS-1$
                PlatformUI.getWorkbench().getHelpSystem().displayHelp(ViewsPlugin.PLUGIN_ID + ".algorithmsView");
                getControl().setFocus();
            } else if (treeObject instanceof TreeObject) {
                AlgorithmView.showContextHelp(extensionPointId, ((TreeObject) treeObject).getName());
                getControl().setFocus();
            }
        }
    });
}
Also used : ShadowAlgorithmHandler(org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler) TreeParent(org.jcryptool.core.views.content.structure.TreeParent) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractHandler(org.eclipse.core.commands.AbstractHandler) ICommandService(org.eclipse.ui.commands.ICommandService) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) CommandInfo(org.jcryptool.core.operations.CommandInfo) IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Iterator(java.util.Iterator) TreeObject(org.jcryptool.core.views.content.structure.TreeObject) TreeObject(org.jcryptool.core.views.content.structure.TreeObject) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 49 with IEvaluationContext

use of org.eclipse.core.expressions.IEvaluationContext in project core by jcryptool.

the class CryptoContributionItem method run.

/* This should hopefully be obsolete
    public void run(IAction cryptoAction) {
        final IHandlerService handlerService = (IHandlerService) view.getSite().getService(IHandlerService.class);
        IEvaluationContext evaluationContext = handlerService.createContextSnapshot(true);
        ExecutionEvent event = new ExecutionEvent(null, Collections.EMPTY_MAP, null, evaluationContext);

        try {
            handler.execute(event);
            cryptoAction.run();
        } catch (ExecutionException ex) {
            LogUtil.logError(FileExplorerPlugin.PLUGIN_ID, ex);
        }
    }
    */
public void run(String commandId) {
    final IHandlerService handlerService = (IHandlerService) view.getSite().getService(IHandlerService.class);
    IEvaluationContext evaluationContext = handlerService.createContextSnapshot(true);
    ExecutionEvent event = new ExecutionEvent(null, Collections.EMPTY_MAP, null, evaluationContext);
    final ICommandService commandService = (ICommandService) view.getSite().getService(ICommandService.class);
    Command command = commandService.getCommand(commandId);
    try {
        handler.execute(event);
        command.executeWithChecks(event);
    } catch (Exception ex) {
        LogUtil.logError(FileExplorerPlugin.PLUGIN_ID, ex);
    }
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ICommandService(org.eclipse.ui.commands.ICommandService)

Aggregations

IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)49 ICommandService (org.eclipse.ui.commands.ICommandService)22 Command (org.eclipse.core.commands.Command)21 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)19 IHandlerService (org.eclipse.ui.handlers.IHandlerService)19 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)11 ISelection (org.eclipse.jface.viewers.ISelection)10 ExecutionException (org.eclipse.core.commands.ExecutionException)9 Expression (org.eclipse.core.expressions.Expression)9 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)7 CoreException (org.eclipse.core.runtime.CoreException)7 ArrayList (java.util.ArrayList)6 AdaptExpression (org.eclipse.core.internal.expressions.AdaptExpression)6 IterateExpression (org.eclipse.core.internal.expressions.IterateExpression)6 WithExpression (org.eclipse.core.internal.expressions.WithExpression)6 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)5 AndExpression (org.eclipse.core.internal.expressions.AndExpression)5 CountExpression (org.eclipse.core.internal.expressions.CountExpression)5 EnablementExpression (org.eclipse.core.internal.expressions.EnablementExpression)5