01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: ******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.core.commands.ExecutionEvent;
13: import org.eclipse.core.commands.ExecutionException;
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.IWorkbenchPart;
21: import org.eclipse.ui.IWorkbenchPartSite;
22: import org.eclipse.ui.handlers.HandlerUtil;
23:
24: /**
25: * Show the menu on top of the icon in the view or editor label.
26: * <p>
27: * Replacement for ShowPartPaneMenuAction
28: * </p>
29: *
30: * @since 3.3
31: */
32: public class ShowPartPaneMenuHandler extends AbstractEvaluationHandler {
33:
34: private Expression enabledWhen;
35:
36: public ShowPartPaneMenuHandler() {
37: registerEnablement();
38: }
39:
40: public Object execute(ExecutionEvent event)
41: throws ExecutionException {
42:
43: IWorkbenchPart part = HandlerUtil.getActivePart(event);
44: if (part != null) {
45: IWorkbenchPartSite site = part.getSite();
46: if (site instanceof PartSite) {
47: PartPane pane = ((PartSite) site).getPane();
48: pane.showSystemMenu();
49: }
50: }
51: return null;
52: }
53:
54: /*
55: * (non-Javadoc)
56: *
57: * @see org.eclipse.ui.internal.AbstractEvaluationHandler#getEnabledWhenExpression()
58: */
59: protected Expression getEnabledWhenExpression() {
60: if (enabledWhen == null) {
61: enabledWhen = new Expression() {
62: public EvaluationResult evaluate(
63: IEvaluationContext context)
64: throws CoreException {
65: IWorkbenchPart part = InternalHandlerUtil
66: .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
81: .addVariableNameAccess(ISources.ACTIVE_PART_NAME);
82: }
83: };
84: }
85: return enabledWhen;
86: }
87: }
|