Search in sources :

Example 11 with IHandlerService

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

the class AboutBoxDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Color background = JFaceColors.getBannerBackground(parent.getDisplay());
    // Color foreground = JFaceColors.getBannerForeground(parent.getDisplay());
    parent.setBackground(background);
    Composite group = new Composite(parent, SWT.NONE);
    group.setBackground(background);
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 20;
    layout.marginWidth = 20;
    group.setLayout(layout);
    GridData gd;
    IProduct product = Platform.getProduct();
    {
        Label nameLabel = new Label(group, SWT.NONE);
        nameLabel.setBackground(background);
        nameLabel.setFont(NAME_FONT);
        nameLabel.setText(product.getName());
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalAlignment = GridData.CENTER;
        nameLabel.setLayoutData(gd);
    }
    Label titleLabel = new Label(group, SWT.NONE);
    titleLabel.setBackground(background);
    titleLabel.setFont(TITLE_FONT);
    titleLabel.setText(product.getProperty(PRODUCT_PROP_SUB_TITLE));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.CENTER;
    titleLabel.setLayoutData(gd);
    titleLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                @Override
                public void run() {
                    // Do not create InstallationDialog directly
                    // but execute "org.eclipse.ui.help.installationDialog" command
                    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                    IHandlerService service = workbenchWindow.getService(IHandlerService.class);
                    if (service != null) {
                        try {
                            // $NON-NLS-1$
                            service.executeCommand("org.eclipse.ui.help.installationDialog", null);
                        } catch (Exception e1) {
                        // just ignore error
                        }
                    }
                }
            });
        }
    });
    Label imageLabel = new Label(group, SWT.NONE);
    imageLabel.setBackground(background);
    gd = new GridData();
    gd.verticalAlignment = GridData.BEGINNING;
    gd.horizontalAlignment = GridData.CENTER;
    gd.grabExcessHorizontalSpace = false;
    imageLabel.setLayoutData(gd);
    imageLabel.setImage(ABOUT_IMAGE);
    Label versionLabel = new Label(group, SWT.NONE);
    versionLabel.setBackground(background);
    versionLabel.setText(CoreMessages.dialog_about_label_version + GeneralUtils.getProductVersion().toString());
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.CENTER;
    versionLabel.setLayoutData(gd);
    Label releaseTimeLabel = new Label(group, SWT.NONE);
    releaseTimeLabel.setBackground(background);
    releaseTimeLabel.setText(DateFormat.getDateInstance(DateFormat.LONG).format(GeneralUtils.getProductReleaseDate()));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.CENTER;
    releaseTimeLabel.setLayoutData(gd);
    Label authorLabel = new Label(group, SWT.NONE);
    authorLabel.setBackground(background);
    authorLabel.setText(product.getProperty(PRODUCT_PROP_COPYRIGHT));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.CENTER;
    authorLabel.setLayoutData(gd);
    Link siteLink = UIUtils.createLink(group, UIUtils.makeAnchor(product.getProperty(PRODUCT_PROP_WEBSITE)), new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            UIUtils.launchProgram(e.text);
        }
    });
    siteLink.setBackground(background);
    gd = new GridData();
    gd.horizontalAlignment = GridData.CENTER;
    siteLink.setLayoutData(gd);
    return parent;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MouseEvent(org.eclipse.swt.events.MouseEvent) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) IHandlerService(org.eclipse.ui.handlers.IHandlerService) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IProduct(org.eclipse.core.runtime.IProduct)

Example 12 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project core by jcryptool.

the class ShowEditorsPulldownMenuAction method run.

/**
 * Rhe implementation of the on click action.
 */
