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: * Shows the View Menu
26: * <p>
27: * Replacement for: ShowViewMenuAction
28: * </p>
29: *
30: * @since 3.3
31: *
32: */
33: public class ShowViewMenuHandler extends AbstractEvaluationHandler {
34:
35: private Expression enabledWhen;
36:
37: public ShowViewMenuHandler() {
38: registerEnablement();
39: }
40:
41: /*
42: * (non-Javadoc)
43: *
44: * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
45: */
46: public Object execute(ExecutionEvent event)
47: throws ExecutionException {
48:
49: IWorkbenchPart part = HandlerUtil.getActivePart(event);
50: if (part != null) {
51: IWorkbenchPartSite site = part.getSite();
52: if (site instanceof PartSite) {
53: PartPane pane = ((PartSite) site).getPane();
54: pane.showPaneMenu();
55: }
56: }
57: return null;
58: }
59:
60: /*
61: * (non-Javadoc)
62: *
63: * @see org.eclipse.ui.internal.AbstractEvaluationHandler#getEnabledWhenExpression()
64: */
65: protected Expression getEnabledWhenExpression() {
66: // TODO Auto-generated method stub
67: if (enabledWhen == null) {
68: enabledWhen = new Expression() {
69: public EvaluationResult evaluate(
70: IEvaluationContext context)
71: throws CoreException {
72: IWorkbenchPart part = InternalHandlerUtil
73: .getActivePart(context);
74: if (part != null) {
75: PartPane pane = ((PartSite) part.getSite())
76: .getPane();
77: if ((pane instanceof ViewPane)
78: && ((ViewPane) pane).hasViewMenu()) {
79: return EvaluationResult.TRUE;
80: }
81: }
82: return EvaluationResult.FALSE;
83: }
84:
85: /*
86: * (non-Javadoc)
87: *
88: * @see org.eclipse.core.expressions.Expression#collectExpressionInfo(org.eclipse.core.expressions.ExpressionInfo)
89: */
90: public void collectExpressionInfo(ExpressionInfo info) {
91: info
92: .addVariableNameAccess(ISources.ACTIVE_PART_NAME);
93: }
94: };
95: }
96: return enabledWhen;
97: }
98:
99: }
|