KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > expressions > LegacyViewContributionExpression


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.expressions;
13
14 import org.eclipse.core.expressions.EvaluationResult;
15 import org.eclipse.core.expressions.ExpressionInfo;
16 import org.eclipse.core.expressions.IEvaluationContext;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.ui.ISources;
19 import org.eclipse.ui.IWorkbenchWindow;
20
21 /**
22  * <p>
23  * An expression representing the <code>targetId</code> of the legacy view
24  * contributions.
25  * </p>
26  * <p>
27  * This class is not intended for use outside of the
28  * <code>org.eclipse.ui.workbench</code> plug-in.
29  * </p>
30  *
31  * @since 3.2
32  */

33 public final class LegacyViewContributionExpression extends
34         WorkbenchWindowExpression {
35
36     /**
37      * The seed for the hash code for all schemes.
38      */

39     private static final int HASH_INITIAL = LegacyViewContributionExpression.class
40             .getName().hashCode();
41
42     /**
43      * The identifier for the part that must be active for this expression to
44      * evaluate to <code>true</code>. This value is never <code>null</code>.
45      */

46     private final String JavaDoc activePartId;
47
48     /**
49      * Constructs a new instance of
50      * <code>LegacyViewContributionExpression</code>
51      *
52      * @param activePartId
53      * The identifier of the part to match with the active part; may
54      * be <code>null</code>
55      * @param window
56      * The workbench window in which this handler should be active.
57      * This value is never <code>null</code>.
58      */

59     public LegacyViewContributionExpression(final String JavaDoc activePartId,
60             final IWorkbenchWindow window) {
61         super(window);
62
63         if (activePartId == null) {
64             throw new NullPointerException JavaDoc(
65                     "The targetId for a view contribution must not be null"); //$NON-NLS-1$
66
}
67         this.activePartId = activePartId;
68     }
69
70     public final void collectExpressionInfo(final ExpressionInfo info) {
71         super.collectExpressionInfo(info);
72         info.addVariableNameAccess(ISources.ACTIVE_PART_ID_NAME);
73     }
74
75     protected final int computeHashCode() {
76         int hashCode = HASH_INITIAL * HASH_FACTOR + hashCode(getWindow());
77         hashCode = hashCode * HASH_FACTOR + hashCode(activePartId);
78         return hashCode;
79     }
80
81     public final boolean equals(final Object JavaDoc object) {
82         if (object instanceof LegacyViewContributionExpression) {
83             final LegacyViewContributionExpression that = (LegacyViewContributionExpression) object;
84             return equals(this.activePartId, that.activePartId)
85                     && equals(this.getWindow(), that.getWindow());
86         }
87
88         return false;
89     }
90
91     public final EvaluationResult evaluate(final IEvaluationContext context)
92             throws CoreException {
93         final EvaluationResult result = super.evaluate(context);
94         if (result == EvaluationResult.FALSE) {
95             return result;
96         }
97
98         final Object JavaDoc variable = context
99                 .getVariable(ISources.ACTIVE_PART_ID_NAME);
100         if (equals(activePartId, variable)) {
101             return EvaluationResult.TRUE;
102         }
103         return EvaluationResult.FALSE;
104     }
105
106     public final String JavaDoc toString() {
107         final StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
108         buffer.append("LegacyViewContributionExpression("); //$NON-NLS-1$
109
buffer.append(activePartId);
110         buffer.append(',');
111         buffer.append(getWindow());
112         buffer.append(')');
113         return buffer.toString();
114     }
115
116 }
117
Popular Tags