KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > commands > CommandImageService


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.commands;
12
13 import java.net.URL JavaDoc;
14
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.ui.commands.ICommandService;
17
18 /**
19  * <p>
20  * Provides services related to the command architecture within the workbench.
21  * This service can be used to access the set of commands and handlers.
22  * </p>
23  *
24  * @since 3.2
25  */

26 public final class CommandImageService implements ICommandImageService {
27
28     /**
29      * The command image manager that supports this service. This value is never
30      * <code>null</code>.
31      */

32     private final CommandImageManager commandImageManager;
33
34     /**
35      * The class providing persistence for this service.
36      */

37     private final CommandImagePersistence commandImagePersistence;
38
39     /**
40      * Constructs a new instance of <code>CommandService</code> using a
41      * command image manager.
42      *
43      * @param commandImageManager
44      * The command image manager to use; must not be
45      * <code>null</code>.
46      * @param commandService
47      * The workbench command service; must not be <code>null</code>.
48      * This is used for checking whether a command is defined when
49      * reading the registry.
50      */

51     public CommandImageService(final CommandImageManager commandImageManager,
52             final ICommandService commandService) {
53         if (commandImageManager == null) {
54             throw new NullPointerException JavaDoc(
55                     "Cannot create a command image service with a null manager"); //$NON-NLS-1$
56
}
57         if (commandService == null) {
58             throw new NullPointerException JavaDoc(
59                     "Cannot create a command image service with a null command service"); //$NON-NLS-1$
60
}
61         this.commandImageManager = commandImageManager;
62         this.commandImagePersistence = new CommandImagePersistence(
63                 commandImageManager, commandService);
64     }
65
66     public final void bind(final String JavaDoc commandId, final int type,
67             final String JavaDoc style, final ImageDescriptor descriptor) {
68         commandImageManager.bind(commandId, type, style, descriptor);
69     }
70
71     public final void bind(final String JavaDoc commandId, final int type,
72             final String JavaDoc style, final URL JavaDoc url) {
73         commandImageManager.bind(commandId, type, style, url);
74     }
75
76     public final void dispose() {
77         commandImagePersistence.dispose();
78     }
79
80     public final String JavaDoc generateUnusedStyle(final String JavaDoc commandId) {
81         return commandImageManager.generateUnusedStyle(commandId);
82     }
83
84     public final ImageDescriptor getImageDescriptor(final String JavaDoc commandId) {
85         return commandImageManager.getImageDescriptor(commandId);
86     }
87
88     public final ImageDescriptor getImageDescriptor(final String JavaDoc commandId,
89             final int type) {
90         return commandImageManager.getImageDescriptor(commandId, type);
91     }
92
93     public final ImageDescriptor getImageDescriptor(final String JavaDoc commandId,
94             final int type, final String JavaDoc style) {
95         return commandImageManager.getImageDescriptor(commandId, type, style);
96     }
97
98     public final ImageDescriptor getImageDescriptor(final String JavaDoc commandId,
99             final String JavaDoc style) {
100         return commandImageManager.getImageDescriptor(commandId, style);
101     }
102
103     public final void readRegistry() {
104         commandImagePersistence.read();
105     }
106 }
107
Popular Tags