KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
14
15 import org.eclipse.ui.internal.util.Util;
16
17 /**
18  * An instance of this class describes changes to an instance of
19  * <code>IHandler</code>.
20  * <p>
21  * This class is not intended to be extended by clients.
22  * </p>
23  *
24  * @since 3.0
25  * @see IHandlerListener#handlerChanged(HandlerEvent)
26  * @deprecated Please use the "org.eclipse.core.commands" plug-in instead.
27  */

28 public final class HandlerEvent {
29
30     /**
31      * Whether the attributes of the handler changed.
32      */

33     private final boolean attributeValuesByNameChanged;
34
35     /**
36      * The handler that changed; this value is never <code>null</code>.
37      */

38     private final IHandler handler;
39
40     /**
41      * This is the cached result of getPreviousAttributeValuesByName. It is
42      * computed the first time getPreviousAttributeValuesByName is called.
43      */

44     private Map JavaDoc previousAttributeValuesByName;
45
46     /**
47      * The map of previous attributes, if they changed. If they did not change,
48      * then this value is <code>null</code>. The map's keys are the attribute
49      * names (strings), and its value are any object.
50      *
51      * This is the original map passed into the constructor. This object always
52      * returns a copy of this map, not the original. However the constructor of
53      * this object is called very frequently and the map is rarely requested,
54      * so we only copy the map the first time it is requested.
55      *
56      * @since 3.1
57      */

58     private final Map JavaDoc originalPreviousAttributeValuesByName;
59     
60     /**
61      * Creates a new instance of this class.
62      *
63      * @param handler
64      * the instance of the interface that changed.
65      * @param attributeValuesByNameChanged
66      * true, iff the attributeValuesByName property changed.
67      * @param previousAttributeValuesByName
68      * the map of previous attribute values by name. This map may be
69      * empty. If this map is not empty, it's collection of keys must
70      * only contain instances of <code>String</code>. This map
71      * must be <code>null</code> if attributeValuesByNameChanged is
72      * <code>false</code> and must not be null if
73      * attributeValuesByNameChanged is <code>true</code>.
74      */

75     public HandlerEvent(IHandler handler, boolean attributeValuesByNameChanged,
76             Map JavaDoc previousAttributeValuesByName) {
77         if (handler == null) {
78             throw new NullPointerException JavaDoc();
79         }
80
81         if (!attributeValuesByNameChanged
82                 && previousAttributeValuesByName != null) {
83             throw new IllegalArgumentException JavaDoc();
84         }
85
86         if (attributeValuesByNameChanged) {
87             this.originalPreviousAttributeValuesByName = previousAttributeValuesByName;
88         } else {
89             this.originalPreviousAttributeValuesByName = null;
90         }
91
92         this.handler = handler;
93         this.attributeValuesByNameChanged = attributeValuesByNameChanged;
94     }
95
96     /**
97      * Returns the instance of the interface that changed.
98      *
99      * @return the instance of the interface that changed. Guaranteed not to be
100      * <code>null</code>.
101      */

102     public IHandler getHandler() {
103         return handler;
104     }
105
106     /**
107      * Returns the map of previous attribute values by name.
108      *
109      * @return the map of previous attribute values by name. This map may be
110      * empty. If this map is not empty, it's collection of keys is
111      * guaranteed to only contain instances of <code>String</code>.
112      * This map is guaranteed to be <code>null</code> if
113      * haveAttributeValuesByNameChanged() is <code>false</code> and is
114      * guaranteed to not be null if haveAttributeValuesByNameChanged()
115      * is <code>true</code>.
116      */

117     public Map JavaDoc getPreviousAttributeValuesByName() {
118         if (originalPreviousAttributeValuesByName == null) {
119             return null;
120         }
121         
122         if (previousAttributeValuesByName == null) {
123             previousAttributeValuesByName = Util.safeCopy(
124                     originalPreviousAttributeValuesByName, String JavaDoc.class, Object JavaDoc.class,
125                     false, true);
126         }
127         
128         return previousAttributeValuesByName;
129     }
130
131     /**
132      * Returns whether or not the attributeValuesByName property changed.
133      *
134      * @return true, iff the attributeValuesByName property changed.
135      */

136     public boolean haveAttributeValuesByNameChanged() {
137         return attributeValuesByNameChanged;
138     }
139 }
140
Popular Tags