KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.swt.widgets.Shell;
14 import org.eclipse.ui.IWorkbenchPartSite;
15 import org.eclipse.ui.internal.util.Util;
16
17 /**
18  * </p>
19  * An instance of this class represents a request to handle a command. A handler
20  * submission specifies a list of conditions under which it would be appropriate
21  * for a particular command to have a particular handler. These conditions
22  * include things like the active part or the active shell. So, it is possible
23  * to say things like: "when my part is active, please consider calling these
24  * classes when you want to perform a cut, copy or paste".
25  * </p>
26  * <p>
27  * The workbench considers all of the submissions it has received and choses the
28  * ones it views as the best possible match.
29  * </p>
30  * <p>
31  * This class is not intended to be extended by clients.
32  * </p>
33  * <p>
34  * Note: this class has a natural ordering that is inconsistent with equals.
35  * </p>
36  *
37  * @since 3.0
38  * @see org.eclipse.ui.commands.IWorkbenchCommandSupport
39  * @deprecated Please use <code>IHandlerService.activateHandler</code>
40  * instead.
41  * @see org.eclipse.ui.handlers.IHandlerService
42  */

43 public final class HandlerSubmission implements Comparable JavaDoc {
44
45     /**
46      * The part identifier for the part that should be active before this
47      * submission can be considered. This value can be <code>null</code>, which
48      * indicates that it should match any part.
49      */

50     private final String JavaDoc activePartId;
51
52     /**
53      * The shell that must be active before this submission can be considered.
54      * This value can be <code>null</code>, which indicates that it should match
55      * any shell.
56      */

57     private final Shell activeShell;
58
59     /**
60      * The workbench site that must be active before this submission can be
61      * considered. This value can be <code>null</code>, which indicates that it
62      * should match an workbench part site.
63      */

64     private final IWorkbenchPartSite activeWorkbenchPartSite;
65
66     /**
67      * The identifier for the command which the submitted handler handles. This
68      * value cannot be <code>null</code>.
69      */

70     private final String JavaDoc commandId;
71
72     /**
73      * The handler being submitted. This value cannot be <code>null</code>.
74      */

75     private final IHandler handler;
76
77     /**
78      * The priority for this submission. In the event of all other factors
79      * being equal, the priority will be considered in an attempt to resolve
80      * conflicts. This value cannot be <code>null</code>.
81      */

82     private final Priority priority;
83
84     /**
85      * A lazily computed cache of the string representation of this submission.
86      * This value is computed once; before it is computed, it is
87      * <code>null</code>.
88      */

89     private transient String JavaDoc string;
90
91     /**
92      * Creates a new instance of this class.
93      *
94      * @param activePartId
95      * the identifier of the part that must be active for this
96      * request to be considered. May be <code>null</code>.
97      * @param activeShell
98      * the shell that must be active for this request to be
99      * considered. May be <code>null</code>.
100      * @param activeWorkbenchPartSite
101      * the workbench part site of the part that must be active for
102      * this request to be considered. May be <code>null</code>.
103      * @param commandId
104      * the identifier of the command to be handled. Must not be
105      * <code>null</code>.
106      * @param handler
107      * the handler. Must not be <code>null</code>.
108      * @param priority
109      * the priority. Must not be <code>null</code>.
110      */

111     public HandlerSubmission(String JavaDoc activePartId, Shell activeShell,
112             IWorkbenchPartSite activeWorkbenchPartSite, String JavaDoc commandId,
113             IHandler handler, Priority priority) {
114         if (commandId == null || handler == null || priority == null) {
115             throw new NullPointerException JavaDoc();
116         }
117
118         this.activePartId = activePartId;
119         this.activeShell = activeShell;
120         this.activeWorkbenchPartSite = activeWorkbenchPartSite;
121         this.commandId = commandId;
122         this.handler = handler;
123         this.priority = priority;
124     }
125
126     /**
127      * @see Comparable#compareTo(java.lang.Object)
128      */

129     public int compareTo(Object JavaDoc object) {
130         HandlerSubmission castedObject = (HandlerSubmission) object;
131         int compareTo = Util.compare(activeWorkbenchPartSite,
132                 castedObject.activeWorkbenchPartSite);
133
134         if (compareTo == 0) {
135             compareTo = Util.compare(activePartId, castedObject.activePartId);
136
137             if (compareTo == 0) {
138                 compareTo = Util.compare(activeShell, castedObject.activeShell);
139
140                 if (compareTo == 0) {
141                     compareTo = Util.compare(priority, castedObject.priority);
142
143                     if (compareTo == 0) {
144                         compareTo = Util.compare(commandId,
145                                 castedObject.commandId);
146
147                         if (compareTo == 0) {
148                             compareTo = Util.compare(handler,
149                                     castedObject.handler);
150                         }
151                     }
152                 }
153             }
154         }
155
156         return compareTo;
157     }
158
159     /**
160      * Returns the identifier of the part that must be active for this request
161      * to be considered.
162      *
163      * @return the identifier of the part that must be active for this request
164      * to be considered. May be <code>null</code>.
165      */

166     public String JavaDoc getActivePartId() {
167         return activePartId;
168     }
169
170     /**
171      * Returns the shell that must be active for this request to be considered.
172      *
173      * @return the shell that must be active for this request to be considered.
174      * May be <code>null</code>.
175      */

176     public Shell getActiveShell() {
177         return activeShell;
178     }
179
180     /**
181      * Returns the workbench part site of the part that must be active for this
182      * request to be considered.
183      *
184      * @return the workbench part site of the part that must be active for this
185      * request to be considered. May be <code>null</code>.
186      */

187     public IWorkbenchPartSite getActiveWorkbenchPartSite() {
188         return activeWorkbenchPartSite;
189     }
190
191     /**
192      * Returns the identifier of the command to be handled.
193      *
194      * @return the identifier of the command to be handled. Guaranteed not to be
195      * <code>null</code>.
196      */

197     public String JavaDoc getCommandId() {
198         return commandId;
199     }
200
201     /**
202      * Returns the handler.
203      *
204      * @return the handler. Guaranteed not to be <code>null</code>.
205      */

206     public IHandler getHandler() {
207         return handler;
208     }
209
210     /**
211      * Returns the priority.
212      *
213      * @return the priority. Guaranteed not to be <code>null</code>.
214      */

215     public Priority getPriority() {
216         return priority;
217     }
218
219     /**
220      * @see Object#toString()
221      */

222     public String JavaDoc toString() {
223         if (string == null) {
224             final StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
225             stringBuffer.append("[activePartId="); //$NON-NLS-1$
226
stringBuffer.append(activePartId);
227             stringBuffer.append(",activeShell="); //$NON-NLS-1$
228
stringBuffer.append(activeShell);
229             stringBuffer.append(",activeWorkbenchSite="); //$NON-NLS-1$
230
stringBuffer.append(activeWorkbenchPartSite);
231             stringBuffer.append(",commandId="); //$NON-NLS-1$
232
stringBuffer.append(commandId);
233             stringBuffer.append(",handler="); //$NON-NLS-1$
234
stringBuffer.append(handler);
235             stringBuffer.append(",priority="); //$NON-NLS-1$
236
stringBuffer.append(priority);
237             stringBuffer.append(']');
238             string = stringBuffer.toString();
239         }
240
241         return string;
242     }
243 }
244
Popular Tags