public void run(IAction action) {
    // connects to the extension point
    // $NON-NLS-1$
    IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint("org.jcryptool.core.editorButton");
    IExtension extension = point.getExtensions()[0];
    IConfigurationElement element = extension.getConfigurationElements()[0];
    final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
    IEvaluationContext evaluationContext = handlerService.createContextSnapshot(true);
    ExecutionEvent event = new ExecutionEvent(null, Collections.EMPTY_MAP, null, evaluationContext);
    try {
        // runs the defined action
        // $NON-NLS-1$
        IHandler handler = (IHandler) element.createExecutableExtension("OnClickClass");
        handler.execute(event);
    } catch (CoreException ex) {
        LogUtil.logError(CorePlugin.PLUGIN_ID, ex);
    } catch (ExecutionException ex) {
        LogUtil.logError(CorePlugin.PLUGIN_ID, ex);
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IHandlerService(org.eclipse.ui.handlers.IHandlerService) CoreException(org.eclipse.core.runtime.CoreException) IExtension(org.eclipse.core.runtime.IExtension) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IHandler(org.eclipse.core.commands.IHandler) ExecutionException(org.eclipse.core.commands.ExecutionException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 13 with IHandlerService

use of org.eclipse.ui.handlers.IHandlerService in project org.csstudio.display.builder by kasemir.

the class SearchView method configureActions.

/**
 * React to selections, button presses, ...
 */
private void configureActions() {
    // Start a channel search
    search.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            searchForChannels();
        }
    });
    // Channel Table: Allow dragging of PVs with archive
    final Table table = channel_table.getTable();
    new ControlSystemDragSource(table) {

        @Override
        public Object getSelection() {
            final IStructuredSelection selection = (IStructuredSelection) channel_table.getSelection();
            // To allow transfer of array, the data must be
            // of the actual array type, not Object[]
            final Object[] objs = selection.toArray();
            final ChannelInfo[] channels = Arrays.copyOf(objs, objs.length, ChannelInfo[].class);
            return channels;
        }
    };
    // Double-clicks should have the same effect as context menu -> Data Browser
    getSite().setSelectionProvider(channel_table);
    channel_table.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            // casting is needed for RAP
            IHandlerService handlerService = getSite().getService(IHandlerService.class);
            try {
                handlerService.executeCommand("org.csstudio.trends.databrowser3.OpenDataBrowserPopup", null);
            } catch (CommandException ex) {
                // $NON-NLS-1$
                Activator.getLogger().log(Level.WARNING, "Failed to open data browser", ex);
            }
        }
    });
    // Add context menu for object contributions
    final MenuManager menu = new MenuManager();
    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    table.setMenu(menu.createContextMenu(table));
    getSite().registerContextMenu(menu, channel_table);
}
Also used : Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CommandException(org.eclipse.core.commands.common.CommandException) ControlSystemDragSource(org.csstudio.ui.util.dnd.ControlSystemDragSource) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuManager(org.eclipse.jface.action.MenuManager) Separator(org.eclipse.jface.action.Separator)

Example 14 with IHandlerService

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

the class MarkupEditorOutline method configureActionBars.

private void configureActionBars(IPageSite site) {
    IActionBars actionBars = site.getActionBars();
    IToolBarManager toolBarManager = actionBars.getToolBarManager();
    IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
    CollapseAllAction collapseAllAction = new CollapseAllAction(getTreeViewer());
    toolBarManager.add(collapseAllAction);
    handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, new ActionHandler(collapseAllAction));
    actionBars.updateActionBars();
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ActionHandler(org.eclipse.jface.commands.ActionHandler) IActionBars(org.eclipse.ui.IActionBars)

Example 15 with IHandlerService

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

the class CommonUtils method runCommand.

/**
 * Programatically run command based on it id and given selection
 *
 * @param commandId
 *            id of command that should be run
 * @param selection
 *            given selection
 * @return {@code true} when command was successfully executed,
 *         {@code false} otherwise
 */
public static boolean runCommand(String commandId, IStructuredSelection selection) {
    ICommandService commandService = CommonUtils.getService(PlatformUI.getWorkbench(), ICommandService.class);
    Command cmd = commandService.getCommand(commandId);
    if (!cmd.isDefined())
        return false;
    IHandlerService handlerService = CommonUtils.getService(PlatformUI.getWorkbench(), IHandlerService.class);
    EvaluationContext c = null;
    if (selection != null) {
        c = new EvaluationContext(handlerService.createContextSnapshot(false), selection.toList());
        c.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
        c.removeVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
    }
    try {
        if (c != null)
            handlerService.executeCommandInContext(new ParameterizedCommand(cmd, null), null, c);
        else
            handlerService.executeCommand(commandId, null);
        return true;
    } catch (CommandException ignored) {
    // Ignored
    }
    return false;
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) CommandException(org.eclipse.core.commands.common.CommandException) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService)

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