use of org.eclipse.ui.handlers.IHandlerService in project egit by eclipse.
the class UIUtils method notifySelectionChangedWithCurrentSelection.
/**
* Locates the current part and selection and fires
* {@link ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)}
* on the passed listener.
*
* @param serviceLocator
* @param selectionListener
*/
public static void notifySelectionChangedWithCurrentSelection(ISelectionListener selectionListener, IServiceLocator serviceLocator) {
IHandlerService handlerService = CommonUtils.getService(serviceLocator, IHandlerService.class);
IEvaluationContext state = handlerService.getCurrentState();
// This seems to be the most reliable way to get the active part, it
// also returns a part when it is called while creating a view that is
// being shown.Getting the active part through the active workbench
// window returned null in that case.
Object partObject = state.getVariable(ISources.ACTIVE_PART_NAME);
Object selectionObject = state.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
if (partObject instanceof IWorkbenchPart && selectionObject instanceof ISelection) {
IWorkbenchPart part = (IWorkbenchPart) partObject;
ISelection selection = (ISelection) selectionObject;
if (!selection.isEmpty())
selectionListener.selectionChanged(part, selection);
}
}
use of org.eclipse.ui.handlers.IHandlerService in project egit by eclipse.
the class SelectionUtils method getEvaluationContext.
private static IEvaluationContext getEvaluationContext() {
IEvaluationContext ctx;
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
// no active window during Eclipse shutdown
if (activeWorkbenchWindow == null)
return null;
IHandlerService hsr = CommonUtils.getService(activeWorkbenchWindow, IHandlerService.class);
ctx = hsr.getCurrentState();
return ctx;
}
use of org.eclipse.ui.handlers.IHandlerService in project egit by eclipse.
the class ReplaceWithOursTheirsMenu method getContributionItems.
@Override
protected IContributionItem[] getContributionItems() {
List<IContributionItem> items = new ArrayList<>();
IHandlerService handlerService = CommonUtils.getService(serviceLocator, IHandlerService.class);
IStructuredSelection selection = SelectionUtils.getSelection(handlerService.getCurrentState());
IPath[] locations = SelectionUtils.getSelectedLocations(selection);
if (locations.length == 0)
return new IContributionItem[0];
Map<Repository, Collection<String>> pathsByRepository = ResourceUtil.splitPathsByRepository(Arrays.asList(locations));
if (pathsByRepository.size() == 1) {
Repository repository = pathsByRepository.keySet().iterator().next();
Collection<String> paths = pathsByRepository.get(repository);
if (paths.size() == 1) {
String path = paths.iterator().next();
items.addAll(createSpecificOursTheirsItems(repository, path));
} else if (paths.size() > 1) {
items.addAll(createUnspecificOursTheirsItems(Arrays.asList(locations)));
}
}
return items.toArray(new IContributionItem[0]);
}
use of org.eclipse.ui.handlers.IHandlerService in project egit by eclipse.
the class RepositoryAction method createExecutionEvent.
/**
* Creates {@link ExecutionEvent} based on current selection
*
* @return {@link ExecutionEvent} with current selection
*/
protected ExecutionEvent createExecutionEvent() {
IServiceLocator locator = getServiceLocator();
ICommandService srv = CommonUtils.getService(locator, ICommandService.class);
IHandlerService hsrv = CommonUtils.getService(locator, IHandlerService.class);
Command command = srv.getCommand(commandId);
ExecutionEvent event = hsrv.createExecutionEvent(command, null);
if (event.getApplicationContext() instanceof IEvaluationContext)
((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
return event;
}
use of org.eclipse.ui.handlers.IHandlerService in project egit by eclipse.
the class StashesMenu method getRepository.
private Repository getRepository() {
if (serviceLocator == null)
return null;
IHandlerService handlerService = CommonUtils.getService(serviceLocator, IHandlerService.class);
if (handlerService == null)
return null;
IEvaluationContext evaluationContext = handlerService.getCurrentState();
return SelectionUtils.getRepository(evaluationContext);
}
Aggregations