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