Search in sources :

Example 96 with IHandlerService

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

Example 97 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project egit by eclipse.

the class RepositoriesView method createEmptyArea.

/**
 * Create area shown when no repositories are present
 *
 * @param parent
 */
protected void createEmptyArea(Composite parent) {
    emptyArea = new Composite(parent, SWT.NONE);
    emptyArea.setBackgroundMode(SWT.INHERIT_FORCE);
    MenuManager manager = new MenuManager();
    manager.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager m) {
            getNavigatorActionService().fillContextMenu(m);
        }
    });
    getSite().registerContextMenu(manager, getCommonViewer());
    Menu menu = manager.createContextMenu(emptyArea);
    emptyArea.setMenu(menu);
    GridLayoutFactory.fillDefaults().applyTo(emptyArea);
    Composite infoArea = new Composite(emptyArea, SWT.NONE);
    infoArea.setMenu(menu);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, true).applyTo(infoArea);
    GridLayoutFactory.swtDefaults().applyTo(infoArea);
    Label messageLabel = new Label(infoArea, SWT.WRAP);
    messageLabel.setText(UIText.RepositoriesView_messsageEmpty);
    messageLabel.setMenu(menu);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(messageLabel);
    Composite optionsArea = new Composite(infoArea, SWT.NONE);
    optionsArea.setMenu(menu);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(optionsArea);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, true).applyTo(optionsArea);
    final FormToolkit toolkit = new FormToolkit(emptyArea.getDisplay());
    emptyArea.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            toolkit.dispose();
        }
    });
    final Color linkColor = JFaceColors.getHyperlinkText(emptyArea.getDisplay());
    Label addLabel = new Label(optionsArea, SWT.NONE);
    Image addImage = UIIcons.NEW_REPOSITORY.createImage();
    UIUtils.hookDisposal(addLabel, addImage);
    addLabel.setImage(addImage);
    Hyperlink addLink = toolkit.createHyperlink(optionsArea, UIText.RepositoriesView_linkAdd, SWT.WRAP);
    addLink.setForeground(linkColor);
    addLink.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent e) {
            IHandlerService service = CommonUtils.getService(getViewSite(), IHandlerService.class);
            UIUtils.executeCommand(service, // $NON-NLS-1$
            "org.eclipse.egit.ui.RepositoriesViewAddRepository");
        }
    });
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(addLink);
    Label cloneLabel = new Label(optionsArea, SWT.NONE);
    Image cloneImage = UIIcons.CLONEGIT.createImage();
    UIUtils.hookDisposal(cloneLabel, cloneImage);
    cloneLabel.setImage(cloneImage);
    Hyperlink cloneLink = toolkit.createHyperlink(optionsArea, UIText.RepositoriesView_linkClone, SWT.WRAP);
    cloneLink.setForeground(linkColor);
    cloneLink.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent e) {
            IHandlerService service = CommonUtils.getService(getViewSite(), IHandlerService.class);
            UIUtils.executeCommand(service, // $NON-NLS-1$
            "org.eclipse.egit.ui.RepositoriesViewClone");
        }
    });
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(cloneLink);
    Label createLabel = new Label(optionsArea, SWT.NONE);
    Image createImage = UIIcons.CREATE_REPOSITORY.createImage();
    UIUtils.hookDisposal(createLabel, createImage);
    createLabel.setImage(createImage);
    Hyperlink createLink = toolkit.createHyperlink(optionsArea, UIText.RepositoriesView_linkCreate, SWT.WRAP);
    createLink.setForeground(linkColor);
    createLink.setText(UIText.RepositoriesView_linkCreate);
    createLink.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent e) {
            IHandlerService service = CommonUtils.getService(getViewSite(), IHandlerService.class);
            UIUtils.executeCommand(service, // $NON-NLS-1$
            "org.eclipse.egit.ui.RepositoriesViewCreateRepository");
        }
    });
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(createLink);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Composite(org.eclipse.swt.widgets.Composite) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.swt.widgets.Label) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Image(org.eclipse.swt.graphics.Image) IMenuListener(org.eclipse.jface.action.IMenuListener) IHandlerService(org.eclipse.ui.handlers.IHandlerService) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 98 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project mylyn.docs by eclipse.

the class MarkupEditor method setAction.

