|
Added
Link Here
|
| 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.core.runtime.CoreException; |
| 19 |
import org.eclipse.ui.ISources; |
| 20 |
import org.eclipse.ui.internal.services.SourcePriorityNameMapping; |
| 21 |
|
| 22 |
/** |
| 23 |
* <p> |
| 24 |
* An expression representing the <code>part id</code> of the legacy editor |
| 25 |
* action bar contribution. |
| 26 |
* </p> |
| 27 |
* <p> |
| 28 |
* This class is not intended for use outside of the |
| 29 |
* <code>org.eclipse.ui.workbench</code> plug-in. |
| 30 |
* </p> |
| 31 |
* |
| 32 |
* @since 3.2 |
| 33 |
*/ |
| 34 |
public class LegacyEditorActionBarExpression extends Expression { |
| 35 |
/** |
| 36 |
* The seed for the hash code for all schemes. |
| 37 |
*/ |
| 38 |
private static final int HASH_INITIAL = LegacyEditorActionBarExpression.class |
| 39 |
.getName().hashCode(); |
| 40 |
|
| 41 |
/** |
| 42 |
* The identifier for the editor that must be active for this expression to |
| 43 |
* evaluate to <code>true</code>. This value is never <code>null</code>. |
| 44 |
*/ |
| 45 |
private final String fActiveEditorId; |
| 46 |
|
| 47 |
/** |
| 48 |
* Constructs a new instance of <code>LegacyEditorActionBarExpression</code> |
| 49 |
* |
| 50 |
* @param activeEditorId |
| 51 |
* The identifier of the editor to match with the active editor; |
| 52 |
* must not be <code>null</code> |
| 53 |
*/ |
| 54 |
public LegacyEditorActionBarExpression(final String activeEditorId) { |
| 55 |
|
| 56 |
if (activeEditorId == null) { |
| 57 |
throw new NullPointerException( |
| 58 |
"The targetId for an editor contribution must not be null"); //$NON-NLS-1$ |
| 59 |
} |
| 60 |
fActiveEditorId = activeEditorId; |
| 61 |
} |
| 62 |
|
| 63 |
public final void collectExpressionInfo(final ExpressionInfo info) { |
| 64 |
info.addVariableNameAccess(ISources.ACTIVE_EDITOR_ID_NAME); |
| 65 |
info |
| 66 |
.addVariableNameAccess(SourcePriorityNameMapping.LEGACY_LEGACY_NAME); |
| 67 |
} |
| 68 |
|
| 69 |
protected final int computeHashCode() { |
| 70 |
int hashCode = HASH_INITIAL * HASH_FACTOR + hashCode(fActiveEditorId); |
| 71 |
return hashCode; |
| 72 |
} |
| 73 |
|
| 74 |
public final boolean equals(final Object object) { |
| 75 |
if (object instanceof LegacyEditorActionBarExpression) { |
| 76 |
final LegacyEditorActionBarExpression that = (LegacyEditorActionBarExpression) object; |
| 77 |
return equals(fActiveEditorId, that.fActiveEditorId); |
| 78 |
} |
| 79 |
|
| 80 |
return false; |
| 81 |
} |
| 82 |
|
| 83 |
/* |
| 84 |
* (non-Javadoc) |
| 85 |
* |
| 86 |
* @see org.eclipse.core.expressions.Expression#evaluate(org.eclipse.core.expressions.IEvaluationContext) |
| 87 |
*/ |
| 88 |
public final EvaluationResult evaluate(final IEvaluationContext context) |
| 89 |
throws CoreException { |
| 90 |
if ("org.eclipse.jdt.ui.CompilationUnitEditor".equals(fActiveEditorId)) { //$NON-NLS-1$ |
| 91 |
System.out.println(); |
| 92 |
} |
| 93 |
|
| 94 |
final Object variable = context |
| 95 |
.getVariable(ISources.ACTIVE_EDITOR_ID_NAME); |
| 96 |
if (equals(fActiveEditorId, variable)) { |
| 97 |
return EvaluationResult.TRUE; |
| 98 |
} |
| 99 |
return EvaluationResult.FALSE; |
| 100 |
} |
| 101 |
|
| 102 |
public final String toString() { |
| 103 |
final StringBuffer buffer = new StringBuffer(); |
| 104 |
buffer.append("LegacyEditorActionBarExpression("); //$NON-NLS-1$ |
| 105 |
buffer.append(fActiveEditorId); |
| 106 |
buffer.append(')'); |
| 107 |
return buffer.toString(); |
| 108 |
} |
| 109 |
} |