1 /*******************************************************************************2 * Copyright (c) 2007 IBM Corporation and others.3 * All rights reserved. This program and the accompanying materials4 * are made available under the terms of the Eclipse Public License v1.05 * which accompanies this distribution, and is available at6 * http://www.eclipse.org/legal/epl-v10.html7 *8 * Contributors:9 * IBM Corporation - initial API and implementation10 ******************************************************************************/11 12 package org.eclipse.ui.internal;13 14 import org.eclipse.core.commands.ExecutionEvent;15 import org.eclipse.core.commands.ExecutionException;16 import org.eclipse.core.expressions.EvaluationResult;17 import org.eclipse.core.expressions.Expression;18 import org.eclipse.core.expressions.ExpressionInfo;19 import org.eclipse.core.expressions.IEvaluationContext;20 import org.eclipse.core.runtime.CoreException;21 import org.eclipse.ui.ISources;22 import org.eclipse.ui.IWorkbenchPart;23 import org.eclipse.ui.IWorkbenchPartSite;24 import org.eclipse.ui.handlers.HandlerUtil;25 26 /**27 * Show the menu on top of the icon in the view or editor label.28 * <p>29 * Replacement for ShowPartPaneMenuAction30 * </p>31 * 32 * @since 3.333 */34 public class ShowPartPaneMenuHandler extends AbstractEvaluationHandler {35 36 private Expression enabledWhen;37 38 public ShowPartPaneMenuHandler() {39 registerEnablement();40 }41 42 public Object execute(ExecutionEvent event) throws ExecutionException {43 44 IWorkbenchPart part = HandlerUtil.getActivePart(event);45 if (part != null) {46 IWorkbenchPartSite site = part.getSite();47 if (site instanceof PartSite) {48 PartPane pane = ((PartSite) site).getPane();49 pane.showSystemMenu();50 }51 }52 return null;53 }54 55 /*56 * (non-Javadoc)57 * 58 * @see org.eclipse.ui.internal.AbstractEvaluationHandler#getEnabledWhenExpression()59 */60 protected Expression getEnabledWhenExpression() {61 if (enabledWhen == null) {62 enabledWhen = new Expression() {63 public EvaluationResult evaluate(IEvaluationContext context)64 throws CoreException {65 IWorkbenchPart part = InternalHandlerUtil66 .getActivePart(context);67 68 if (part != null) {69 return EvaluationResult.TRUE;70 }71 return EvaluationResult.FALSE;72 }73 74 /*75 * (non-Javadoc)76 * 77 * @see org.eclipse.core.expressions.Expression#collectExpressionInfo(org.eclipse.core.expressions.ExpressionInfo)78 */79 public void collectExpressionInfo(ExpressionInfo info) {80 info.addVariableNameAccess(ISources.ACTIVE_PART_NAME);81 }82 };83 }84 return enabledWhen;85 }86 }87