Search in sources :

Example 21 with IEvaluationContext

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

the class ToggleDCIFilterHandler method execute.

/* (non-Javadoc)
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Object object = event.getApplicationContext();
    if (object instanceof IEvaluationContext) {
        // $NON-NLS-1$
        Object tab = ((IEvaluationContext) object).getVariable("org.netxms.ui.eclipse.objectview.ActiveTab");
        if ((tab != null) && (tab instanceof LastValues)) {
            ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
            // $NON-NLS-1$
            Command command = service.getCommand("org.netxms.ui.eclipse.datacollection.commands.show_dci_filter");
            // $NON-NLS-1$
            State state = command.getState("org.netxms.ui.eclipse.datacollection.commands.show_dci_filter.state");
            boolean isChecked = !(Boolean) state.getValue();
            state.setValue(isChecked);
            ((LastValues) tab).setFilterEnabled(isChecked);
            service.refreshElements(event.getCommand().getId(), null);
        }
    }
    return null;
}
Also used : Command(org.eclipse.core.commands.Command) State(org.eclipse.core.commands.State) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) LastValues(org.netxms.ui.eclipse.datacollection.objecttabs.LastValues) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 22 with IEvaluationContext

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

the class SyncDisconnectHandler method setEnabled.

@Override
public void setEnabled(Object evaluationContext) {
    Repository repository = org.eclipse.flux.core.Activator.getDefault().getRepository();
    if (repository != null && evaluationContext instanceof IEvaluationContext) {
        IEvaluationContext evalContext = (IEvaluationContext) evaluationContext;
        Object selection = evalContext.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
        if (selection instanceof ISelection) {
            IProject[] selectedProjects = getSelectedProjects((ISelection) selection);
            for (IProject project : selectedProjects) {
                if (repository.isConnected(project)) {
                    setBaseEnabled(true);
                    return;
                }
            }
        }
    }
    setBaseEnabled(false);
}
Also used : Repository(org.eclipse.flux.core.Repository) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ISelection(org.eclipse.jface.viewers.ISelection) IProject(org.eclipse.core.resources.IProject)

Example 23 with IEvaluationContext

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

the class SyncConnectHandler method setEnabled.

@Override
public void setEnabled(Object evaluationContext) {
    Repository repository = org.eclipse.flux.core.Activator.getDefault().getRepository();
    if (repository != null && evaluationContext instanceof IEvaluationContext) {
        IEvaluationContext evalContext = (IEvaluationContext) evaluationContext;
        Object selection = evalContext.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
        if (selection instanceof ISelection) {
            IProject[] selectedProjects = getSelectedProjects((ISelection) selection);
            for (IProject project : selectedProjects) {
                if (!repository.isConnected(project)) {
                    setBaseEnabled(true);
                    return;
                }
            }
        }
    }
    setBaseEnabled(false);
}
Also used : Repository(org.eclipse.flux.core.Repository) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ISelection(org.eclipse.jface.viewers.ISelection) IProject(org.eclipse.core.resources.IProject)

Example 24 with IEvaluationContext

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

the class ActionUtils method runCommand.

public static void runCommand(String commandId, ISelection selection, Map<String, Object> parameters, IServiceLocator serviceLocator) {
    if (commandId != null) {
        try {
            ICommandService commandService = serviceLocator.getService(ICommandService.class);
            IHandlerService handlerService = serviceLocator.getService(IHandlerService.class);
            if (commandService != null) {
                Command command = commandService.getCommand(commandId);
                boolean needContextPatch = false;
                if (selection != null) {
                    needContextPatch = true;
                    if (serviceLocator instanceof IWorkbenchSite) {
                        final ISelection curSelection = ((IWorkbenchSite) serviceLocator).getSelectionProvider().getSelection();
                        if (curSelection instanceof IStructuredSelection && selection instanceof IStructuredSelection) {
                            if (((IStructuredSelection) curSelection).size() == ((IStructuredSelection) selection).size() && ((IStructuredSelection) curSelection).getFirstElement() == ((IStructuredSelection) selection).getFirstElement()) {
                                // The same selection
                                needContextPatch = false;
                            }
                        }
                    }
                }
                Parameterization[] parametrization = null;
                if (!CommonUtils.isEmpty(parameters)) {
                    parametrization = new Parameterization[parameters.size()];
                    int paramIndex = 0;
                    for (Map.Entry<String, Object> param : parameters.entrySet()) {
                        IParameter parameter = command.getParameter(param.getKey());
                        if (parameter != null) {
                            parametrization[paramIndex] = new Parameterization(parameter, CommonUtils.toString(param.getValue()));
                        } else {
                            log.debug("Parameter '" + param.getKey() + "' not found in command '" + commandId + "'");
                            parametrization[paramIndex] = null;
                        }
                        paramIndex++;
                    }
                }
                if (selection != null && needContextPatch) {
                    // Create new eval context
                    IEvaluationContext context = new EvaluationContext(handlerService.createContextSnapshot(false), selection);
                    if (serviceLocator instanceof IWorkbenchPartSite) {
                        context.addVariable(ISources.ACTIVE_PART_NAME, ((IWorkbenchPartSite) serviceLocator).getPart());
                    }
                    context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
                    ParameterizedCommand pc = new ParameterizedCommand(command, parametrization);
                    handlerService.executeCommandInContext(pc, null, context);
                } else if (command != null) {
                    if (command.isEnabled()) {
                        ParameterizedCommand pc = new ParameterizedCommand(command, parametrization);
                        handlerService.executeCommand(pc, null);
                    } else {
                        log.warn("Command '" + commandId + "' is disabled");
                    }
                } else {
                    log.warn("Command '" + commandId + "' not found");
                }
            }
        } catch (Exception e) {
            DBWorkbench.getPlatformUI().showError("Error running command", "Can't execute command '" + commandId + "'", e);
        }
    }
}
Also used : IParameter(org.eclipse.core.commands.IParameter) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Parameterization(org.eclipse.core.commands.Parameterization) ICommandService(org.eclipse.ui.commands.ICommandService) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) IHandlerService(org.eclipse.ui.handlers.IHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) ISelection(org.eclipse.jface.viewers.ISelection) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) Map(java.util.Map) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 25 with IEvaluationContext

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

the class AlgorithmPaletteViewer method makeAndAssignActions.

/**
 * Constructs the actions according to the algorithm extension point and
 * assigns the actions to the doubleclick listener of the viewer
 */
