org.eclipse.ui.LegacyHandlerSubmissionExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of workbench Show documentation
Show all versions of workbench Show documentation
This plug-in contains the bulk of the Workbench implementation, and depends on JFace, SWT, and Core Runtime. It cannot be used independently from org.eclipse.ui. Workbench client plug-ins should not depend directly on this plug-in.
The newest version!
/*******************************************************************************
* Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui;
import org.eclipse.core.expressions.EvaluationResult;
import org.eclipse.core.expressions.Expression;
import org.eclipse.core.expressions.ExpressionInfo;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.swt.widgets.Shell;
/**
*
* An expression encapsulating all of the information from legacy handler
* submissions.
*
*
* @since 3.1
*/
public final class LegacyHandlerSubmissionExpression extends Expression {
/**
* The seed for the hash code for all schemes.
*/
private static final int HASH_INITIAL = LegacyHandlerSubmissionExpression.class
.getName().hashCode();
/**
* The identifier for the part that must be active for this expression to
* evaluate to true
. If this value is null
,
* then any part may be active.
*/
private final String activePartId;
/**
* The shell that must be active for this expression to evaluate to
* true
. If this value is null
, then any
* shell may be active.
*/
private final Shell activeShell;
/**
* The site that must be active for this expression to evaluate to
* true
. If this value is null
, then any
* site may be active.
*/
private final IWorkbenchPartSite activeSite;
/**
* Constructs a new instance of
* LegacyHandlerSubmissionExpression
*
* @param activePartId
* The part identifier to match with the active part;
* null
if it will match any active part.
* @param activeShell
* The shell to match with the active shell; null
* if it will match any active shell.
* @param activeSite
* The site to match with the active site; null
if
* it will match any active site.
*/
public LegacyHandlerSubmissionExpression(final String activePartId,
final Shell activeShell, final IWorkbenchPartSite activeSite) {
this.activePartId = activePartId;
this.activeShell = activeShell;
this.activeSite = activeSite;
}
/**
* Collect expression info for a legacy handler submission. Namely
* the active part id and name, active shell name, active workbench
* window shell name and the active site name.
*
* @since 3.2
*/
public final void collectExpressionInfo(final ExpressionInfo info) {
if (activePartId != null) {
info.addVariableNameAccess(ISources.ACTIVE_PART_ID_NAME);
}
if (activeShell != null) {
info.addVariableNameAccess(ISources.ACTIVE_SHELL_NAME);
info
.addVariableNameAccess(ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME);
}
if (activeSite != null) {
info.addVariableNameAccess(ISources.ACTIVE_SITE_NAME);
}
}
protected final int computeHashCode() {
int hashCode = HASH_INITIAL * HASH_FACTOR + hashCode(activePartId);
hashCode = hashCode * HASH_FACTOR + hashCode(activeShell);
hashCode = hashCode * HASH_FACTOR + hashCode(activeSite);
return hashCode;
}
public final boolean equals(final Object object) {
if (object instanceof LegacyHandlerSubmissionExpression) {
final LegacyHandlerSubmissionExpression that = (LegacyHandlerSubmissionExpression) object;
return equals(this.activePartId, that.activePartId)
&& equals(this.activeShell, that.activeShell)
&& equals(this.activeSite, that.activeSite);
}
return false;
}
/**
* Evaluates this expression. This tests the three conditions against the
* current state of the application (as defined by context
).
* If a condition is null
, then it matches any possible
* value (i.e., it is not tested at all).
*
* @param context
* The context providing the current workbench state; must not be
* null
.
* @return EvaluationResult.TRUE
if the conditions all
* matches; EvaluationResult.FALSE
otherwise.
*/
public final EvaluationResult evaluate(final IEvaluationContext context) {
if (activePartId != null) {
final Object value = context
.getVariable(ISources.ACTIVE_PART_ID_NAME);
if (!activePartId.equals(value)) {
return EvaluationResult.FALSE;
}
}
if (activeShell != null) {
Object value = context.getVariable(ISources.ACTIVE_SHELL_NAME);
if (!activeShell.equals(value)) {
value = context
.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME);
if (!activeShell.equals(value)) {
return EvaluationResult.FALSE;
}
}
}
if (activeSite != null) {
final Object value = context.getVariable(ISources.ACTIVE_SITE_NAME);
if (!activeSite.equals(value)) {
return EvaluationResult.FALSE;
}
}
return EvaluationResult.TRUE;
}
public final String toString() {
final StringBuffer buffer = new StringBuffer();
buffer.append("LegacyHandlerSubmission("); //$NON-NLS-1$
buffer.append(activeShell);
buffer.append(',');
buffer.append(activePartId);
buffer.append(',');
buffer.append(activeSite);
buffer.append(')');
return buffer.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy