KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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.Expression;
16 import org.eclipse.core.expressions.ExpressionInfo;
17 import org.eclipse.core.expressions.IEvaluationContext;
18 import org.eclipse.ui.ISources;
19 import org.eclipse.ui.internal.services.SourcePriorityNameMapping;
20
21 /**
22  * <p>
23  * An expression representing the <code>part id</code> of the legacy editor
24  * action bar contribution.
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 class LegacyEditorActionBarExpression extends Expression {
34     /**
35      * The seed for the hash code for all schemes.
36      */

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

44     private final String JavaDoc activeEditorId;
45
46     /**
47      * Constructs a new instance of <code>LegacyEditorActionBarExpression</code>
48      *
49      * @param editorId
50      * The identifier of the editor to match with the active editor;
51      * must not be <code>null</code>
52      */

53     public LegacyEditorActionBarExpression(final String JavaDoc editorId) {
54
55         if (editorId == null) {
56             throw new IllegalArgumentException JavaDoc(
57                     "The targetId for an editor contribution must not be null"); //$NON-NLS-1$
58
}
59         activeEditorId = editorId;
60     }
61
62     public final void collectExpressionInfo(final ExpressionInfo info) {
63         info.addVariableNameAccess(ISources.ACTIVE_PART_ID_NAME);
64         info
65                 .addVariableNameAccess(SourcePriorityNameMapping.LEGACY_LEGACY_NAME);
66     }
67
68     protected final int computeHashCode() {
69         int hashCode = HASH_INITIAL * HASH_FACTOR + hashCode(activeEditorId);
70         return hashCode;
71     }
72
73     public final boolean equals(final Object JavaDoc object) {
74         if (object instanceof LegacyEditorActionBarExpression) {
75             final LegacyEditorActionBarExpression that = (LegacyEditorActionBarExpression) object;
76             return activeEditorId.equals(that.activeEditorId);
77         }
78
79         return false;
80     }
81
82     /*
83      * (non-Javadoc)
84      *
85      * @see org.eclipse.core.expressions.Expression#evaluate(org.eclipse.core.expressions.IEvaluationContext)
86      */

87     public final EvaluationResult evaluate(final IEvaluationContext context) {
88         final Object JavaDoc variable = context
89                 .getVariable(ISources.ACTIVE_PART_ID_NAME);
90         if (equals(activeEditorId, variable)) {
91             return EvaluationResult.TRUE;
92         }
93         return EvaluationResult.FALSE;
94     }
95
96     public final String JavaDoc toString() {
97         final StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
98         buffer.append("LegacyEditorActionBarExpression("); //$NON-NLS-1$
99
buffer.append(activeEditorId);
100         buffer.append(')');
101         return buffer.toString();
102     }
103 }
104
Popular Tags