@Override
public void setAction(String actionID, IAction action) {
    if (action != null && action.getActionDefinitionId() != null && !isCommandAction(action)) {
        // bug 336679: don't activate handlers for CommandAction.
        // We do this by class name so that we don't rely on internals
        IHandlerService handlerService = getSite().getService(IHandlerService.class);
        handlerService.activateHandler(action.getActionDefinitionId(), new ActionHandler(action));
    }
    super.setAction(actionID, action);
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 99 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project ecf by eclipse.

the class DiscoveryView method createPartControl.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
	 * .Composite)
	 */
public void createPartControl(Composite parent) {
    ComposedAdapterFactory adapterFactory = DiscoveryEditingDomainProvider.eINSTANCE.getAdapterFactory();
    // create the viewer
    setSelectionViewer(new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL));
    getSelectionViewer().setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
    getSelectionViewer().setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
    getSelectionViewer().setComparator(new ViewerComparator());
    getSelectionViewer().setFilters(getViewerFilters());
    getSelectionViewer().setUseHashlookup(true);
    getSite().setSelectionProvider(getSelectionViewer());
    // populate the viewer with the model if available
    EList resources = DiscoveryEditingDomainProvider.eINSTANCE.getEditingDomain().getResourceSet().getResources();
    if (resources != null) {
        getSelectionViewer().setInput(resources.get(0));
        getSelectionViewer().setSelection(new StructuredSelection(resources.get(0)), true);
    }
    new AdapterFactoryTreeEditor(getSelectionViewer().getTree(), adapterFactory);
    getSelectionViewer().addPostSelectionChangedListener(new AdapterFactoryStatuslineProvider(adapterFactory, getViewSite().getActionBars().getStatusLineManager()));
    drillDownAdapter = new DrillDownAdapter(getSelectionViewer());
    createContextMenuFor(getSelectionViewer());
    hookContextMenu();
    contributeToActionBars();
    // add collapse handler
    IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
    collapseHandler = new CollapseAllHandler(getSelectionViewer());
    handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, collapseHandler);
    // add DND support
    Transfer[] supportedTransfers = { LocalSelectionTransfer.getTransfer() };
    getSelectionViewer().addDragSupport(DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_MOVE, supportedTransfers, new DragSourceAdapter() {

        public void dragSetData(DragSourceEvent event) {
            LocalSelectionTransfer.getTransfer().setSelection(getSelectionViewer().getSelection());
        }
    });
    // $NON-NLS-1$
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, "org.eclipse.ecf.discovery.ui.ServiceView");
    getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
}
Also used : AdapterFactoryTreeEditor(org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) AdapterFactoryContentProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider) CollapseAllHandler(org.eclipse.ui.handlers.CollapseAllHandler) AdapterFactoryStatuslineProvider(org.eclipse.ecf.internal.discovery.ui.statusline.AdapterFactoryStatuslineProvider) EList(org.eclipse.emf.common.util.EList) IHandlerService(org.eclipse.ui.handlers.IHandlerService) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer)

Example 100 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project dbeaver by serge-rider.

the class CheckForUpdateAction method deactivateStandardHandler.

public static void deactivateStandardHandler(IWorkbenchWindow window) {
    if (p2UpdateHandlerActivation != null) {
        return;
    }
    IHandlerService srv = window.getService(IHandlerService.class);
    p2UpdateHandlerActivation = srv.activateHandler(CheckForUpdateAction.P2_UPDATE_COMMAND, new AbstractHandler() {

        @Override
        public Object execute(ExecutionEvent event) throws ExecutionException {
            new CheckForUpdateAction().run();
            return null;
        }
    });
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) AbstractHandler(org.eclipse.core.commands.AbstractHandler)

Aggregations

IHandlerService (org.eclipse.ui.handlers.IHandlerService)102 ActionHandler (org.eclipse.jface.commands.ActionHandler)44 Action (org.eclipse.jface.action.Action)41 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)25 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)18 Command (org.eclipse.core.commands.Command)17 ICommandService (org.eclipse.ui.commands.ICommandService)17 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)15 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 AbstractHandler (org.eclipse.core.commands.AbstractHandler)10 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)9 IHandler (org.eclipse.core.commands.IHandler)8 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)8 ArrayList (java.util.ArrayList)7 ExecutionException (org.eclipse.core.commands.ExecutionException)7 IAction (org.eclipse.jface.action.IAction)7 IContextService (org.eclipse.ui.contexts.IContextService)7