KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 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 /**
14  * <p>
15  * An event indicating that the image bindings have changed.
16  * </p>
17  * <p>
18  * Clients must neither instantiate nor extend.
19  * </p>
20  * <p>
21  * <strong>PROVISIONAL</strong>. This class or interface has been added as
22  * part of a work in progress. There is a guarantee neither that this API will
23  * work nor that it will remain the same. Please do not use this API without
24  * consulting with the Platform/UI team.
25  * </p>
26  * <p>
27  * This class is eventually intended to exist in
28  * <code>org.eclipse.jface.commands</code>.
29  * </p>
30  *
31  * @since 3.2
32  * @see ICommandImageManagerListener#commandImageManagerChanged(CommandImageManagerEvent)
33  */

34 public final class CommandImageManagerEvent {
35
36     /**
37      * The identifiers of the commands whose image bindings have changed. This
38      * value is never <code>null</code> and never empty.
39      */

40     private final String JavaDoc[] changedCommandIds;
41
42     /**
43      * The command image manager that has changed. This value is never
44      * <code>null</code>.
45      */

46     private final CommandImageManager commandImageManager;
47
48     /**
49      * The style of image that changed.
50      */

51     private final String JavaDoc style;
52
53     /**
54      * The type of image that changed.
55      */

56     private final int type;
57
58     /**
59      * Creates a new instance of this class.
60      *
61      * @param commandImageManager
62      * the instance of the manager that changed; must not be
63      * <code>null</code>.
64      * @param changedCommandIds
65      * The identifiers of the commands whose image bindings have
66      * changed; this value must not be <code>null</code> and must
67      * not be empty. This value is not copied.
68      */

69     CommandImageManagerEvent(final CommandImageManager commandImageManager,
70             final String JavaDoc[] changedCommandIds, final int type, final String JavaDoc style) {
71         if (commandImageManager == null) {
72             throw new NullPointerException JavaDoc("An event must refer to its manager"); //$NON-NLS-1$
73
}
74
75         if ((changedCommandIds == null) || (changedCommandIds.length < 1)) {
76             throw new IllegalArgumentException JavaDoc(
77                     "There must be at least one change command identifier"); //$NON-NLS-1$
78
}
79
80         this.commandImageManager = commandImageManager;
81         this.changedCommandIds = changedCommandIds;
82         this.type = type;
83         this.style = style;
84     }
85
86     /**
87      * Returns the identifiers of the commands whose bindings have changed.
88      *
89      * @return The identifiers of the commands whose bindings have changed;
90      * neither <code>null</code> nor empty.
91      */

92     public final String JavaDoc[] getChangedCommandIds() {
93         final String JavaDoc[] copy = new String JavaDoc[changedCommandIds.length];
94         System.arraycopy(changedCommandIds, 0, copy, 0,
95                 changedCommandIds.length);
96         return copy;
97     }
98
99     /**
100      * Returns the instance of the interface that changed.
101      *
102      * @return the instance of the interface that changed. Guaranteed not to be
103      * <code>null</code>.
104      */

105     public final CommandImageManager getCommandImageManager() {
106         return commandImageManager;
107     }
108
109     /**
110      * Returns whether one of the images of the given command has changed.
111      *
112      * @param commandId
113      * The identifier of the command to check; must not be
114      * <code>null</code>.
115      * @return <code>true</code> if one of the command's images has changed;
116      * <code>false</code> otherwise.
117      */

118     public final boolean isCommandIdChanged(final String JavaDoc commandId) {
119         // PERFORMANCE
120
for (int i = 0; i < changedCommandIds.length; i++) {
121             if (commandId.equals(changedCommandIds[i])) {
122                 return true;
123             }
124         }
125
126         return false;
127     }
128
129     /**
130      * Returns whether the image for the command has changed.
131      *
132      * @param commandId
133      * The identifier of the command to check; must not be
134      * <code>null</code>.
135      * @return <code>true</code> if the command's image has changed
136      * @see CommandImageManager#getImageDescriptor(String)
137      */

138     public final boolean isCommandImageChanged(final String JavaDoc commandId) {
139         return isCommandIdChanged(commandId)
140                 && (type == CommandImageManager.TYPE_DEFAULT)
141                 && (style == null);
142     }
143
144     /**
145      * Returns whether the image of the given type for the command has changed.
146      *
147      * @param commandId
148      * The identifier of the command to check; must not be
149      * <code>null</code>.
150      * @param type
151      * The type of image, one of
152      * {@link CommandImageManager#TYPE_DEFAULT},
153      * {@link CommandImageManager#TYPE_DISABLED} or
154      * {@link CommandImageManager#TYPE_HOVER}.
155      * @return <code>true</code> if the command's image of the given type has
156      * changed.
157      * @see CommandImageManager#getImageDescriptor(String, int)
158      */

159     public final boolean isCommandImageChanged(final String JavaDoc commandId,
160             final int type) {
161         return isCommandIdChanged(commandId)
162                 && ((type == CommandImageManager.TYPE_DEFAULT) || (type == this.type))
163                 && (style == null);
164     }
165
166     /**
167      * Returns whether the image of the given type and style for the command has
168      * changed.
169      *
170      * @param commandId
171      * The identifier of the command to check; must not be
172      * <code>null</code>.
173      * @param type
174      * The type of image, one of
175      * {@link CommandImageManager#TYPE_DEFAULT},
176      * {@link CommandImageManager#TYPE_DISABLED} or
177      * {@link CommandImageManager#TYPE_HOVER}.
178      * @param style
179      * The style of the image; may be anything.
180      * @return <code>true</code> if the command's image of the given type and
181      * style has changed.
182      * @see CommandImageManager#getImageDescriptor(String, int, String)
183      */

184     public final boolean isCommandImageChanged(final String JavaDoc commandId,
185             final int type, final String JavaDoc style) {
186         return isCommandIdChanged(commandId)
187                 && ((type == CommandImageManager.TYPE_DEFAULT) || (type == this.type))
188                 && ((style == null) || (style.equals(this.style)));
189     }
190
191     /**
192      * Returns whether the image of the given style for the command has changed.
193      *
194      * @param commandId
195      * The identifier of the command to check; must not be
196      * <code>null</code>.
197      * @param style
198      * The style of the image; may be anything.
199      * @return <code>true</code> if the command's image of the given style has
200      * changed.
201      * @see CommandImageManager#getImageDescriptor(String, String)
202      */

203     public final boolean isCommandImageChanged(final String JavaDoc commandId,
204             final String JavaDoc style) {
205         return isCommandIdChanged(commandId)
206                 && (type == CommandImageManager.TYPE_DEFAULT)
207                 && ((style == null) || (style.equals(this.style)));
208     }
209 }
210
Popular Tags