Search in sources :

Example 1 with ICommandImageService

use of org.eclipse.ui.commands.ICommandImageService in project jbosstools-base by jbosstools.

the class ModelImages method createImageDescriptor.

public ImageDescriptor createImageDescriptor(String key) {
    if (key.startsWith("command:")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        key = key.substring("command:".length());
        IWorkbench w = ModelPlugin.getDefault().getWorkbench();
        ICommandImageService s = (ICommandImageService) w.getService(ICommandImageService.class);
        return s.getImageDescriptor(key);
    }
    URL url = baseUrl;
    if (key.startsWith("plugin:")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        key = key.substring("plugin:".length());
        // $NON-NLS-1$
        int i = key.indexOf(":");
        String plugin = key.substring(0, i);
        key = key.substring(i + 1);
        Bundle bundle = Platform.getBundle(plugin);
        if (bundle != null) {
            url = bundle.getEntry(XModelObjectConstants.SEPARATOR);
        }
    }
    try {
        return ImageDescriptor.createFromURL(makeIconFileURL(url, key));
    } catch (MalformedURLException e) {
        return ImageDescriptor.getMissingImageDescriptor();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) MalformedURLException(java.net.MalformedURLException) Bundle(org.osgi.framework.Bundle) ICommandImageService(org.eclipse.ui.commands.ICommandImageService) URL(java.net.URL)

Example 2 with ICommandImageService

use of org.eclipse.ui.commands.ICommandImageService in project jmc by openjdk.

the class ActionToolkit method convertToCommandAction.

public static void convertToCommandAction(IAction a, String commandId) {
    try {
        a.setActionDefinitionId(commandId);
        IServiceLocator sl = PlatformUI.getWorkbench();
        ICommandImageService is = sl.getService(ICommandImageService.class);
        ICommandService cs = sl.getService(ICommandService.class);
        Command command = cs.getCommand(commandId);
        a.setText(command.getName());
        a.setDescription(command.getDescription());
        a.setImageDescriptor(is.getImageDescriptor(commandId, ICommandImageService.TYPE_DEFAULT));
        a.setDisabledImageDescriptor(is.getImageDescriptor(commandId, ICommandImageService.TYPE_DISABLED));
        a.setHoverImageDescriptor(is.getImageDescriptor(commandId, ICommandImageService.TYPE_HOVER));
    } catch (RuntimeException e) {
        a.setText(commandId);
        // $NON-NLS-1$
        UIPlugin.getDefault().getLogger().log(Level.SEVERE, "Could not create CommandAction for " + commandId, e);
    } catch (NotDefinedException e) {
        a.setText(commandId);
        // $NON-NLS-1$
        UIPlugin.getDefault().getLogger().log(Level.SEVERE, commandId + " not defined", e);
    }
}
Also used : Command(org.eclipse.core.commands.Command) IServiceLocator(org.eclipse.ui.services.IServiceLocator) ICommandImageService(org.eclipse.ui.commands.ICommandImageService) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 3 with ICommandImageService

use of org.eclipse.ui.commands.ICommandImageService in project eclipse.platform.ui by eclipse-platform.

the class CommandLegacyActionWrapper method getHoverImageDescriptor.

@Override
public ImageDescriptor getHoverImageDescriptor() {
    final String commandId = getActionDefinitionId();
    final ICommandImageService commandImageService = serviceLocator.getService(ICommandImageService.class);
    return commandImageService.getImageDescriptor(commandId, CommandImageManager.TYPE_HOVER, style);
}
Also used : ICommandImageService(org.eclipse.ui.commands.ICommandImageService)

Example 4 with ICommandImageService

use of org.eclipse.ui.commands.ICommandImageService in project eclipse.platform.ui by eclipse-platform.

the class CommandLegacyActionWrapper method getImageDescriptor.

@Override
public ImageDescriptor getImageDescriptor() {
    final String commandId = getActionDefinitionId();
    final ICommandImageService commandImageService = serviceLocator.getService(ICommandImageService.class);
    return commandImageService.getImageDescriptor(commandId, style);
}
Also used : ICommandImageService(org.eclipse.ui.commands.ICommandImageService)

Example 5 with ICommandImageService

use of org.eclipse.ui.commands.ICommandImageService in project eclipse.platform.ui by eclipse-platform.

the class CommandLegacyActionWrapper method setHoverImageDescriptor.

@Override
public void setHoverImageDescriptor(final ImageDescriptor newImage) {
    final String commandId = getActionDefinitionId();
    final int type = CommandImageManager.TYPE_HOVER;
    final ICommandImageService commandImageService = serviceLocator.getService(ICommandImageService.class);
    if (commandImageService instanceof CommandImageService) {
        ((CommandImageService) commandImageService).bind(commandId, type, style, newImage);
    }
}
Also used : ICommandImageService(org.eclipse.ui.commands.ICommandImageService) CommandImageService(org.eclipse.ui.internal.commands.CommandImageService) ICommandImageService(org.eclipse.ui.commands.ICommandImageService)

Aggregations

ICommandImageService (org.eclipse.ui.commands.ICommandImageService)16 CommandImageService (org.eclipse.ui.internal.commands.CommandImageService)5 MCommand (org.eclipse.e4.ui.model.application.commands.MCommand)3 MParameter (org.eclipse.e4.ui.model.application.commands.MParameter)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 Map (java.util.Map)2 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)2 MHandledMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem)2 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)2 ICommandService (org.eclipse.ui.commands.ICommandService)2 ArrayList (java.util.ArrayList)1 Command (org.eclipse.core.commands.Command)1 ExpressionContext (org.eclipse.e4.core.commands.ExpressionContext)1 MApplication (org.eclipse.e4.ui.model.application.MApplication)1 MHandledToolItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem)1 MMenuContribution (org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution)1 MMenuElement (org.eclipse.e4.ui.model.application.ui.menu.MMenuElement)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1