Search in sources :

Example 16 with IHandlerService

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);
    }
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ISelection(org.eclipse.jface.viewers.ISelection)

Example 17 with IHandlerService

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext)

Example 18 with IHandlerService

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]);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IPath(org.eclipse.core.runtime.IPath) IContributionItem(org.eclipse.jface.action.IContributionItem) ArrayList(java.util.ArrayList) Collection(java.util.Collection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 19 with IHandlerService

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;
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IServiceLocator(org.eclipse.ui.services.IServiceLocator) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 20 with IHandlerService

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);
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext)

Aggregations

IHandlerService (org.eclipse.ui.handlers.IHandlerService)107 ActionHandler (org.eclipse.jface.commands.ActionHandler)45 Action (org.eclipse.jface.action.Action)41 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)25 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)19 Command (org.eclipse.core.commands.Command)18 ICommandService (org.eclipse.ui.commands.ICommandService)18 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)15 AbstractHandler (org.eclipse.core.commands.AbstractHandler)11 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)10 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)9 IHandler (org.eclipse.core.commands.IHandler)8 IAction (org.eclipse.jface.action.IAction)8 GridLayout (org.eclipse.swt.layout.GridLayout)8 IContextService (org.eclipse.ui.contexts.IContextService)8 ArrayList (java.util.ArrayList)7