001: /*******************************************************************************
002: * Copyright (c) 2000, 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.contexts;
011:
012: import java.util.Set;
013:
014: import org.eclipse.ui.internal.util.Util;
015:
016: /**
017: * An instance of this class describes changes to an instance of
018: * <code>IContextManager</code>.
019: * <p>
020: * This class is not intended to be extended by clients.
021: * </p>
022: *
023: * @since 3.0
024: * @see IContextManagerListener#contextManagerChanged(ContextManagerEvent)
025: * @deprecated Please use the "org.eclipse.core.commands" plug-in instead.
026: * @see org.eclipse.core.commands.contexts.ContextManagerEvent
027: */
028: public final class ContextManagerEvent {
029:
030: /**
031: * The context manager which has changed. This value is never
032: * <code>null</code>.
033: */
034: private final IContextManager contextManager;
035:
036: /**
037: * Whether the set of defined contexts has changed.
038: */
039: private final boolean definedContextIdsChanged;
040:
041: /**
042: * Whether the set of enabled contexts has changed.
043: */
044: private final boolean enabledContextIdsChanged;
045:
046: /**
047: * The set of context identifiers (strings) that were defined before the
048: * change occurred. If the defined contexts did not changed, then this value
049: * is <code>null</code>.
050: */
051: private final Set previouslyDefinedContextIds;
052:
053: /**
054: * The set of context identifiers (strings) that were enabled before the
055: * change occurred. If the enabled contexts did not changed, then this value
056: * is <code>null</code>.
057: */
058: private final Set previouslyEnabledContextIds;
059:
060: /**
061: * Creates a new instance of this class.
062: *
063: * @param contextManager
064: * the instance of the interface that changed.
065: * @param definedContextIdsChanged
066: * true, iff the definedContextIds property changed.
067: * @param enabledContextIdsChanged
068: * true, iff the enabledContextIds property changed.
069: * @param previouslyDefinedContextIds
070: * the set of identifiers to previously defined contexts. This
071: * set may be empty. If this set is not empty, it must only
072: * contain instances of <code>String</code>. This set must be
073: * <code>null</code> if definedContextIdsChanged is
074: * <code>false</code> and must not be null if
075: * definedContextIdsChanged is <code>true</code>.
076: * @param previouslyEnabledContextIds
077: * the set of identifiers to previously enabled contexts. This
078: * set may be empty. If this set is not empty, it must only
079: * contain instances of <code>String</code>. This set must be
080: * <code>null</code> if enabledContextIdsChanged is
081: * <code>false</code> and must not be null if
082: * enabledContextIdsChanged is <code>true</code>.
083: */
084: public ContextManagerEvent(IContextManager contextManager,
085: boolean definedContextIdsChanged,
086: boolean enabledContextIdsChanged,
087: Set previouslyDefinedContextIds,
088: Set previouslyEnabledContextIds) {
089: if (contextManager == null) {
090: throw new NullPointerException();
091: }
092:
093: if (!definedContextIdsChanged
094: && previouslyDefinedContextIds != null) {
095: throw new IllegalArgumentException();
096: }
097:
098: if (!enabledContextIdsChanged
099: && previouslyEnabledContextIds != null) {
100: throw new IllegalArgumentException();
101: }
102:
103: if (definedContextIdsChanged) {
104: this .previouslyDefinedContextIds = Util.safeCopy(
105: previouslyDefinedContextIds, String.class);
106: } else {
107: this .previouslyDefinedContextIds = null;
108: }
109:
110: if (enabledContextIdsChanged) {
111: this .previouslyEnabledContextIds = Util.safeCopy(
112: previouslyEnabledContextIds, String.class);
113: } else {
114: this .previouslyEnabledContextIds = null;
115: }
116:
117: this .contextManager = contextManager;
118: this .definedContextIdsChanged = definedContextIdsChanged;
119: this .enabledContextIdsChanged = enabledContextIdsChanged;
120: }
121:
122: /**
123: * Returns the instance of the interface that changed.
124: *
125: * @return the instance of the interface that changed. Guaranteed not to be
126: * <code>null</code>.
127: */
128: public IContextManager getContextManager() {
129: return contextManager;
130: }
131:
132: /**
133: * Returns the set of identifiers to previously defined contexts.
134: *
135: * @return the set of identifiers to previously defined contexts. This set
136: * may be empty. If this set is not empty, it is guaranteed to only
137: * contain instances of <code>String</code>. This set is
138: * guaranteed to be <code>null</code> if
139: * haveDefinedContextIdsChanged() is <code>false</code> and is
140: * guaranteed to not be null if haveDefinedContextIdsChanged() is
141: * <code>true</code>.
142: */
143: public Set getPreviouslyDefinedContextIds() {
144: return previouslyDefinedContextIds;
145: }
146:
147: /**
148: * Returns the set of identifiers to previously enabled contexts.
149: *
150: * @return the set of identifiers to previously enabled contexts. This set
151: * may be empty. If this set is not empty, it is guaranteed to only
152: * contain instances of <code>String</code>. This set is
153: * guaranteed to be <code>null</code> if
154: * haveEnabledContextIdsChanged() is <code>false</code> and is
155: * guaranteed to not be null if haveEnabledContextIdsChanged() is
156: * <code>true</code>.
157: */
158: public Set getPreviouslyEnabledContextIds() {
159: return previouslyEnabledContextIds;
160: }
161:
162: /**
163: * Returns whether or not the definedContextIds property changed.
164: *
165: * @return true, iff the definedContextIds property changed.
166: */
167: public boolean haveDefinedContextIdsChanged() {
168: return definedContextIdsChanged;
169: }
170:
171: /**
172: * Returns whether or not the enabledContextIds property changed.
173: *
174: * @return true, iff the enabledContextIds property changed.
175: */
176: public boolean haveEnabledContextIdsChanged() {
177: return enabledContextIdsChanged;
178: }
179: }
|