001: /*******************************************************************************
002: * Copyright (c) 2003, 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.commands;
011:
012: import java.util.Collections;
013: import java.util.Map;
014:
015: import org.eclipse.ui.internal.util.Util;
016:
017: /**
018: * An instance of this class describes changes to an instance of
019: * <code>ICommand</code>.
020: * <p>
021: * This class is not intended to be extended by clients.
022: * </p>
023: *
024: * @since 3.0
025: * @see ICommandListener#commandChanged(CommandEvent)
026: * @deprecated Please use the "org.eclipse.core.commands" plug-in instead.
027: * @see org.eclipse.core.commands.CommandEvent
028: */
029: public final class CommandEvent {
030:
031: /**
032: * Whether the attributes of the command have changed. These are name and
033: * value pairs representing properties of the command.
034: */
035: private final boolean attributeValuesByNameChanged;
036:
037: /**
038: * Whether the category identifier has changed.
039: */
040: private final boolean categoryIdChanged;
041:
042: /**
043: * The command that has changed; this value is never <code>null</code>.
044: */
045: private final ICommand command;
046:
047: /**
048: * Whether the defined state of the command has changed.
049: */
050: private final boolean definedChanged;
051:
052: /**
053: * Whether the description of the command has changed.
054: */
055: private final boolean descriptionChanged;
056:
057: /**
058: * Whether the command has either gained or lost a handler.
059: */
060: private final boolean handledChanged;
061:
062: /**
063: * Whether the key bindings for the command have changed.
064: */
065: private final boolean keySequenceBindingsChanged;
066:
067: /**
068: * Whether the name of the command has changed.
069: */
070: private final boolean nameChanged;
071:
072: /**
073: * The map of attributes before the change. This is a map of attribute name
074: * (strings) to values (any object).
075: */
076: private Map previousAttributeValuesByName;
077:
078: /**
079: * Creates a new instance of this class.
080: *
081: * @param command
082: * the instance of the interface that changed.
083: * @param attributeValuesByNameChanged
084: * true, iff the attributeValuesByName property changed.
085: * @param categoryIdChanged
086: * true, iff the categoryId property changed.
087: * @param definedChanged
088: * true, iff the defined property changed.
089: * @param descriptionChanged
090: * true, iff the description property changed.
091: * @param handledChanged
092: * true, iff the handled property changed.
093: * @param keySequenceBindingsChanged
094: * true, iff the keySequenceBindings property changed.
095: * @param nameChanged
096: * true, iff the name property changed.
097: * @param previousAttributeValuesByName
098: * the map of previous attribute values by name. This map may be
099: * empty. If this map is not empty, it's collection of keys must
100: * only contain instances of <code>String</code>. This map
101: * must be <code>null</code> if attributeValuesByNameChanged is
102: * <code>false</code> and must not be null if
103: * attributeValuesByNameChanged is <code>true</code>.
104: */
105: public CommandEvent(ICommand command,
106: boolean attributeValuesByNameChanged,
107: boolean categoryIdChanged, boolean definedChanged,
108: boolean descriptionChanged, boolean handledChanged,
109: boolean keySequenceBindingsChanged, boolean nameChanged,
110: Map previousAttributeValuesByName) {
111: if (command == null) {
112: throw new NullPointerException();
113: }
114:
115: if (!attributeValuesByNameChanged
116: && previousAttributeValuesByName != null) {
117: throw new IllegalArgumentException();
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.class,
126: Object.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 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: }
|