KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > commands > CommandEvent


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.commands;
12
13 import java.util.Collections JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.ui.internal.util.Util;
17
18 /**
19  * An instance of this class describes changes to an instance of
20  * <code>ICommand</code>.
21  * <p>
22  * This class is not intended to be extended by clients.
23  * </p>
24  *
25  * @since 3.0
26  * @see ICommandListener#commandChanged(CommandEvent)
27  * @deprecated Please use the "org.eclipse.core.commands" plug-in instead.
28  * @see org.eclipse.core.commands.CommandEvent
29  */

30 public final class CommandEvent {
31
32     /**
33      * Whether the attributes of the command have changed. These are name and
34      * value pairs representing properties of the command.
35      */

36     private final boolean attributeValuesByNameChanged;
37
38     /**
39      * Whether the category identifier has changed.
40      */

41     private final boolean categoryIdChanged;
42
43     /**
44      * The command that has changed; this value is never <code>null</code>.
45      */

46     private final ICommand command;
47
48     /**
49      * Whether the defined state of the command has changed.
50      */

51     private final boolean definedChanged;
52
53     /**
54      * Whether the description of the command has changed.
55      */

56     private final boolean descriptionChanged;
57
58     /**
59      * Whether the command has either gained or lost a handler.
60      */

61     private final boolean handledChanged;
62
63     /**
64      * Whether the key bindings for the command have changed.
65      */

66     private final boolean keySequenceBindingsChanged;
67
68     /**
69      * Whether the name of the command has changed.
70      */

71     private final boolean nameChanged;
72
73     /**
74      * The map of attributes before the change. This is a map of attribute name
75      * (strings) to values (any object).
76      */

77     private Map JavaDoc previousAttributeValuesByName;
78
79     /**
80      * Creates a new instance of this class.
81      *
82      * @param command
83      * the instance of the interface that changed.
84      * @param attributeValuesByNameChanged
85      * true, iff the attributeValuesByName property changed.
86      * @param categoryIdChanged
87      * true, iff the categoryId property changed.
88      * @param definedChanged
89      * true, iff the defined property changed.
90      * @param descriptionChanged
91      * true, iff the description property changed.
92      * @param handledChanged
93      * true, iff the handled property changed.
94      * @param keySequenceBindingsChanged
95      * true, iff the keySequenceBindings property changed.
96      * @param nameChanged
97      * true, iff the name property changed.
98      * @param previousAttributeValuesByName
99      * the map of previous attribute values by name. This map may be
100      * empty. If this map is not empty, it's collection of keys must
101      * only contain instances of <code>String</code>. This map
102      * must be <code>null</code> if attributeValuesByNameChanged is
103      * <code>false</code> and must not be null if
104      * attributeValuesByNameChanged is <code>true</code>.
105      */

106     public CommandEvent(ICommand command, boolean attributeValuesByNameChanged,
107             boolean categoryIdChanged, boolean definedChanged,
108             boolean descriptionChanged, boolean handledChanged,
109             boolean keySequenceBindingsChanged, boolean nameChanged,
110             Map JavaDoc previousAttributeValuesByName) {
111         if (command == null) {
112             throw new NullPointerException JavaDoc();
113         }
114
115         if (!attributeValuesByNameChanged
116                 && previousAttributeValuesByName != null) {
117             throw new IllegalArgumentException JavaDoc();
118         }
119
120         if (attributeValuesByNameChanged) {
121             if (previousAttributeValuesByName == null) {
122                 this.previousAttributeValuesByName = Collections.EMPTY_MAP;
123             } else {
124                 this.previousAttributeValuesByName = Util.safeCopy(
125                         previousAttributeValuesByName, String JavaDoc.class,
126                         Object JavaDoc.class, false, true);
127             }
128         }
129
130         this.command = command;
131         this.attributeValuesByNameChanged = attributeValuesByNameChanged;
132         this.categoryIdChanged = categoryIdChanged;
133         this.definedChanged = definedChanged;
134         this.descriptionChanged = descriptionChanged;
135         this.handledChanged = handledChanged;
136         this.keySequenceBindingsChanged = keySequenceBindingsChanged;
137         this.nameChanged = nameChanged;
138     }
139
140     /**
141      * Returns the instance of the interface that changed.
142      *
143      * @return the instance of the interface that changed. Guaranteed not to be
144      * <code>null</code>.
145      */

146     public ICommand getCommand() {
147         return command;
148     }
149
150     /**
151      * Returns the map of previous attribute values by name.
152      *
153      * @return the map of previous attribute values by name. This map may be
154      * empty. If this map is not empty, it's collection of keys is
155      * guaranteed to only contain instances of <code>String</code>.
156      * This map is guaranteed to be <code>null</code> if
157      * haveAttributeValuesByNameChanged() is <code>false</code> and is
158      * guaranteed to not be null if haveAttributeValuesByNameChanged()
159      * is <code>true</code>.
160      */

161     public Map JavaDoc getPreviousAttributeValuesByName() {
162         return previousAttributeValuesByName;
163     }
164
165     /**
166      * Returns whether or not the categoryId property changed.
167      *
168      * @return true, iff the categoryId property changed.
169      */

170     public boolean hasCategoryIdChanged() {
171         return categoryIdChanged;
172     }
173
174     /**
175      * Returns whether or not the defined property changed.
176      *
177      * @return true, iff the defined property changed.
178      */

179     public boolean hasDefinedChanged() {
180         return definedChanged;
181     }
182
183     /**
184      * Returns whether or not the description property changed.
185      *
186      * @return true, iff the description property changed.
187      */

188     public boolean hasDescriptionChanged() {
189         return descriptionChanged;
190     }
191
192     /**
193      * Returns whether or not the handled property changed.
194      *
195      * @return true, iff the handled property changed.
196      */

197     public boolean hasHandledChanged() {
198         return handledChanged;
199     }
200
201     /**
202      * Returns whether or not the name property changed.
203      *
204      * @return true, iff the name property changed.
205      */

206     public boolean hasNameChanged() {
207         return nameChanged;
208     }
209
210     /**
211      * Returns whether or not the attributeValuesByName property changed.
212      *
213      * @return true, iff the attributeValuesByName property changed.
214      */

215     public boolean haveAttributeValuesByNameChanged() {
216         return attributeValuesByNameChanged;
217     }
218
219     /**
220      * Returns whether or not the keySequenceBindings property changed.
221      *
222      * @return true, iff the keySequenceBindings property changed.
223      */

224     public boolean haveKeySequenceBindingsChanged() {
225         return keySequenceBindingsChanged;
226     }
227 }
228
Popular Tags