KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > contexts > ContextActivation


1 /*******************************************************************************
2  * Copyright (c) 2005, 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
12 package org.eclipse.ui.internal.contexts;
13
14 import org.eclipse.core.expressions.Expression;
15 import org.eclipse.core.expressions.IEvaluationContext;
16 import org.eclipse.ui.ISources;
17 import org.eclipse.ui.contexts.IContextActivation;
18 import org.eclipse.ui.contexts.IContextService;
19 import org.eclipse.ui.internal.services.EvaluationResultCache;
20
21 /**
22  * <p>
23  * A token representing the activation of a context. This token can later be
24  * used to cancel that activation. Without this token, then the context will
25  * only become inactive if the component in which the context was activated is
26  * destroyed.
27  * </p>
28  * <p>
29  * This caches the context id, so that they can later be identified.
30  * </p>
31  * <p>
32  * Note: this class has a natural ordering that is inconsistent with equals.
33  * </p>
34  *
35  * @since 3.1
36  */

37 final class ContextActivation extends EvaluationResultCache implements
38         IContextActivation {
39
40     /**
41      * The identifier for the context which should be active. This value is
42      * never <code>null</code>.
43      */

44     private final String JavaDoc contextId;
45
46     /**
47      * The context service from which this context activation was requested.
48      * This value is never <code>null</code>.
49      */

50     private final IContextService contextService;
51
52     /**
53      * Constructs a new instance of <code>ContextActivation</code>.
54      *
55      * @param contextId
56      * The identifier for the context which should be activated. This
57      * value must not be <code>null</code>.
58      * @param expression
59      * The expression that must evaluate to <code>true</code>
60      * before this handler is active. This value may be
61      * <code>null</code> if it is always active.
62      * @param contextService
63      * The context service from which the handler activation was
64      * requested; must not be <code>null</code>.
65      * @see ISources
66      */

67     public ContextActivation(final String JavaDoc contextId,
68             final Expression expression, final IContextService contextService) {
69         super(expression);
70
71         if (contextId == null) {
72             throw new NullPointerException JavaDoc(
73                     "The context identifier for a context activation cannot be null"); //$NON-NLS-1$
74
}
75
76         if (contextService == null) {
77             throw new NullPointerException JavaDoc(
78                     "The context service for an activation cannot be null"); //$NON-NLS-1$
79
}
80
81         this.contextId = contextId;
82         this.contextService = contextService;
83     }
84
85     public final void clearActive() {
86         clearResult();
87     }
88
89     public final String JavaDoc getContextId() {
90         return contextId;
91     }
92
93     public final IContextService getContextService() {
94         return contextService;
95     }
96
97     public final boolean isActive(final IEvaluationContext context) {
98         return evaluate(context);
99     }
100
101     public final String JavaDoc toString() {
102         final StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
103
104         buffer.append("ContextActivation(contextId="); //$NON-NLS-1$
105
buffer.append(contextId);
106         buffer.append(",sourcePriority="); //$NON-NLS-1$
107
buffer.append(getSourcePriority());
108         buffer.append(')');
109
110         return buffer.toString();
111     }
112
113 }
114
Popular Tags