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 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 handle a command. A handler
019: * submission specifies a list of conditions under which it would be appropriate
020: * for a particular command to have a particular handler. These conditions
021: * include things like the active part or the active shell. So, it is possible
022: * to say things like: "when my part is active, please consider calling these
023: * classes when you want to perform a cut, copy or paste".
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 org.eclipse.ui.commands.IWorkbenchCommandSupport
038: * @deprecated Please use <code>IHandlerService.activateHandler</code>
039: * instead.
040: * @see org.eclipse.ui.handlers.IHandlerService
041: */
042: public final class HandlerSubmission implements Comparable {
043:
044: /**
045: * The part identifier for the part that should be active before this
046: * submission can be considered. This value can be <code>null</code>, which
047: * indicates that it should match any part.
048: */
049: private final String activePartId;
050:
051: /**
052: * The shell that must be active before this submission can be considered.
053: * This value can be <code>null</code>, which indicates that it should match
054: * any shell.
055: */
056: private final Shell activeShell;
057:
058: /**
059: * The workbench site that must be active before this submission can be
060: * considered. This value can be <code>null</code>, which indicates that it
061: * should match an workbench part site.
062: */
063: private final IWorkbenchPartSite activeWorkbenchPartSite;
064:
065: /**
066: * The identifier for the command which the submitted handler handles. This
067: * value cannot be <code>null</code>.
068: */
069: private final String commandId;
070:
071: /**
072: * The handler being submitted. This value cannot be <code>null</code>.
073: */
074: private final IHandler handler;
075:
076: /**
077: * The priority for this submission. In the event of all other factors
078: * being equal, the priority will be considered in an attempt to resolve
079: * conflicts. This value cannot be <code>null</code>.
080: */
081: private final Priority priority;
082:
083: /**
084: * A lazily computed cache of the string representation of this submission.
085: * This value is computed once; before it is computed, it is
086: * <code>null</code>.
087: */
088: private transient String string;
089:
090: /**
091: * Creates a new instance of this class.
092: *
093: * @param activePartId
094: * the identifier of the part that must be active for this
095: * request to be considered. May be <code>null</code>.
096: * @param activeShell
097: * the shell that must be active for this request to be
098: * considered. May be <code>null</code>.
099: * @param activeWorkbenchPartSite
100: * the workbench part site of the part that must be active for
101: * this request to be considered. May be <code>null</code>.
102: * @param commandId
103: * the identifier of the command to be handled. Must not be
104: * <code>null</code>.
105: * @param handler
106: * the handler. Must not be <code>null</code>.
107: * @param priority
108: * the priority. Must not be <code>null</code>.
109: */
110: public HandlerSubmission(String activePartId, Shell activeShell,
111: IWorkbenchPartSite activeWorkbenchPartSite,
112: String commandId, IHandler handler, Priority priority) {
113: if (commandId == null || handler == null || priority == null) {
114: throw new NullPointerException();
115: }
116:
117: this .activePartId = activePartId;
118: this .activeShell = activeShell;
119: this .activeWorkbenchPartSite = activeWorkbenchPartSite;
120: this .commandId = commandId;
121: this .handler = handler;
122: this .priority = priority;
123: }
124:
125: /**
126: * @see Comparable#compareTo(java.lang.Object)
127: */
128: public int compareTo(Object object) {
129: HandlerSubmission castedObject = (HandlerSubmission) object;
130: int compareTo = Util.compare(activeWorkbenchPartSite,
131: castedObject.activeWorkbenchPartSite);
132:
133: if (compareTo == 0) {
134: compareTo = Util.compare(activePartId,
135: castedObject.activePartId);
136:
137: if (compareTo == 0) {
138: compareTo = Util.compare(activeShell,
139: castedObject.activeShell);
140:
141: if (compareTo == 0) {
142: compareTo = Util.compare(priority,
143: castedObject.priority);
144:
145: if (compareTo == 0) {
146: compareTo = Util.compare(commandId,
147: castedObject.commandId);
148:
149: if (compareTo == 0) {
150: compareTo = Util.compare(handler,
151: castedObject.handler);
152: }
153: }
154: }
155: }
156: }
157:
158: return compareTo;
159: }
160:
161: /**
162: * Returns the identifier of the part that must be active for this request
163: * to be considered.
164: *
165: * @return the identifier of the part that must be active for this request
166: * to be considered. May be <code>null</code>.
167: */
168: public String getActivePartId() {
169: return activePartId;
170: }
171:
172: /**
173: * Returns the shell that must be active for this request to be considered.
174: *
175: * @return the shell that must be active for this request to be considered.
176: * May be <code>null</code>.
177: */
178: public Shell getActiveShell() {
179: return activeShell;
180: }
181:
182: /**
183: * Returns the workbench part site of the part that must be active for this
184: * request to be considered.
185: *
186: * @return the workbench part site of the part that must be active for this
187: * request to be considered. May be <code>null</code>.
188: */
189: public IWorkbenchPartSite getActiveWorkbenchPartSite() {
190: return activeWorkbenchPartSite;
191: }
192:
193: /**
194: * Returns the identifier of the command to be handled.
195: *
196: * @return the identifier of the command to be handled. Guaranteed not to be
197: * <code>null</code>.
198: */
199: public String getCommandId() {
200: return commandId;
201: }
202:
203: /**
204: * Returns the handler.
205: *
206: * @return the handler. Guaranteed not to be <code>null</code>.
207: */
208: public IHandler getHandler() {
209: return handler;
210: }
211:
212: /**
213: * Returns the priority.
214: *
215: * @return the priority. Guaranteed not to be <code>null</code>.
216: */
217: public Priority getPriority() {
218: return priority;
219: }
220:
221: /**
222: * @see Object#toString()
223: */
224: public String toString() {
225: if (string == null) {
226: final StringBuffer stringBuffer = new StringBuffer();
227: stringBuffer.append("[activePartId="); //$NON-NLS-1$
228: stringBuffer.append(activePartId);
229: stringBuffer.append(",activeShell="); //$NON-NLS-1$
230: stringBuffer.append(activeShell);
231: stringBuffer.append(",activeWorkbenchSite="); //$NON-NLS-1$
232: stringBuffer.append(activeWorkbenchPartSite);
233: stringBuffer.append(",commandId="); //$NON-NLS-1$
234: stringBuffer.append(commandId);
235: stringBuffer.append(",handler="); //$NON-NLS-1$
236: stringBuffer.append(handler);
237: stringBuffer.append(",priority="); //$NON-NLS-1$
238: stringBuffer.append(priority);
239: stringBuffer.append(']');
240: string = stringBuffer.toString();
241: }
242:
243: return string;
244: }
245: }
|