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;
}
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);
}
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);
}
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);
}
}
}
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);
}
}
});
}
Aggregations