001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.commands;
011:
012: import java.net.URL;
013:
014: import org.eclipse.jface.resource.ImageDescriptor;
015: import org.eclipse.ui.commands.ICommandService;
016:
017: /**
018: * <p>
019: * Provides services related to the command architecture within the workbench.
020: * This service can be used to access the set of commands and handlers.
021: * </p>
022: *
023: * @since 3.2
024: */
025: public final class CommandImageService implements ICommandImageService {
026:
027: /**
028: * The command image manager that supports this service. This value is never
029: * <code>null</code>.
030: */
031: private final CommandImageManager commandImageManager;
032:
033: /**
034: * The class providing persistence for this service.
035: */
036: private final CommandImagePersistence commandImagePersistence;
037:
038: /**
039: * Constructs a new instance of <code>CommandService</code> using a
040: * command image manager.
041: *
042: * @param commandImageManager
043: * The command image manager to use; must not be
044: * <code>null</code>.
045: * @param commandService
046: * The workbench command service; must not be <code>null</code>.
047: * This is used for checking whether a command is defined when
048: * reading the registry.
049: */
050: public CommandImageService(
051: final CommandImageManager commandImageManager,
052: final ICommandService commandService) {
053: if (commandImageManager == null) {
054: throw new NullPointerException(
055: "Cannot create a command image service with a null manager"); //$NON-NLS-1$
056: }
057: if (commandService == null) {
058: throw new NullPointerException(
059: "Cannot create a command image service with a null command service"); //$NON-NLS-1$
060: }
061: this .commandImageManager = commandImageManager;
062: this .commandImagePersistence = new CommandImagePersistence(
063: commandImageManager, commandService);
064: }
065:
066: public final void bind(final String commandId, final int type,
067: final String style, final ImageDescriptor descriptor) {
068: commandImageManager.bind(commandId, type, style, descriptor);
069: }
070:
071: public final void bind(final String commandId, final int type,
072: final String style, final URL url) {
073: commandImageManager.bind(commandId, type, style, url);
074: }
075:
076: public final void dispose() {
077: commandImagePersistence.dispose();
078: }
079:
080: public final String generateUnusedStyle(final String commandId) {
081: return commandImageManager.generateUnusedStyle(commandId);
082: }
083:
084: public final ImageDescriptor getImageDescriptor(
085: final String commandId) {
086: return commandImageManager.getImageDescriptor(commandId);
087: }
088:
089: public final ImageDescriptor getImageDescriptor(
090: final String commandId, final int type) {
091: return commandImageManager.getImageDescriptor(commandId, type);
092: }
093:
094: public final ImageDescriptor getImageDescriptor(
095: final String commandId, final int type, final String style) {
096: return commandImageManager.getImageDescriptor(commandId, type,
097: style);
098: }
099:
100: public final ImageDescriptor getImageDescriptor(
101: final String commandId, final String style) {
102: return commandImageManager.getImageDescriptor(commandId, style);
103: }
104:
105: public final void readRegistry() {
106: commandImagePersistence.read();
107: }
108: }
|