private void makeAndAssignActions() {
    doubleClickHandler = new AbstractHandler() {

        public Object execute(ExecutionEvent event) {
            Object selection = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (selection instanceof PaletteEditPart) {
                PaletteEditPart paletteEditPart = (PaletteEditPart) selection;
                Object model = paletteEditPart.getModel();
                IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
                if (editorReferences.length == 0 && (!((PaletteEntry) model).getParent().getLabel().equals(org.jcryptool.core.Messages.applicationActionBarAdvisor_Menu_Algorithms_PRNG))) {
                    AlgorithmView.showMessage(Messages.AlgorithmPaletteViewer_0);
                } 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 && model.toString().equals("Palette Entry (" + handler.getText() + ")")) {
                            // $NON-NLS-1$ //$NON-NLS-2$
                            Command command = commandService.getCommand(commandId);
                            try {
                                return command.executeWithChecks(event);
                            } catch (Exception ex) {
                                LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
                                return (null);
                            }
                        }
                    }
                }
            }
            return (null);
        }
    };
    viewer.getControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(final MouseEvent e) {
            if (e.button == 1) {
                // only left button double clicks
                final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
                IEvaluationContext evaluationContext = handlerService.createContextSnapshot(true);
                ExecutionEvent event = new ExecutionEvent(null, Collections.EMPTY_MAP, null, evaluationContext);
                try {
                    // run assigned action
                    doubleClickHandler.execute(event);
                } catch (ExecutionException ex) {
                    LogUtil.logError(ViewsPlugin.PLUGIN_ID, ex);
                }
            }
        }

        @Override
        public void mouseDown(final MouseEvent e) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object obj = selection.getFirstElement();
            if (obj instanceof PaletteEditPart) {
                AlgorithmView.showContextHelp(extensionPointId, ((PaletteEntry) ((PaletteEditPart) obj).getModel()).getLabel());
                viewer.getControl().setFocus();
                viewer.setSelection(selection);
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) ShadowAlgorithmHandler(org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PaletteEntry(org.eclipse.gef.palette.PaletteEntry) PaletteEditPart(org.eclipse.gef.ui.palette.editparts.PaletteEditPart) AbstractHandler(org.eclipse.core.commands.AbstractHandler) ICommandService(org.eclipse.ui.commands.ICommandService) 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) Iterator(java.util.Iterator) ExecutionException(org.eclipse.core.commands.ExecutionException)

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