KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > contexts > EnabledSubmission


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.contexts;
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 enabled a context. An
20  * enabled submission specifies a list of conditions under which it would be
21  * appropriate for a particular context to be enabled. These conditions include
22  * things like the active part or the active shell. So, it is possible to say
23  * things like: "when the java editor is active, please consider enabling the
24  * 'editing java' context".
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 IWorkbenchContextSupport
39  * @deprecated Please use <code>IContextService.activateContext</code>
40  * instead.
41  * @see org.eclipse.ui.contexts.IContextService
42  */

43 public final class EnabledSubmission implements Comparable JavaDoc {
44
45     /**
46      * The identifier of the part in which this context should be enabled. If
47      * this value is <code>null</code>, this means it should be active in any
48      * part.
49      */

50     private final String JavaDoc activePartId;
51
52     /**
53      * The shell in which this context should be enabled. If this value is
54      * <code>null</code>, this means it should be active in any shell.
55      */

56     private final Shell activeShell;
57
58     /**
59      * The part site in which this context should be enabled. If this value is
60      * <code>null</code>, this means it should be active in any part site.
61      */

62     private final IWorkbenchPartSite activeWorkbenchPartSite;
63
64     /**
65      * The identifier for the context that should be enabled by this
66      * submissions. This value should never be <code>null</code>.
67      */

68     private final String JavaDoc contextId;
69
70     /**
71      * The cached string representation of this instance. This value is computed
72      * lazily on the first call to retrieve the string representation, and the
73      * cache is used for all future calls. If this value is <code>null</code>,
74      * then the value has not yet been computed.
75      */

76     private transient String JavaDoc string = null;
77
78     /**
79      * Creates a new instance of this class.
80      *
81      * @param activePartId
82      * the identifier of the part that must be active for this
83      * request to be considered. May be <code>null</code>.
84      * @param activeShell
85      * the shell that must be active for this request to be
86      * considered. May be <code>null</code>.
87      * @param activeWorkbenchPartSite
88      * the workbench part site of the part that must be active for
89      * this request to be considered. May be <code>null</code>.
90      * @param contextId
91      * the identifier of the context to be enabled. Must not be
92      * <code>null</code>.
93      */

94     public EnabledSubmission(String JavaDoc activePartId, Shell activeShell,
95             IWorkbenchPartSite activeWorkbenchPartSite, String JavaDoc contextId) {
96         if (contextId == null) {
97             throw new NullPointerException JavaDoc();
98         }
99
100         this.activePartId = activePartId;
101         this.activeShell = activeShell;
102         this.activeWorkbenchPartSite = activeWorkbenchPartSite;
103         this.contextId = contextId;
104     }
105
106     /**
107      * @see Comparable#compareTo(java.lang.Object)
108      */

109     public int compareTo(Object JavaDoc object) {
110         EnabledSubmission castedObject = (EnabledSubmission) object;
111         int compareTo = Util.compare(activeWorkbenchPartSite,
112                 castedObject.activeWorkbenchPartSite);
113
114         if (compareTo == 0) {
115             compareTo = Util.compare(activePartId, castedObject.activePartId);
116
117             if (compareTo == 0) {
118                 compareTo = Util.compare(activeShell, castedObject.activeShell);
119
120                 if (compareTo == 0) {
121                     compareTo = Util.compare(contextId, castedObject.contextId);
122                 }
123             }
124         }
125
126         return compareTo;
127     }
128
129     /**
130      * Returns the identifier of the part that must be active for this request
131      * to be considered.
132      *
133      * @return the identifier of the part that must be active for this request
134      * to be considered. May be <code>null</code>.
135      */

136     public String JavaDoc getActivePartId() {
137         return activePartId;
138     }
139
140     /**
141      * Returns the shell that must be active for this request to be considered.
142      *
143      * @return the shell that must be active for this request to be considered.
144      * May be <code>null</code>.
145      */

146     public Shell getActiveShell() {
147         return activeShell;
148     }
149
150     /**
151      * Returns the workbench part site of the part that must be active for this
152      * request to be considered.
153      *
154      * @return the workbench part site of the part that must be active for this
155      * request to be considered. May be <code>null</code>.
156      */

157     public IWorkbenchPartSite getActiveWorkbenchPartSite() {
158         return activeWorkbenchPartSite;
159     }
160
161     /**
162      * Returns the identifier of the context to be enabled.
163      *
164      * @return the identifier of the context to be enabled. Guaranteed not to be
165      * <code>null</code>.
166      */

167     public String JavaDoc getContextId() {
168         return contextId;
169     }
170
171     /**
172      * @see Object#toString()
173      */

174     public String JavaDoc toString() {
175         if (string == null) {
176             final StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
177             stringBuffer.append("[activePartId="); //$NON-NLS-1$
178
stringBuffer.append(activePartId);
179             stringBuffer.append(",activeShell="); //$NON-NLS-1$
180
stringBuffer.append(activeShell);
181             stringBuffer.append(",activeWorkbenchSite="); //$NON-NLS-1$
182
stringBuffer.append(activeWorkbenchPartSite);
183             stringBuffer.append(",contextId="); //$NON-NLS-1$
184
stringBuffer.append(contextId);
185             stringBuffer.append(']');
186             string = stringBuffer.toString();
187         }
188
189         return string;
190     }
191 }
192
Popular Tags