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();
}
}
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);
}
}
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);
}
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);
}
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);
}
}
Aggregations