Search in sources :

Example 6 with IServiceLocator

use of org.eclipse.ui.services.IServiceLocator in project egit by eclipse.

the class GarbageCollectCommand method execute.

/**
 * Execute garbage collection
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // get selected nodes
    final List<RepositoryNode> selectedNodes;
    try {
        selectedNodes = getSelectedNodes(event);
        if (selectedNodes.isEmpty())
            return null;
    } catch (ExecutionException e) {
        Activator.handleError(e.getMessage(), e, true);
        return null;
    }
    Job job = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "Collecting Garbage...") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            for (RepositoryNode node : selectedNodes) {
                Repository repo = node.getRepository();
                String name = MessageFormat.format(UIText.GarbageCollectCommand_jobTitle, getRepositoryName(repo));
                this.setName(name);
                final GarbageCollectOperation op = new GarbageCollectOperation(repo);
                try {
                    op.execute(monitor);
                } catch (CoreException e) {
                    Activator.logError(MessageFormat.format(UIText.GarbageCollectCommand_failed, repo), e);
                }
            }
            return Status.OK_STATUS;
        }
    };
    IServiceLocator serviceLocator = HandlerUtil.getActiveSite(event);
    if (serviceLocator != null) {
        IWorkbenchSiteProgressService service = CommonUtils.getService(serviceLocator, IWorkbenchSiteProgressService.class);
        service.schedule(job);
    } else {
        job.schedule();
    }
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) GarbageCollectOperation(org.eclipse.egit.core.op.GarbageCollectOperation) IServiceLocator(org.eclipse.ui.services.IServiceLocator) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) ExecutionException(org.eclipse.core.commands.ExecutionException) Job(org.eclipse.core.runtime.jobs.Job)

Example 7 with IServiceLocator

use of org.eclipse.ui.services.IServiceLocator 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 8 with IServiceLocator

use of org.eclipse.ui.services.IServiceLocator in project yamcs-studio by yamcs.

the class OPIShell method sendUpdateCommand.

/**
 * Alert whoever is listening that a new OPIShell has been created.
 */
private static void sendUpdateCommand() {
    IServiceLocator serviceLocator = PlatformUI.getWorkbench();
    var commandService = serviceLocator.getService(ICommandService.class);
    try {
        var command = commandService.getCommand(OPI_SHELLS_CHANGED_ID);
        command.executeWithChecks(new ExecutionEvent());
    } catch (ExecutionException | NotHandledException | NotEnabledException | NotDefinedException e) {
        log.log(Level.WARNING, "Failed to send OPI shells changed command", e);
    }
}
Also used : NotHandledException(org.eclipse.core.commands.NotHandledException) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IServiceLocator(org.eclipse.ui.services.IServiceLocator) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ExecutionException(org.eclipse.core.commands.ExecutionException) NotEnabledException(org.eclipse.core.commands.NotEnabledException)

Example 9 with IServiceLocator

use of org.eclipse.ui.services.IServiceLocator in project core by jcryptool.

the class ApplicationActionBarAdvisor method createEditMenu.

private IMenuManager createEditMenu() {
    MenuManager menu = new MenuManager(Messages.applicationActionBarAdvisor_Menu_Edit, IWorkbenchActionConstants.M_EDIT);
    menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));
    IServiceLocator serviceLocator = PlatformUI.getWorkbench();
    // undo, redo
    menu.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.EDIT_UNDO));
    menu.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.EDIT_REDO));
    menu.add(new GroupMarker(IWorkbenchActionConstants.UNDO_EXT));
    menu.add(new Separator());
    // cut, copy, paste
    menu.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.EDIT_CUT));
    menu.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.EDIT_COPY));
    menu.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.EDIT_PASTE));
    menu.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT));
    menu.add(new Separator());
    // delete, select all
    menu.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.EDIT_DELETE));
    menu.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.EDIT_SELECT_ALL));
    menu.add(new Separator());
    // find
    menu.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE));
    menu.add(new GroupMarker(IWorkbenchActionConstants.FIND_EXT));
    menu.add(new GroupMarker(IWorkbenchActionConstants.ADD_EXT));
    // provide a uniform location for the "show in" or "open with" actions
    // $NON-NLS-1$
    MenuManager showin = new MenuManager(Messages.ApplicationActionBarAdvisor_1, "showin");
    // $NON-NLS-1$
    showin.add(new GroupMarker("start"));
    menu.add(showin);
    menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));
    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    return menu;
}
Also used : MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IServiceLocator(org.eclipse.ui.services.IServiceLocator) GroupMarker(org.eclipse.jface.action.GroupMarker) Separator(org.eclipse.jface.action.Separator)

