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.contexts;
011:
012: import org.eclipse.swt.widgets.Shell;
013: import org.eclipse.ui.IWorkbenchPartSite;
014: import org.eclipse.ui.internal.util.Util;
015:
016: /**
017: * </p>
018: * An instance of this class represents a request to enabled a context. An
019: * enabled submission specifies a list of conditions under which it would be
020: * appropriate for a particular context to be enabled. These conditions include
021: * things like the active part or the active shell. So, it is possible to say
022: * things like: "when the java editor is active, please consider enabling the
023: * 'editing java' context".
024: * </p>
025: * <p>
026: * The workbench considers all of the submissions it has received and choses the
027: * ones it views as the best possible match.
028: * </p>
029: * <p>
030: * This class is not intended to be extended by clients.
031: * </p>
032: * <p>
033: * Note: this class has a natural ordering that is inconsistent with equals.
034: * </p>
035: *
036: * @since 3.0
037: * @see IWorkbenchContextSupport
038: * @deprecated Please use <code>IContextService.activateContext</code>
039: * instead.
040: * @see org.eclipse.ui.contexts.IContextService
041: */
042: public final class EnabledSubmission implements Comparable {
043:
044: /**
045: * The identifier of the part in which this context should be enabled. If
046: * this value is <code>null</code>, this means it should be active in any
047: * part.
048: */
049: private final String activePartId;
050:
051: /**
052: * The shell in which this context should be enabled. If this value is
053: * <code>null</code>, this means it should be active in any shell.
054: */
055: private final Shell activeShell;
056:
057: /**
058: * The part site in which this context should be enabled. If this value is
059: * <code>null</code>, this means it should be active in any part site.
060: */
061: private final IWorkbenchPartSite activeWorkbenchPartSite;
062:
063: /**
064: * The identifier for the context that should be enabled by this
065: * submissions. This value should never be <code>null</code>.
066: */
067: private final String contextId;
068:
069: /**
070: * The cached string representation of this instance. This value is computed
071: * lazily on the first call to retrieve the string representation, and the
072: * cache is used for all future calls. If this value is <code>null</code>,
073: * then the value has not yet been computed.
074: */
075: private transient String string = null;
076:
077: /**
078: * Creates a new instance of this class.
079: *
080: * @param activePartId
081: * the identifier of the part that must be active for this
082: * request to be considered. May be <code>null</code>.
083: * @param activeShell
084: * the shell that must be active for this request to be
085: * considered. May be <code>null</code>.
086: * @param activeWorkbenchPartSite
087: * the workbench part site of the part that must be active for
088: * this request to be considered. May be <code>null</code>.
089: * @param contextId
090: * the identifier of the context to be enabled. Must not be
091: * <code>null</code>.
092: */
093: public EnabledSubmission(String activePartId, Shell activeShell,
094: IWorkbenchPartSite activeWorkbenchPartSite, String contextId) {
095: if (contextId == null) {
096: throw new NullPointerException();
097: }
098:
099: this .activePartId = activePartId;
100: this .activeShell = activeShell;
101: this .activeWorkbenchPartSite = activeWorkbenchPartSite;
102: this .contextId = contextId;
103: }
104:
105: /**
106: * @see Comparable#compareTo(java.lang.Object)
107: */
108: public int compareTo(Object object) {
109: EnabledSubmission castedObject = (EnabledSubmission) object;
110: int compareTo = Util.compare(activeWorkbenchPartSite,
111: castedObject.activeWorkbenchPartSite);
112:
113: if (compareTo == 0) {
114: compareTo = Util.compare(activePartId,
115: castedObject.activePartId);
116:
117: if (compareTo == 0) {
118: compareTo = Util.compare(activeShell,
119: castedObject.activeShell);
120:
121: if (compareTo == 0) {
122: compareTo = Util.compare(contextId,
123: castedObject.contextId);
124: }
125: }
126: }
127:
128: return compareTo;
129: }
130:
131: /**
132: * Returns the identifier of the part that must be active for this request
133: * to be considered.
134: *
135: * @return the identifier of the part that must be active for this request
136: * to be considered. May be <code>null</code>.
137: */
138: public String getActivePartId() {
139: return activePartId;
140: }
141:
142: /**
143: * Returns the shell that must be active for this request to be considered.
144: *
145: * @return the shell that must be active for this request to be considered.
146: * May be <code>null</code>.
147: */
148: public Shell getActiveShell() {
149: return activeShell;
150: }
151:
152: /**
153: * Returns the workbench part site of the part that must be active for this
154: * request to be considered.
155: *
156: * @return the workbench part site of the part that must be active for this
157: * request to be considered. May be <code>null</code>.
158: */
159: public IWorkbenchPartSite getActiveWorkbenchPartSite() {
160: return activeWorkbenchPartSite;
161: }
162:
163: /**
164: * Returns the identifier of the context to be enabled.
165: *
166: * @return the identifier of the context to be enabled. Guaranteed not to be
167: * <code>null</code>.
168: */
169: public String getContextId() {
170: return contextId;
171: }
172:
173: /**
174: * @see Object#toString()
175: */
176: public String toString() {
177: if (string == null) {
178: final StringBuffer stringBuffer = new StringBuffer();
179: stringBuffer.append("[activePartId="); //$NON-NLS-1$
180: stringBuffer.append(activePartId);
181: stringBuffer.append(",activeShell="); //$NON-NLS-1$
182: stringBuffer.append(activeShell);
183: stringBuffer.append(",activeWorkbenchSite="); //$NON-NLS-1$
184: stringBuffer.append(activeWorkbenchPartSite);
185: stringBuffer.append(",contextId="); //$NON-NLS-1$
186: stringBuffer.append(contextId);
187: stringBuffer.append(']');
188: string = stringBuffer.toString();
189: }
190:
191: return string;
192: }
193: }
|