Example 10 with IServiceLocator

use of org.eclipse.ui.services.IServiceLocator in project core by jcryptool.

the class ApplicationActionBarAdvisor method fillCoolBar.

@Override
protected void fillCoolBar(ICoolBarManager coolBar) {
    // ToolBar File & Additions
    IToolBarManager fileToolBar = new ToolBarManager(coolBar.getStyle());
    IServiceLocator serviceLocator = PlatformUI.getWorkbench();
    fileToolBar.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
    fileToolBar.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.FILE_SAVE));
    fileToolBar.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.FILE_SAVE_ALL));
    fileToolBar.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.FILE_PRINT));
    fileToolBar.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
    fileToolBar.add(new Separator());
    fileToolBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
    // $NON-NLS-1$
    coolBar.add(new ToolBarContributionItem(fileToolBar, CorePlugin.PLUGIN_ID + ".toolbar"));
    // ToolBar Help
    IToolBarManager helpToolBar = new ToolBarManager(coolBar.getStyle());
    // $NON-NLS-1$
    coolBar.add(new ToolBarContributionItem(helpToolBar, CorePlugin.PLUGIN_ID + ".helpToolBar"));
    // CoolBar Context Menu
    // $NON-NLS-1$
    MenuManager coolBarContextMenuManager = new MenuManager(null, CorePlugin.PLUGIN_ID + ".contextMenu");
    coolBar.setContextMenuManager(coolBarContextMenuManager);
    coolBarContextMenuManager.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.WINDOW_LOCK_TOOLBAR));
    coolBarContextMenuManager.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.WINDOW_CUSTOMIZE_PERSPECTIVE));
    coolBarContextMenuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
}
Also used : ToolBarContributionItem(org.eclipse.jface.action.ToolBarContributionItem) IToolBarManager(org.eclipse.jface.action.IToolBarManager) IServiceLocator(org.eclipse.ui.services.IServiceLocator) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) GroupMarker(org.eclipse.jface.action.GroupMarker) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ToolBarManager(org.eclipse.jface.action.ToolBarManager) Separator(org.eclipse.jface.action.Separator)

Aggregations

IServiceLocator (org.eclipse.ui.services.IServiceLocator)17 Command (org.eclipse.core.commands.Command)4 IMenuManager (org.eclipse.jface.action.IMenuManager)4 MenuManager (org.eclipse.jface.action.MenuManager)4 Separator (org.eclipse.jface.action.Separator)4 ICommandService (org.eclipse.ui.commands.ICommandService)4 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 GroupMarker (org.eclipse.jface.action.GroupMarker)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 RepositoryNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryNode)2 Repository (org.eclipse.jgit.lib.Repository)2 IHandlerService (org.eclipse.ui.handlers.IHandlerService)2 IWorkbenchSiteProgressService (org.eclipse.ui.progress.IWorkbenchSiteProgressService)2 IOException (java.io.IOException)1 NotEnabledException (org.eclipse.core.commands.NotEnabledException)1 NotHandledException (org.eclipse.core.commands.NotHandledException)1 State (org.eclipse.core.commands.State)1 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)1